Mercurial > hgsubversion
changeset 440:80909328aef1
move remaining cmdutils into util
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Tue, 16 Jun 2009 13:33:47 +0200 |
parents | d8f84daf744d |
children | de085126dbd4 |
files | hgsubversion/__init__.py hgsubversion/cmdutil.py hgsubversion/util.py hgsubversion/utility_commands.py hgsubversion/wrappers.py |
diffstat | 5 files changed, 65 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -34,7 +34,7 @@ demandimport.ignore.append('svn') from svn import core import svncommands -import cmdutil +import util import svnrepo import wrappers @@ -134,7 +134,7 @@ def reposetup(ui, repo): def _lookup(url): - if cmdutil.islocalrepo(url): + if util.islocalrepo(url): return svnrepo else: return hg._local(url)
deleted file mode 100644 --- a/hgsubversion/cmdutil.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/python -import re -import os -import urllib - -import util - - -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 formatrev(rev): - if rev == -1: - return '\t(working copy)' - return '\t(revision %d)' % rev - - -def filterdiff(diff, oldrev, newrev): - diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' - r'+++ \1\t(working copy)', - diff) - oldrev = formatrev(oldrev) - newrev = formatrev(newrev) - diff = a_re.sub(r'--- \1'+ oldrev, diff) - diff = b_re.sub(r'+++ \1' + newrev, 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 parentrev(ui, repo, meta, hashes): - """Find the svn parent revision of the repo's dirstate. - """ - workingctx = repo.parents()[0] - outrev = util.outgoing_revisions(repo, hashes, workingctx.node()) - if outrev: - workingctx = repo[outrev[-1]].parents()[0] - return workingctx - - -def islocalrepo(url): - if not url.startswith('file:///'): - return False - if '#' in url.split('/')[-1]: # strip off #anchor - url = url[:url.rfind('#')] - path = url[len('file://'):] - path = urllib.url2pathname(path).replace(os.sep, '/') - while '/' in path: - if reduce(lambda x,y: x and y, - map(lambda p: os.path.exists(os.path.join(path, p)), - ('hooks', 'format', 'db', ))): - return True - path = path.rsplit('/', 1)[0] - return False
--- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -1,10 +1,65 @@ +import re import os +import urllib from mercurial import hg from mercurial import node from mercurial import util as hgutil +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 formatrev(rev): + if rev == -1: + return '\t(working copy)' + return '\t(revision %d)' % rev + + +def filterdiff(diff, oldrev, newrev): + diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n' + r'+++ \1\t(working copy)', + diff) + oldrev = formatrev(oldrev) + newrev = formatrev(newrev) + diff = a_re.sub(r'--- \1'+ oldrev, diff) + diff = b_re.sub(r'+++ \1' + newrev, 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 parentrev(ui, repo, meta, hashes): + """Find the svn parent revision of the repo's dirstate. + """ + workingctx = repo.parents()[0] + outrev = outgoing_revisions(repo, hashes, workingctx.node()) + if outrev: + workingctx = repo[outrev[-1]].parents()[0] + return workingctx + + +def islocalrepo(url): + if not url.startswith('file:///'): + return False + if '#' in url.split('/')[-1]: # strip off #anchor + url = url[:url.rfind('#')] + path = url[len('file://'):] + path = urllib.url2pathname(path).replace(os.sep, '/') + while '/' in path: + if reduce(lambda x,y: x and y, + map(lambda p: os.path.exists(os.path.join(path, p)), + ('hooks', 'format', 'db', ))): + return True + path = path.rsplit('/', 1)[0] + return False + + def getuserpass(opts): # DO NOT default the user to hg's getuser(). If you provide # *any* default username to Subversion, it won't use any remembered
--- a/hgsubversion/utility_commands.py +++ b/hgsubversion/utility_commands.py @@ -4,7 +4,6 @@ from mercurial import util as hgutil import svnmeta import svnwrap -import cmdutil import util def genignore(ui, repo, hg_repo_path, force=False, **opts): @@ -20,7 +19,7 @@ def genignore(ui, repo, hg_repo_path, fo svn = svnwrap.SubversionRepo(url, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid) hashes = meta.revmap.hashes() - parent = cmdutil.parentrev(ui, repo, meta, hashes) + parent = util.parentrev(ui, repo, meta, hashes) r, br = hashes[parent.node()] if br == None: branchpath = 'trunk' @@ -48,7 +47,7 @@ def info(ui, repo, hg_repo_path, **opts) svn = svnwrap.SubversionRepo(url, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid) hashes = meta.revmap.hashes() - parent = cmdutil.parentrev(ui, repo, meta, hashes) + parent = util.parentrev(ui, repo, meta, hashes) pn = parent.node() if pn not in hashes: ui.status('Not a child of an svn revision.\n')
--- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -1,6 +1,6 @@ from hgext import rebase as hgrebase -from mercurial import cmdutil as hgcmdutil +from mercurial import cmdutil from mercurial import patch from mercurial import hg from mercurial import util as hgutil @@ -10,7 +10,6 @@ from mercurial import i18n from svn import core from svn import delta -import cmdutil import svnmeta import replay import pushmod @@ -37,10 +36,10 @@ def parents(orig, ui, repo, *args, **opt return orig(ui, repo, *args, **opts) meta = svnmeta.SVNMeta(repo) hashes = meta.revmap.hashes() - ha = cmdutil.parentrev(ui, repo, meta, hashes) + ha = util.parentrev(ui, repo, meta, hashes) if ha.node() == node.nullid: raise hgutil.Abort('No parent svn revision!') - displayer = hgcmdutil.show_changeset(ui, repo, opts, buffered=False) + displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) displayer.show(ha) return 0 @@ -95,7 +94,7 @@ def diff(orig, ui, repo, *args, **opts): if o_r: parent = repo[o_r[-1]].parents()[0] opts['rev'] = ['%s:.' % node.hex(parent.node()), ] - node1, node2 = hgcmdutil.revpair(repo, opts['rev']) + node1, node2 = cmdutil.revpair(repo, opts['rev']) baserev, _junk = hashes.get(node1, (-1, 'junk')) newrev, _junk = hashes.get(node2, (-1, 'junk')) it = patch.diff(repo, node1, node2, @@ -107,7 +106,7 @@ def diff(orig, ui, repo, *args, **opts): 'unified': True, 'text': False, })) - ui.write(cmdutil.filterdiff(''.join(it), baserev, newrev)) + ui.write(util.filterdiff(''.join(it), baserev, newrev)) def push(repo, dest, force, revs): """push revisions starting at a specified head back to Subversion. @@ -374,7 +373,7 @@ def clone(orig, ui, source, dest=None, * ui.setconfig(section, name, str(opts.pop(opt))) # this must be kept in sync with mercurial/commands.py - srcrepo, dstrepo = hg.clone(hgcmdutil.remoteui(ui, opts), source, dest, + srcrepo, dstrepo = hg.clone(cmdutil.remoteui(ui, opts), source, dest, pull=opts.get('pull'), stream=opts.get('uncompressed'), rev=opts.get('rev'),