Merge lp:~piastucki/bzr-xmloutput/fix-551351-ignored-in-symlink-root into lp:bzr-xmloutput

Proposed by Piotr Piastucki
Status: Merged
Merged at revision: 174
Proposed branch: lp:~piastucki/bzr-xmloutput/fix-551351-ignored-in-symlink-root
Merge into: lp:bzr-xmloutput
Diff against target: 57 lines (+23/-9)
2 files modified
lsxml.py (+6/-9)
tests/test_ls_xml.py (+17/-0)
To merge this branch: bzr merge lp:~piastucki/bzr-xmloutput/fix-551351-ignored-in-symlink-root
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+173101@code.launchpad.net

Description of the change

This patch fixes the way ignored files are handled in case the branch is access via symlink rather than a real path.

Invoking xmlls in the following way
bzr xmlls --ignored symlink

Results in an error (see traceback below) because the code first concatenates the symlink with the relative path of the ignored file and then tries to get the relative path by calling tree.relpath(fp). tree.relpath(fp) cannot find the relative path as bzr seems to expand symlinks so that the branch root (tree.basedir) contains the actual path.
The fix changes the order of pattern lookup and path concatenation and completely removes the need to call tree.relpath(fp).

Traceback:
0.102 Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/xmloutput/xml_errors.py", line 69, in xml_error_handling
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/xmloutput/cmds.py", line 385, in run
    lsxml.show_ls_xml(self.outf, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/xmloutput/lsxml.py", line 89, in show_ls_xml
    pattern = '<pattern>%s</pattern>' % _escape_cdata(pat)
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/xmloutput/writer.py", line 13, in _escape_cdata
    text = text.replace("&", "&amp;")
AttributeError: 'NoneType' object has no attribute 'replace'

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Thanks for working on this, can I ask you to add a test case for it?

Thanks.

review: Needs Information
174. By Piotr Piastucki

Add test case

Revision history for this message
Piotr Piastucki (piastucki) wrote :

Test case added

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lsxml.py'
2--- lsxml.py 2011-12-12 15:11:38 +0000
3+++ lsxml.py 2013-08-26 19:03:54 +0000
4@@ -71,6 +71,12 @@
5 continue
6 if kind is not None and fkind != kind:
7 continue
8+ if fc == 'I' and ignored:
9+ # get the pattern
10+ pat = tree.is_ignored(fp)
11+ pattern = '<pattern>%s</pattern>' % _escape_cdata(pat)
12+ else:
13+ pattern = ''
14 if prefix:
15 fp = osutils.pathjoin(prefix, fp)
16 if fid is None:
17@@ -80,15 +86,6 @@
18 fkind = '<kind>%s</kind>' % fkind
19 status_kind = '<status_kind>%s</status_kind>' % long_status_kind[fc]
20 fpath = '<path>%s</path>' % _escape_cdata(fp)
21- if fc == 'I' and ignored:
22- # get the pattern
23- if tree.basedir in fp:
24- pat = tree.is_ignored(tree.relpath(fp))
25- else:
26- pat = tree.is_ignored(fp)
27- pattern = '<pattern>%s</pattern>' % _escape_cdata(pat)
28- else:
29- pattern = ''
30 outstring = '<item>%s%s%s%s%s</item>' % (fid, fkind, fpath,
31 status_kind, pattern)
32 outf.write(outstring)
33
34=== modified file 'tests/test_ls_xml.py'
35--- tests/test_ls_xml.py 2012-02-21 10:14:16 +0000
36+++ tests/test_ls_xml.py 2013-08-26 19:03:54 +0000
37@@ -318,4 +318,21 @@
38 'path': 'a',
39 'status_kind': 'versioned'}]
40 self.assertEquals(expected_items, self.run_xmlls('--revision 1'))
41+
42+ def test_lsxml_ignored_symlink(self):
43+ # Ignored files inside a symlink directory
44+ self.wt.add(['a', '.bzrignore'], ['a-id', 'bzrignore-id'])
45+ self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
46+ symlink = self.test_dir + '_symlink'
47+ os.symlink(self.test_dir, symlink)
48+ expected_items = [{'kind': 'file',
49+ 'path': os.path.join(symlink, 'blah.pyo'),
50+ 'pattern': '*.pyo',
51+ 'status_kind': 'ignored'},
52+ {'kind': 'file',
53+ 'path': os.path.join(symlink, 'user-ignore'),
54+ 'pattern': 'user-ignore',
55+ 'status_kind': 'ignored'}]
56+ self.assertEquals(expected_items, self.run_xmlls('--ignored ' + symlink))
57+
58

Subscribers

People subscribed via source and target branches

to all changes: