Mercurial > hgsubversion
annotate diff_cmd.py @ 131:4d42dbbb5127
hg_delta_editor: fix parent revision detection on branch copy
Project items copyfrom revisions are irrelevant to parent revision detection,
only the project one or those of its ancestors matter. Items copyfrom is
useful when retrieving items content.
Former code resulted in incorrect converted graph for pyglet repository,
especially on the following revision:
------------------------------------------------------------------------
r274 | r1chardj0n3s | 2006-12-21 02:02:14 +0100 (Jeu, 21 Dec 2006) | 2 lines
Changed paths:
A /branches/richard-glx-version (from /trunk:269)
M /branches/richard-glx-version/pyglet/window/xlib/__init__.py
R /branches/richard-glx-version/tests/test.py (from /trunk/tests/test.py:270)
R /branches/richard-glx-version/tools/info.py (from /trunk/tools/info.py:272)
R /branches/richard-glx-version/website/get_involved.php (from /trunk/website/get_involved.php:273)
Branching to horribly mangle GLX
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Wed, 10 Dec 2008 11:03:22 -0600 |
parents | 91ce18fa0375 |
children | 40474f6c1f84 |
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 @util.register_subcommand('diff') |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
28 def diff_command(ui, repo, hg_repo_path, **opts): |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
29 """Show a diff of the most recent revision against its parent from svn. |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
30 """ |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
31 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
|
32 ui_=ui) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
33 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
|
34 hge.revmap.iterkeys())) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
35 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
36 parent = repo.parents()[0] |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
37 if o_r: |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
38 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
|
39 base_rev, _junk = svn_commit_hashes[parent.node()] |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
40 it = patch.diff(repo, parent.node(), None, |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
41 opts=patch.diffopts(ui, opts)) |
91ce18fa0375
Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
42 ui.write(filterdiff(''.join(it), base_rev)) |