Merge lp:~bzr-eclipse/bzr-xmloutput/xmlls-verbose-mode into lp:bzr-xmloutput

Proposed by Piotr Piastucki
Status: Needs review
Proposed branch: lp:~bzr-eclipse/bzr-xmloutput/xmlls-verbose-mode
Merge into: lp:bzr-xmloutput
Diff against target: 110 lines (+64/-6)
2 files modified
lsxml.py (+22/-5)
tests/test_ls_xml.py (+42/-1)
To merge this branch: bzr merge lp:~bzr-eclipse/bzr-xmloutput/xmlls-verbose-mode
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Pending
Review via email: mp+183818@code.launchpad.net

Description of the change

This patch adds support for --verbose flag to xmlls command. Verbose output contains additional information about the most recent revision of each file listed by xmlls including: revision number, committer name and timestamp as shown below.
This enhancement is crucial to make text file decorator work efficiently in bzr-eclipse.

<item>
<id>xml_errors.py-20080619205226-dorz3pen7q1idbwj-1</id>
<kind>file</kind><path>xml_errors.py</path>
<status_kind>versioned</status_kind>
<log>
<revno>148.1.3</revno>
<committer>Jelmer Vernooij &lt;<email address hidden>&gt;</committer>
<timestamp>Wed 2010-12-15 19:27:12 +0100</timestamp>
</log>
</item>

To post a comment you must log in.
176. By Piotr Piastucki

Minor cleanup

Unmerged revisions

176. By Piotr Piastucki

Minor cleanup

175. By Piotr Piastucki

Add verbose mode to xmlls command
When --verbose flag is set xmlls will print additional information about the most recent revision of each file including:
revision number, timestamp and committer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lsxml.py'
--- lsxml.py 2013-07-04 21:31:29 +0000
+++ lsxml.py 2013-09-04 11:13:44 +0000
@@ -57,10 +57,13 @@
57 prefix = fs_path + '/'57 prefix = fs_path + '/'
5858
59 if revision is not None:59 if revision is not None:
60 tree = branch.repository.revision_tree(60 tree = r_tree = branch.repository.revision_tree(
61 revision[0].as_revision_id(branch))61 revision[0].as_revision_id(branch))
62 elif tree is None:62 else:
63 tree = branch.basis_tree()63 if tree is None:
64 tree = branch.basis_tree()
65 if verbose:
66 r_tree = branch.basis_tree()
6467
65 tree.lock_read()68 tree.lock_read()
66 try:69 try:
@@ -79,15 +82,29 @@
79 pattern = ''82 pattern = ''
80 if prefix:83 if prefix:
81 fp = osutils.pathjoin(prefix, fp)84 fp = osutils.pathjoin(prefix, fp)
85 verbosestr = ''
82 if fid is None:86 if fid is None:
83 fid = ''87 fid = ''
84 else:88 else:
89 if verbose:
90 try:
91 revid = r_tree.get_file_revision(fid)
92 revno = branch.revision_id_to_dotted_revno(revid)
93 if isinstance(revno, tuple):
94 revno = '.'.join(map(str, revno))
95 rev = branch.repository.get_revision(revid)
96 date_str = osutils.format_date(rev.timestamp, rev.timezone or 0)
97 verbosestr='<log><revno>%s</revno><committer>%s</committer><timestamp>%s</timestamp></log>' \
98 % (revno, _escape_cdata(rev.committer), date_str)
99 except:
100 # e.g. newly added file not existing in any revision yet
101 pass
85 fid = '<id>%s</id>' % _escape_cdata(fid)102 fid = '<id>%s</id>' % _escape_cdata(fid)
86 fkind = '<kind>%s</kind>' % fkind103 fkind = '<kind>%s</kind>' % fkind
87 status_kind = '<status_kind>%s</status_kind>' % long_status_kind[fc]104 status_kind = '<status_kind>%s</status_kind>' % long_status_kind[fc]
88 fpath = '<path>%s</path>' % _escape_cdata(fp)105 fpath = '<path>%s</path>' % _escape_cdata(fp)
89 outstring = '<item>%s%s%s%s%s</item>' % (fid, fkind, fpath,106 outstring = '<item>%s%s%s%s%s%s</item>' % (fid, fkind, fpath,
90 status_kind, pattern)107 status_kind, pattern, verbosestr)
91 outf.write(outstring)108 outf.write(outstring)
92 finally:109 finally:
93 outf.write('</list>')110 outf.write('</list>')
94111
=== modified file 'tests/test_ls_xml.py'
--- tests/test_ls_xml.py 2013-08-26 18:53:37 +0000
+++ tests/test_ls_xml.py 2013-09-04 11:13:44 +0000
@@ -51,7 +51,12 @@
51 for item_elem in lst.findall('item'):51 for item_elem in lst.findall('item'):
52 item = {}52 item = {}
53 for attr in item_elem:53 for attr in item_elem:
54 item[attr.tag] = attr.text54 if attr.tag == 'log':
55 for log_item_elem in attr:
56 if log_item_elem.tag != 'timestamp':
57 item['log.' + log_item_elem.tag] = log_item_elem.text
58 else:
59 item[attr.tag] = attr.text
55 items.append(item)60 items.append(item)
56 return items61 return items
5762
@@ -335,4 +340,40 @@
335 'status_kind': 'ignored'}]340 'status_kind': 'ignored'}]
336 self.assertEquals(expected_items, self.run_xmlls('--ignored ' + symlink))341 self.assertEquals(expected_items, self.run_xmlls('--ignored ' + symlink))
337 342
343 def test_lsxml_verbose(self):
344 self.build_tree(['b', 'c', 'd', 'blah.pyo'])
345 self.wt.add(['a', '.bzrignore'], ['a-id', 'bzrignore-id'])
346 self.wt.commit('commit 1', committer='Paul')
347 self.wt.add(['d'], ['d-id'])
348 self.wt.commit('commit 2', committer='John')
349 self.wt.add(['c'], ['c-id'])
350 expected_items = [{'id': 'bzrignore-id',
351 'kind': 'file',
352 'log.committer': 'Paul',
353 'log.revno': '1',
354 'path': '.bzrignore',
355 'status_kind': 'versioned'},
356 {'id': 'a-id',
357 'kind': 'file',
358 'log.committer': 'Paul',
359 'log.revno': '1',
360 'path': 'a',
361 'status_kind': 'versioned'},
362 {'kind': 'file',
363 'path': 'b',
364 'status_kind': 'unknown'},
365 {'kind': 'file',
366 'path': 'blah.pyo',
367 'status_kind': 'ignored'},
368 {'id': 'c-id',
369 'kind': 'file',
370 'path': 'c',
371 'status_kind': 'versioned'},
372 {'id': 'd-id',
373 'kind': 'file',
374 'log.committer': 'John',
375 'log.revno': '2',
376 'path': 'd',
377 'status_kind': 'versioned'}]
378 self.assertEquals(expected_items, self.run_xmlls('--verbose'))
338379

Subscribers

People subscribed via source and target branches

to all changes: