Merge lp:~parthm/bzr/596785-diff-no-dir-error into lp:bzr

Proposed by Parth Malwankar
Status: Rejected
Rejected by: John A Meinel
Proposed branch: lp:~parthm/bzr/596785-diff-no-dir-error
Merge into: lp:bzr
Diff against target: 49 lines (+18/-0)
3 files modified
NEWS (+3/-0)
bzrlib/builtins.py (+5/-0)
bzrlib/tests/blackbox/test_diff.py (+10/-0)
To merge this branch: bzr merge lp:~parthm/bzr/596785-diff-no-dir-error
Reviewer Review Type Date Requested Status
John A Meinel Disapprove
Review via email: mp+28653@code.launchpad.net

Commit message

`bzr diff --old|new PATH` now show an error if PATH is not a directory. Fixes #596785.

Description of the change

=== Fixed Bug #596785 ===
`bzr diff --old|new PATH` now show an error if PATH is not a dir. Without this patch it exists silently which is confusing (i.e. no diff output).

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

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

Parth Malwankar wrote:
> Parth Malwankar has proposed merging lp:~parthm/bzr/596785-diff-no-dir-error into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> #596785 'bzr diff --old|new PATH' does silently exists if arg does not exist
> https://bugs.launchpad.net/bugs/596785
>
>
> === Fixed Bug #596785 ===
> `bzr diff --old|new PATH` now show an error if PATH is not a dir. Without this patch it exists silently which is confusing (i.e. no diff output).
>
>

old and new can be URLs which will fail your isdir() check, but not fail
to work.

 merge: rejected

If you really want something like this, use a check something like:
  if old is not None and old_tree is None:
    fail

John
=:->

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

iEYEARECAAYFAkwo0REACgkQJdeBCYSNAANIIgCgkW2ttdDtydFdKxdYF9LI5Ard
1EcAoIGBngukt8Y89oOLH31v5C5eC4G6
=ghVe
-----END PGP SIGNATURE-----

review: Disapprove
Revision history for this message
Parth Malwankar (parthm) wrote :

> old and new can be URLs which will fail your isdir() check, but not fail
> to work.
>

Good point. I should have thought of that :P

> If you really want something like this, use a check something like:
>  if old is not None and old_tree is None:
>    fail

Interestingly, old_tree is not None even with an invalid path. With
the following patch:

=== modified file 'bzrlib/diff.py'
--- bzrlib/diff.py 2010-05-26 15:58:08 +0000
+++ bzrlib/diff.py 2010-06-28 17:24:13 +0000
@@ -395,12 +395,15 @@
         old_url = default_location
     working_tree, branch, relpath = \
         bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
+ print "wt:", working_tree, "br:", branch, "relpath:", relpath
+ print "has relpath:", branch.control_transport.has(relpath)
     lock_tree_or_branch(working_tree, branch)
     if consider_relpath and relpath != '':
         if working_tree is not None and apply_view:
             views.check_path_in_view(working_tree, relpath)
         specific_files.append(relpath)
     old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
+ print "old_tree:", old_tree
     old_branch = branch

     # Get the new location
@@ -441,6 +444,8 @@
     extra_trees = None
     if working_tree is not None and working_tree not in (old_tree, new_tree):
         extra_trees = (working_tree,)
+ print "old_branch:", old_branch

I get:

wt: <WorkingTree6 of
/storage/parth/src/bzr.dev/596785-diff-no-dir-error> br:
BzrBranch7(file:///storage/parth/src/bzr.dev/596785-diff-no-dir-error/)
relpath: foobar
has relpath: False
old_tree: <DirStateRevisionTree of
<email address hidden> in
DirState(u'/storage/parth/src/bzr.dev/596785-diff-no-dir-error/.bzr/checkout/dirstate')>
old_branch: BzrBranch7(file:///storage/parth/src/bzr.dev/596785-diff-no-dir-error/)

I am thinking that `branch.control_transport.has(relpath)` check could
be used to set old_tree/new_tree to None and check these in
cmd_diff.run as you suggested. Does that seem like a good solution?

Thanks for the review.

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

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

Parth Malwankar wrote:
>> old and new can be URLs which will fail your isdir() check, but not fail
>> to work.
>>
>
> Good point. I should have thought of that :P
>
>> If you really want something like this, use a check something like:
>> if old is not None and old_tree is None:
>> fail
>
> Interestingly, old_tree is not None even with an invalid path. With
> the following patch:
>
> === modified file 'bzrlib/diff.py'
> --- bzrlib/diff.py 2010-05-26 15:58:08 +0000
> +++ bzrlib/diff.py 2010-06-28 17:24:13 +0000
> @@ -395,12 +395,15 @@
> old_url = default_location
> working_tree, branch, relpath = \
> bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
> + print "wt:", working_tree, "br:", branch, "relpath:", relpath
> + print "has relpath:", branch.control_transport.has(relpath)
> lock_tree_or_branch(working_tree, branch)
> if consider_relpath and relpath != '':
> if working_tree is not None and apply_view:
> views.check_path_in_view(working_tree, relpath)
> specific_files.append(relpath)
> old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
> + print "old_tree:", old_tree
> old_branch = branch
>

offhand I would guess that you are getting a containing workingtree. I'm
not sure what should be done about relpath.

At least in my mind '--old' and '--new' are meant to be the exact path
to a branch (or wt), and not have any remainder.

So one option is just:
  if old is not None and (old_tree is None or relpath):
    ..

Is the relpath for the old_url used? If it isn't, then I think my point
stands.

John
=:->

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

iEYEARECAAYFAkwo4AIACgkQJdeBCYSNAAM0MwCgr67dVr1JkSz2HwHDudMFAnuR
j3AAn0TfpwNtD6L/qsFwtYAmuGb034Jg
=QKQr
-----END PGP SIGNATURE-----

Unmerged revisions

5326. By Parth Malwankar

updated NEWS

5325. By Parth Malwankar

diff now raises an error if --old/new are supplied invalid path.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-06-28 03:23:26 +0000
3+++ NEWS 2010-06-28 16:07:25 +0000
4@@ -64,6 +64,9 @@
5 * ``BzrDir.find_bzrdirs`` should ignore dirs that raises PermissionDenied.
6 (Marius Kruger, Robert Collins)
7
8+* ``diff --old|--new PATH`` now show an error message if PATH is not a
9+ directory. (Parth Malwankar, #596785)
10+
11 * Ensure that wrong path specifications in ``BZR_PLUGINS_AT`` display
12 proper error messages. (Vincent Ladeuil, #591215)
13
14
15=== modified file 'bzrlib/builtins.py'
16--- bzrlib/builtins.py 2010-06-17 08:53:15 +0000
17+++ bzrlib/builtins.py 2010-06-28 16:07:25 +0000
18@@ -1966,6 +1966,11 @@
19 raise errors.BzrCommandError('--using and --format are mutually '
20 'exclusive.')
21
22+ if old and not osutils.isdir(old):
23+ raise errors.NotADirectory(old)
24+ if new and not osutils.isdir(new):
25+ raise errors.NotADirectory(new)
26+
27 (old_tree, new_tree,
28 old_branch, new_branch,
29 specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
30
31=== modified file 'bzrlib/tests/blackbox/test_diff.py'
32--- bzrlib/tests/blackbox/test_diff.py 2010-04-05 21:56:39 +0000
33+++ bzrlib/tests/blackbox/test_diff.py 2010-06-28 16:07:25 +0000
34@@ -321,6 +321,16 @@
35 output = self.run_bzr('diff --format=boo', retcode=1)
36 self.assertTrue("BOO!" in output[0])
37
38+ def test_diff_old_new_error(self):
39+ """Ensure --old/new produce error for invalid path."""
40+ tree = self.make_example_branch()
41+ out, err = self.run_bzr(['diff', '--old', 'foobar'], 3)
42+ self.assertEquals(out, '')
43+ self.assertContainsRe(err, 'ERROR.*foobar.*not a directory')
44+ out, err = self.run_bzr(['diff', '--new', 'foobar'], 3)
45+ self.assertEquals(out, '')
46+ self.assertContainsRe(err, 'ERROR.*foobar.*not a directory')
47+
48
49 class TestCheckoutDiff(TestDiff):
50