Mercurial > hgsubversion
comparison diff_cmd.py @ 100:91ce18fa0375
Add a diff command that behaves kind of like svn diff.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Fri, 21 Nov 2008 16:15:23 -0600 |
| parents | |
| children | 40474f6c1f84 |
comparison
equal
deleted
inserted
replaced
| 99:1da7aafdd323 | 100:91ce18fa0375 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 import re | |
| 3 | |
| 4 from mercurial import patch | |
| 5 | |
| 6 import util | |
| 7 import hg_delta_editor | |
| 8 | |
| 9 b_re = re.compile(r'^\+\+\+ b\/([^\n]*)', re.MULTILINE) | |
| 10 a_re = re.compile(r'^--- a\/([^\n]*)', re.MULTILINE) | |
| 11 devnull_re = re.compile(r'^([-+]{3}) /dev/null', re.MULTILINE) | |
| 12 header_re = re.compile(r'^diff --git .* b\/(.*)', re.MULTILINE) | |
| 13 newfile_devnull_re = re.compile(r'^--- /dev/null\n\+\+\+ b/([^\n]*)', | |
| 14 re.MULTILINE) | |
| 15 def filterdiff(diff, base_revision): | |
| 16 diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' | |
| 17 r'+++ \1\t(working copy)', | |
| 18 diff) | |
| 19 diff = a_re.sub(r'--- \1'+ ('\t(revision %d)' % base_revision), diff) | |
| 20 diff = b_re.sub(r'+++ \1' + '\t(working copy)', diff) | |
| 21 diff = devnull_re.sub(r'\1 /dev/null' '\t(working copy)', diff) | |
| 22 | |
| 23 diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff) | |
| 24 return diff | |
| 25 | |
| 26 | |
| 27 @util.register_subcommand('diff') | |
| 28 def diff_command(ui, repo, hg_repo_path, **opts): | |
| 29 """Show a diff of the most recent revision against its parent from svn. | |
| 30 """ | |
| 31 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, | |
| 32 ui_=ui) | |
| 33 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), | |
| 34 hge.revmap.iterkeys())) | |
| 35 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) | |
| 36 parent = repo.parents()[0] | |
| 37 if o_r: | |
| 38 parent = repo[o_r[-1]].parents()[0] | |
| 39 base_rev, _junk = svn_commit_hashes[parent.node()] | |
| 40 it = patch.diff(repo, parent.node(), None, | |
| 41 opts=patch.diffopts(ui, opts)) | |
| 42 ui.write(filterdiff(''.join(it), base_rev)) |
