Merge lp:~lifeless/bzr/bug-3918 into lp:bzr/2.0

Proposed by Robert Collins
Status: Merged
Approved by: Andrew Bennetts
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~lifeless/bzr/bug-3918
Merge into: lp:bzr/2.0
Diff against target: 94 lines
3 files modified
NEWS (+31/-0)
bzrlib/mutabletree.py (+5/-0)
bzrlib/tests/per_workingtree/test_smart_add.py (+12/-0)
To merge this branch: bzr merge lp:~lifeless/bzr/bug-3918
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+12505@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This avoids adding filenames containing \r or \n to the dirstate via 'bzr add', which prevents a common source of 'wtf' for people with odd trees that they are importing via the command line.

Revision history for this message
Andrew Bennetts (spiv) wrote :

Looks sane.

(It would be nice to actually support \r and \n in filenames, but I see that even 2a still barfs on that :( )

review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

> Looks sane.

Oh, and I'm not very familiar with the dirstate code, but I assume this change will also catch filenames from sources other than add, e.g. like "bzr mv foo foo\nbar" ?

Revision history for this message
Robert Collins (lifeless) wrote :

It won't catch 'mv', because of layers and costs.

so, apply_inventory_delta is the right place to fully catch it, but some
code still does a full inventory serialisation.

So this really only catches the _common_ case - 'bzr add BAD'

-Rob

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

Congratulations on fixing what may be the oldest open bug.

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

Revision history for this message
Robert Collins (lifeless) wrote :

On Mon, 2009-09-28 at 05:09 +0000, Martin Pool wrote:
> Congratulations on fixing what may be the oldest open bug.

Thanks :). Its not really fixed, just put behind a small wall - but the
wall that /most/ users have been complaining about the lack of. We
should finish making inventory deltas The Way to update dirstate, and
then put the check in apply_inventory_delta, at which point mv and
direct API usage will also be unable to add such paths.

-Rob

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

Good to see that bug caught.

Yet, shouldn't the long term plan *accept* these paths ?

I'm mostly thinking about conversions from foreign VCS here.
We already encouter the problem in such contexts.

So may be we need a way to address the issue by accepting the
path and *renaming* it on the fly in some canonical way that
allows tracking further changes on it ?

Revision history for this message
Robert Collins (lifeless) wrote :

On Mon, 2009-09-28 at 08:30 +0000, Vincent Ladeuil wrote:
> Good to see that bug caught.
>
> Yet, shouldn't the long term plan *accept* these paths ?
>
> I'm mostly thinking about conversions from foreign VCS here.
> We already encouter the problem in such contexts.
>
> So may be we need a way to address the issue by accepting the
> path and *renaming* it on the fly in some canonical way that
> allows tracking further changes on it ?

Follow up to the bug please :). I suggest repeating this particular
comment there, as the merge proposal will be invisible to others wanting
to think about this, now that its landed.

-Rob

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

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

Robert Collins wrote:
> Robert Collins has proposed merging lp:~lifeless/bzr/bug-3918 into lp:bzr/2.0.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> #3918 bzr can be caused to error with filenames containing newlines
> https://bugs.launchpad.net/bugs/3918
>
>
> This avoids adding filenames containing \r or \n to the dirstate via 'bzr add', which prevents a common source of 'wtf' for people with odd trees that they are importing via the command line.
>

I came late and this has already landed, but '\\' is also not allowed
(ATM). I think there might be some other characters. '\t' wasn't
supported in XML, IIRC, it may be supported in dirstate + 2a.

Just thinking if this gives a nice error about what is going wrong and
skipping a bad filename, it would probably be nice to unify it with some
of the other exceptional cases.

John
=:->

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

iEYEARECAAYFAkrAwrwACgkQJdeBCYSNAAOGGgCeJPEolRP+0u3xIUlHffQr59bX
Mh4AoLk9uMqrdGAzUVsAOxJmDosuJKll
=9roN
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-09-25 21:05:28 +0000
3+++ NEWS 2009-09-28 03:00:29 +0000
4@@ -2,6 +2,37 @@
5 Bazaar Release Notes
6 ####################
7
8+2.0 series (not released)
9+#########################
10+
11+Compatibility Breaks
12+********************
13+
14+New Features
15+************
16+
17+Bug Fixes
18+*********
19+
20+* ``bzr add`` in a tree that has files with ``\r`` or ``\n`` in the
21+ filename will issue a warning and skip over those files.
22+ (Robert Collins, #3918)
23+
24+Improvements
25+************
26+
27+Documentation
28+*************
29+
30+API Changes
31+***********
32+
33+Internals
34+*********
35+
36+Testing
37+*******
38+
39 bzr 2.0.1
40 ##########
41
42
43=== modified file 'bzrlib/mutabletree.py'
44--- bzrlib/mutabletree.py 2009-09-07 23:14:05 +0000
45+++ bzrlib/mutabletree.py 2009-09-28 03:00:29 +0000
46@@ -23,6 +23,7 @@
47 from bzrlib.lazy_import import lazy_import
48 lazy_import(globals(), """
49 import os
50+import re
51
52 from bzrlib import (
53 add,
54@@ -427,6 +428,7 @@
55 dirs_to_add.append((path, None))
56 prev_dir = path.raw_path
57
58+ illegalpath_re = re.compile(r'[\r\n]')
59 # dirs_to_add is initialised to a list of directories, but as we scan
60 # directories we append files to it.
61 # XXX: We should determine kind of files when we scan them rather than
62@@ -443,6 +445,9 @@
63 if not InventoryEntry.versionable_kind(kind):
64 warning("skipping %s (can't add file of kind '%s')", abspath, kind)
65 continue
66+ if illegalpath_re.search(directory.raw_path):
67+ warning("skipping %r (contains \\n or \\r)" % abspath)
68+ continue
69
70 if parent_ie is not None:
71 versioned = directory.base_path in parent_ie.children
72
73=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
74--- bzrlib/tests/per_workingtree/test_smart_add.py 2009-07-10 07:14:02 +0000
75+++ bzrlib/tests/per_workingtree/test_smart_add.py 2009-09-28 03:00:29 +0000
76@@ -51,6 +51,18 @@
77 self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
78 files)
79
80+ def assertFilenameSkipped(self, filename):
81+ tree = self.make_branch_and_tree('tree')
82+ self.build_tree(['tree/'+filename])
83+ tree.smart_add(['tree'])
84+ self.assertEqual(None, tree.path2id(filename))
85+
86+ def test_path_containing_newline_skips(self):
87+ self.assertFilenameSkipped('a\nb')
88+
89+ def test_path_containing_carriagereturn_skips(self):
90+ self.assertFilenameSkipped('a\rb')
91+
92 def test_save_false(self):
93 """Dry-run add doesn't permanently affect the tree."""
94 wt = self.make_branch_and_tree('.')

Subscribers

People subscribed via source and target branches