Merge lp:~henninge/launchpad/bug-526643-prefix into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Approved by: Aaron Bentley
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/bug-526643-prefix
Merge into: lp:launchpad
Diff against target: 53 lines (+5/-24)
1 file modified
lib/lp/code/model/tests/test_branchjob.py (+5/-24)
To merge this branch: bzr merge lp:~henninge/launchpad/bug-526643-prefix
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+20005@code.launchpad.net

Commit message

Avoid code duplication by using create_prefix and smart_add from bzrlib.

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Hi Aaron,
I agree that this change is actually a bit small for its own branch. I guess I thought there would be more work involved. I had arrived at the same solution for create_prefix and put_bytes but did not see that smart_add needs to be used. Thank you for showing me how to do this.

Cheers,
Henning

Revision history for this message
Aaron Bentley (abentley) wrote :

Actually, I guess os.path.split should become os.path.basename, since we no longer need fname for anything.

review: Approve
Revision history for this message
Henning Eggers (henninge) wrote :

Good point! Although it's dirname that we want ... ;-) Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
2--- lib/lp/code/model/tests/test_branchjob.py 2010-02-22 12:26:18 +0000
3+++ lib/lp/code/model/tests/test_branchjob.py 2010-02-23 22:15:28 +0000
4@@ -867,22 +867,6 @@
5 self.assertFalse(job.generateDiffs())
6
7
8-def all_dirs(directory):
9- """Generate all parent directories and the directory itself.
10-
11- Passing 'a/b/c/d' produces ['a', 'a/b', 'a/b/c', 'a/b/c/d'].
12- """
13- if directory == '':
14- return []
15- dirs = [directory]
16- while(1):
17- head, tail = os.path.split(directory)
18- if head == '':
19- return reversed(dirs)
20- directory = head
21- dirs.append(directory)
22-
23-
24 class TestRosettaUploadJob(TestCaseWithFactory):
25 """Tests for RosettaUploadJob."""
26
27@@ -937,21 +921,18 @@
28 seen_dirs = set()
29 for file_pair in files:
30 file_name = file_pair[0]
31- dname, fname = os.path.split(file_name)
32- for adir in all_dirs(dname):
33- if adir in seen_dirs:
34- continue
35- self.tree.bzrdir.root_transport.mkdir(adir)
36- self.tree.add(adir)
37- seen_dirs.add(adir)
38 try:
39 file_content = file_pair[1]
40 if file_content is None:
41 raise IndexError # Same as if missing.
42 except IndexError:
43 file_content = self.factory.getUniqueString()
44+ dname = os.path.dirname(file_name)
45+ self.tree.bzrdir.root_transport.clone(dname).create_prefix()
46 self.tree.bzrdir.root_transport.put_bytes(file_name, file_content)
47- self.tree.add(file_name)
48+ if len(files) > 0:
49+ self.tree.smart_add(
50+ [self.tree.abspath(file_pair[0]) for file_pair in files])
51 if commit_message is None:
52 commit_message = self.factory.getUniqueString('commit')
53 revision_id = self.tree.commit(commit_message)