Mercurial > hgsubversion
annotate diff_cmd.py @ 300:4aba7542f6a9
Various cleanups, cosmetics and removal of superfluous assertions.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 27 Mar 2009 03:16:21 +0100 |
parents | 57355b0e7bd1 |
children |
rev | line source |
---|---|
100
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
2 import re |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
3 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 from mercurial import patch |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
6 import util |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 import hg_delta_editor |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
8 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
9 b_re = re.compile(r'^\+\+\+ b\/([^\n]*)', re.MULTILINE) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
10 a_re = re.compile(r'^--- a\/([^\n]*)', re.MULTILINE) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
11 devnull_re = re.compile(r'^([-+]{3}) /dev/null', re.MULTILINE) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
12 header_re = re.compile(r'^diff --git .* b\/(.*)', re.MULTILINE) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
13 newfile_devnull_re = re.compile(r'^--- /dev/null\n\+\+\+ b/([^\n]*)', |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 re.MULTILINE) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
15 def filterdiff(diff, base_revision): |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
16 diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
17 r'+++ \1\t(working copy)', |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
18 diff) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
19 diff = a_re.sub(r'--- \1'+ ('\t(revision %d)' % base_revision), diff) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
20 diff = b_re.sub(r'+++ \1' + '\t(working copy)', diff) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
21 diff = devnull_re.sub(r'\1 /dev/null' '\t(working copy)', diff) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
22 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
23 diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
24 return diff |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
25 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
26 |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
27 def diff_command(ui, repo, hg_repo_path, **opts): |
185
57355b0e7bd1
Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents:
181
diff
changeset
|
28 """show a diff of the most recent revision against its parent from svn |
100
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
29 """ |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
30 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
31 ui_=ui) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
32 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
33 hge.revmap.iterkeys())) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
34 parent = repo.parents()[0] |
152
1fde85a10f9e
push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents:
138
diff
changeset
|
35 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, parent.node()) |
100
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
36 if o_r: |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
37 parent = repo[o_r[-1]].parents()[0] |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
38 base_rev, _junk = svn_commit_hashes[parent.node()] |
138
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
39 it = patch.diff(repo, parent.node(), None, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
40 opts=patch.diffopts(ui, opts={'git': True, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
41 'show_function': False, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
42 'ignore_all_space': False, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
43 'ignore_space_change': False, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
44 'ignore_blank_lines': False, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
45 'unified': True, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
46 'text': False, |
40474f6c1f84
diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents:
100
diff
changeset
|
47 })) |
100
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
48 ui.write(filterdiff(''.join(it), base_rev)) |
181
e37f9d3fd5e7
remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
152
diff
changeset
|
49 diff_command = util.register_subcommand('diff')(diff_command) |