annotate diff_cmd.py @ 152:1fde85a10f9e

push: Fix the bad implementation that required modifying the dirstate to push.
author Augie Fackler <durin42@gmail.com>
date Mon, 22 Dec 2008 21:22:11 -0600
parents 40474f6c1f84
children e37f9d3fd5e7
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 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
36 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
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()]
138
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
40 it = patch.diff(repo, parent.node(), None,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
41 opts=patch.diffopts(ui, opts={'git': True,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
42 'show_function': False,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
43 'ignore_all_space': False,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
44 'ignore_space_change': False,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
45 'ignore_blank_lines': False,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
46 'unified': True,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
47 'text': False,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 100
diff changeset
48 }))
100
91ce18fa0375 Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 ui.write(filterdiff(''.join(it), base_rev))