Mercurial > hgsubversion
changeset 244:28d0ee605308
Move diff to svncommands.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 08 Apr 2009 18:21:47 +0200 |
parents | 2027f851d60c |
children | f8e9b74df403 |
files | cmdutil.py diff_cmd.py svncommand.py svncommands.py tests/test_diff.py |
diffstat | 5 files changed, 52 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/cmdutil.py +++ b/cmdutil.py @@ -1,3 +1,5 @@ +#!/usr/bin/python +import re from mercurial import util as hgutil @@ -7,11 +9,31 @@ import svnwrap import svnexternals +b_re = re.compile(r'^\+\+\+ b\/([^\n]*)', re.MULTILINE) +a_re = re.compile(r'^--- a\/([^\n]*)', re.MULTILINE) +devnull_re = re.compile(r'^([-+]{3}) /dev/null', re.MULTILINE) +header_re = re.compile(r'^diff --git .* b\/(.*)', re.MULTILINE) +newfile_devnull_re = re.compile(r'^--- /dev/null\n\+\+\+ b/([^\n]*)', + re.MULTILINE) + + class NoFilesException(Exception): """Exception raised when you try and commit without files. """ +def filterdiff(diff, base_revision): + diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' + r'+++ \1\t(working copy)', + diff) + diff = a_re.sub(r'--- \1'+ ('\t(revision %d)' % base_revision), diff) + diff = b_re.sub(r'+++ \1' + '\t(working copy)', diff) + diff = devnull_re.sub(r'\1 /dev/null' '\t(working copy)', diff) + + diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff) + return diff + + def replay_convert_rev(hg_editor, svn, r): hg_editor.set_current_rev(r) svn.get_replay(r.revnum, hg_editor)
deleted file mode 100644 --- a/diff_cmd.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python -import re - -from mercurial import patch - -import util -import hg_delta_editor - -b_re = re.compile(r'^\+\+\+ b\/([^\n]*)', re.MULTILINE) -a_re = re.compile(r'^--- a\/([^\n]*)', re.MULTILINE) -devnull_re = re.compile(r'^([-+]{3}) /dev/null', re.MULTILINE) -header_re = re.compile(r'^diff --git .* b\/(.*)', re.MULTILINE) -newfile_devnull_re = re.compile(r'^--- /dev/null\n\+\+\+ b/([^\n]*)', - re.MULTILINE) -def filterdiff(diff, base_revision): - diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' - r'+++ \1\t(working copy)', - diff) - diff = a_re.sub(r'--- \1'+ ('\t(revision %d)' % base_revision), diff) - diff = b_re.sub(r'+++ \1' + '\t(working copy)', diff) - diff = devnull_re.sub(r'\1 /dev/null' '\t(working copy)', diff) - - diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff) - return diff - - -def diff_command(ui, repo, hg_repo_path, **opts): - """show a diff of the most recent revision against its parent from svn - """ - hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, - ui_=ui) - svn_commit_hashes = dict(zip(hge.revmap.itervalues(), - hge.revmap.iterkeys())) - parent = repo.parents()[0] - o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, parent.node()) - if o_r: - parent = repo[o_r[-1]].parents()[0] - base_rev, _junk = svn_commit_hashes[parent.node()] - it = patch.diff(repo, parent.node(), None, - opts=patch.diffopts(ui, opts={'git': True, - 'show_function': False, - 'ignore_all_space': False, - 'ignore_space_change': False, - 'ignore_blank_lines': False, - 'unified': True, - 'text': False, - })) - ui.write(filterdiff(''.join(it), base_rev)) -diff_command = util.register_subcommand('diff')(diff_command)
--- a/svncommand.py +++ b/svncommand.py @@ -8,12 +8,11 @@ from mercurial import node import util from util import register_subcommand, svn_subcommands, generate_help, svn_commands_nourl # dirty trick to force demandimport to run my decorator anyway. -from svncommands import pull +from svncommands import pull, diff from utility_commands import print_wc_url -from diff_cmd import diff_command from rebuildmeta import rebuildmeta # shut up, pyflakes, we must import those -__x = [print_wc_url, pull, diff_command, rebuildmeta] +__x = [print_wc_url, pull, diff, rebuildmeta] def svncmd(ui, repo, subcommand, *args, **opts):
--- a/svncommands.py +++ b/svncommands.py @@ -2,6 +2,7 @@ import os from mercurial import hg from mercurial import node +from mercurial import patch from mercurial import util as hgutil from svn import core @@ -185,3 +186,28 @@ def push(ui, repo, hg_repo_path, svn_url push = util.register_subcommand('push')(push) # for git expats dcommit = util.register_subcommand('dcommit')(push) + + +def diff(ui, repo, hg_repo_path, **opts): + """show a diff of the most recent revision against its parent from svn + """ + hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, + ui_=ui) + svn_commit_hashes = dict(zip(hge.revmap.itervalues(), + hge.revmap.iterkeys())) + parent = repo.parents()[0] + o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, parent.node()) + if o_r: + parent = repo[o_r[-1]].parents()[0] + base_rev, _junk = svn_commit_hashes[parent.node()] + it = patch.diff(repo, parent.node(), None, + opts=patch.diffopts(ui, opts={'git': True, + 'show_function': False, + 'ignore_all_space': False, + 'ignore_space_change': False, + 'ignore_blank_lines': False, + 'unified': True, + 'text': False, + })) + ui.write(cmdutil.filterdiff(''.join(it), base_rev)) +diff = util.register_subcommand('diff')(diff)
--- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -2,7 +2,7 @@ import unittest from mercurial import ui -import diff_cmd +import svncommands import test_util @@ -32,7 +32,7 @@ class DiffTests(test_util.TestBase): ('alpha', 'alpha', 'alpha\n\nadded line\n'), ]) u = ui.ui() - diff_cmd.diff_command(u, self.repo, self.wc_path) + svncommands.diff(u, self.repo, self.wc_path) self.assertEqual(u.stream.getvalue(), expected_diff_output)