Merge lp:~junak-michal/bzr/giveback into lp:bzr

Proposed by Michal Junák
Status: Merged
Merged at revision: not available
Proposed branch: lp:~junak-michal/bzr/giveback
Merge into: lp:bzr
Diff against target: 49 lines (+23/-3)
2 files modified
bzrlib/export/__init__.py (+12/-3)
bzrlib/tests/test_export.py (+11/-0)
To merge this branch: bzr merge lp:~junak-michal/bzr/giveback
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Information
John A Meinel Approve
Martin Pool Approve
Ian Clatworthy Approve
Review via email: mp+18297@code.launchpad.net

This proposal supersedes a proposal from 2010-01-29.

To post a comment you must log in.
Revision history for this message
Michal Junák (junak-michal) wrote : Posted in a previous version of this proposal

#511987 bugfix

Revision history for this message
John A Meinel (jameinel) wrote : Posted in a previous version of this proposal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michal Junák wrote:
> Michal Junák has proposed merging lp:~junak-michal/bzr/giveback into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
>
> #511987 bugfix
>

I think there are some logic failures in this patch, though it is
getting closer.

1) isinstance(subdir_object, InventoryFile) is probably better done as:
  if subdir_object.kind == 'file'

2) inv.path2id(path) will return None if the object isn't present, so
you don't need a 'has_filename' check on top of getting the file_id.
(you can do "if file_id is None" instead.)

3) The docstring should be updated. It clearly states that 'subdir' is
meant to be the path to a directory. So it should probably say ":param
subdir: None or the path of an entry to start exporting.

4) This doesn't handle symlinks, and it seems reasonably easy to do so.
Namely, instead of checking if the object is a file, you could instead
check if the object is not a directory. So:

if not isinstance(...)

would become

if subdir_object is not None and subdir_object.kind != 'directory':
  yield, return
else:
  entries = ...

 review: needs_fixing

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktirt8ACgkQJdeBCYSNAAPqqACghwnPBXwjMp6UHD8Fvl1h/7t9
jPkAoM58UhjBuScNpHspp6HGE0deHw+Z
=+A6y
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal

In addition to John's comments:

Please don't add unnecessary vertical whitespace here:

     """
+
     inv = tree.inventory
     if subdir is None:
- s

and here:

+ yield subdir_object.name, subdir_object
+ return
+
     if subdir is None:

Thanks.
-Rob

Revision history for this message
Michal Junák (junak-michal) wrote : Posted in a previous version of this proposal

> I think there are some logic failures in this patch, though it is
> getting closer.
>
> 1) isinstance(subdir_object, InventoryFile) is probably better done as:
> if subdir_object.kind == 'file'
>
> 2) inv.path2id(path) will return None if the object isn't present, so
> you don't need a 'has_filename' check on top of getting the file_id.
> (you can do "if file_id is None" instead.)
>
> 3) The docstring should be updated. It clearly states that 'subdir' is
> meant to be the path to a directory. So it should probably say ":param
> subdir: None or the path of an entry to start exporting.
>
> 4) This doesn't handle symlinks, and it seems reasonably easy to do so.
> Namely, instead of checking if the object is a file, you could instead
> check if the object is not a directory. So:
>
> if not isinstance(...)
>
> would become
>
> if subdir_object is not None and subdir_object.kind != 'directory':
> yield, return
> else:
> entries = ...
>
> review: needs_fixing
>
> John
> =:->

2) Well, it was stupid to search through twice. None-check added.
3) Docstring changed. I was thinking of renaming subdir variable too, but no better name crossed my mind.
4) Even though exporting the symlink won't cause a crash in the new version, if someone exports the symlink, they may not get what they anticipated.

And whitespaces deleted

Revision history for this message
Michal Junák (junak-michal) wrote :

I' ve repaired the bugfix by your suggestions. I' am new in launchpad, but I hope that resubmitting my proposal is the right way to let you know.

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

This looks ok now. BTW, it's good to add an entry to NEWS taking credit for fixing bugs and making improvements. In this case, I'll add one for you while I'm merging (after it gets a second approval).

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

looks good. contributor agreement done?

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

@Michal,

Thanks for your patch, can you please follow the instructions at
http://www.canonical.com/contributors so we can merge it ?

review: Needs Information
Revision history for this message
John A Meinel (jameinel) wrote :

We should merge lp:~jameinel/bzr/export-file-511987

I merged with bzr.dev, resolved a small conflict in test_export, and added a NEWS entry to give Michal credit for the bugfix.

Just waiting on the contributor agreement getting signed.

review: Approve
Revision history for this message
Michal Junák (junak-michal) wrote :

Shame on me, I haven't noticed I have to accept contributor agreement, sorry for that. I did it by sending email as Vincent advised me, I hope it is alright now.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Martin, did you get Michal mail regarding the contributor agreement ?
It doesn't appear to be a https://edge.launchpad.net/~contributor-agreement-canonical member yet.

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

2010/2/6 Michal Junák <email address hidden>:
> Shame on me, I haven't noticed I have to accept contributor agreement, sorry for that. I did it by sending email as Vincent advised me, I hope it is alright now.

Sorry Michal, I didn't get that. Did you cc me?

--
Martin <http://launchpad.net/~mbp/>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/export/__init__.py'
2--- bzrlib/export/__init__.py 2009-03-23 14:59:43 +0000
3+++ bzrlib/export/__init__.py 2010-01-30 09:38:13 +0000
4@@ -138,14 +138,23 @@
5 """Iter the entries for tree suitable for exporting.
6
7 :param tree: A tree object.
8- :param subdir: None or the path of a directory to start exporting from.
9+ :param subdir: None or the path of an entry to start exporting from.
10 """
11 inv = tree.inventory
12 if subdir is None:
13- subdir_id = None
14+ subdir_object = None
15 else:
16 subdir_id = inv.path2id(subdir)
17- entries = inv.iter_entries(subdir_id)
18+ if subdir_id is not None:
19+ subdir_object = inv[subdir_id]
20+ # XXX: subdir is path not an id, so NoSuchId isn't proper error
21+ else:
22+ raise errors.NoSuchId(tree, subdir)
23+ if subdir_object is not None and subdir_object.kind != 'directory':
24+ yield subdir_object.name, subdir_object
25+ return
26+ else:
27+ entries = inv.iter_entries(subdir_object)
28 if subdir is None:
29 entries.next() # skip root
30 for entry in entries:
31
32=== modified file 'bzrlib/tests/test_export.py'
33--- bzrlib/tests/test_export.py 2009-07-29 13:46:55 +0000
34+++ bzrlib/tests/test_export.py 2010-01-30 09:38:13 +0000
35@@ -62,3 +62,14 @@
36 wt.commit('1')
37 self.build_tree(['target/', 'target/foo'])
38 self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")
39+
40+ def test_dir_export_existing_single_file(self):
41+ self.build_tree(['dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
42+ wtree = self.make_branch_and_tree('dir1')
43+ wtree.add(['dir2', 'first', 'dir2/second'])
44+ wtree.commit('1')
45+ export.export(wtree, 'target1', format='dir', subdir='first')
46+ self.failUnlessExists('target1/first')
47+ export.export(wtree, 'target2', format='dir', subdir='dir2/second')
48+ self.failUnlessExists('target2/second')
49+