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
=== modified file 'NEWS'
--- NEWS 2009-09-25 21:05:28 +0000
+++ NEWS 2009-09-28 03:00:29 +0000
@@ -2,6 +2,37 @@
2Bazaar Release Notes2Bazaar Release Notes
3####################3####################
44
52.0 series (not released)
6#########################
7
8Compatibility Breaks
9********************
10
11New Features
12************
13
14Bug Fixes
15*********
16
17* ``bzr add`` in a tree that has files with ``\r`` or ``\n`` in the
18 filename will issue a warning and skip over those files.
19 (Robert Collins, #3918)
20
21Improvements
22************
23
24Documentation
25*************
26
27API Changes
28***********
29
30Internals
31*********
32
33Testing
34*******
35
5bzr 2.0.136bzr 2.0.1
6##########37##########
738
839
=== modified file 'bzrlib/mutabletree.py'
--- bzrlib/mutabletree.py 2009-09-07 23:14:05 +0000
+++ bzrlib/mutabletree.py 2009-09-28 03:00:29 +0000
@@ -23,6 +23,7 @@
23from bzrlib.lazy_import import lazy_import23from bzrlib.lazy_import import lazy_import
24lazy_import(globals(), """24lazy_import(globals(), """
25import os25import os
26import re
2627
27from bzrlib import (28from bzrlib import (
28 add,29 add,
@@ -427,6 +428,7 @@
427 dirs_to_add.append((path, None))428 dirs_to_add.append((path, None))
428 prev_dir = path.raw_path429 prev_dir = path.raw_path
429430
431 illegalpath_re = re.compile(r'[\r\n]')
430 # dirs_to_add is initialised to a list of directories, but as we scan432 # dirs_to_add is initialised to a list of directories, but as we scan
431 # directories we append files to it.433 # directories we append files to it.
432 # XXX: We should determine kind of files when we scan them rather than434 # XXX: We should determine kind of files when we scan them rather than
@@ -443,6 +445,9 @@
443 if not InventoryEntry.versionable_kind(kind):445 if not InventoryEntry.versionable_kind(kind):
444 warning("skipping %s (can't add file of kind '%s')", abspath, kind)446 warning("skipping %s (can't add file of kind '%s')", abspath, kind)
445 continue447 continue
448 if illegalpath_re.search(directory.raw_path):
449 warning("skipping %r (contains \\n or \\r)" % abspath)
450 continue
446451
447 if parent_ie is not None:452 if parent_ie is not None:
448 versioned = directory.base_path in parent_ie.children453 versioned = directory.base_path in parent_ie.children
449454
=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
--- bzrlib/tests/per_workingtree/test_smart_add.py 2009-07-10 07:14:02 +0000
+++ bzrlib/tests/per_workingtree/test_smart_add.py 2009-09-28 03:00:29 +0000
@@ -51,6 +51,18 @@
51 self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],51 self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
52 files)52 files)
5353
54 def assertFilenameSkipped(self, filename):
55 tree = self.make_branch_and_tree('tree')
56 self.build_tree(['tree/'+filename])
57 tree.smart_add(['tree'])
58 self.assertEqual(None, tree.path2id(filename))
59
60 def test_path_containing_newline_skips(self):
61 self.assertFilenameSkipped('a\nb')
62
63 def test_path_containing_carriagereturn_skips(self):
64 self.assertFilenameSkipped('a\rb')
65
54 def test_save_false(self):66 def test_save_false(self):
55 """Dry-run add doesn't permanently affect the tree."""67 """Dry-run add doesn't permanently affect the tree."""
56 wt = self.make_branch_and_tree('.')68 wt = self.make_branch_and_tree('.')

Subscribers

People subscribed via source and target branches