Merge lp:~bzr/bzr/parent-directories into lp:~bzr/bzr/trunk-old

Proposed by Ian Clatworthy
Status: Merged
Merged at revision: not available
Proposed branch: lp:~bzr/bzr/parent-directories
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 39 lines
To merge this branch: bzr merge lp:~bzr/bzr/parent-directories
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+6673@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

This patch is one of the building blocks for faster selective file commit.

Revision history for this message
Martin Pool (mbp) wrote :

I think this is a good example of a function where a doctest would be easy to add and make the meaning more clear.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/osutils.py'
2--- bzrlib/osutils.py 2009-05-16 08:21:11 +0000
3+++ bzrlib/osutils.py 2009-05-18 11:35:18 +0000
4@@ -867,6 +867,16 @@
5 return pathjoin(*p)
6
7
8+def parent_directories(filename):
9+ """Return the list of parent directories, deepest first."""
10+ parents = []
11+ parts = splitpath(dirname(filename))
12+ while parts:
13+ parents.append(joinpath(parts))
14+ parts.pop()
15+ return parents
16+
17+
18 try:
19 from bzrlib._chunks_to_lines_pyx import chunks_to_lines
20 except ImportError:
21
22=== modified file 'bzrlib/tests/test_osutils.py'
23--- bzrlib/tests/test_osutils.py 2009-05-07 05:08:46 +0000
24+++ bzrlib/tests/test_osutils.py 2009-05-18 11:35:18 +0000
25@@ -860,6 +860,15 @@
26 self.assertRaises(errors.BzrError, osutils.splitpath, 'a/../b')
27
28
29+class TestParentDirectories(tests.TestCaseInTempDir):
30+ """Test osutils.parent_directories()"""
31+
32+ def test_parent_directories(self):
33+ self.assertEqual([], osutils.parent_directories('a'))
34+ self.assertEqual(['a'], osutils.parent_directories('a/b'))
35+ self.assertEqual(['a/b', 'a'], osutils.parent_directories('a/b/c'))
36+
37+
38 class TestMacFuncsDirs(tests.TestCaseInTempDir):
39 """Test mac special functions that require directories."""
40