annotate diff_cmd.py @ 122:04c92c2c4501

SubversionRepo: work around ra.get_files() not releasing input buffer
author Patrick Mezard <pmezard@gmail.com>
date Tue, 02 Dec 2008 20:13:13 -0600
parents 91ce18fa0375
children 40474f6c1f84
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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))