comparison util.py @ 304:ce676eff002b

First merge, totally untested.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 01 May 2009 10:28:59 +0200
parents f8f9a2993705
children 33736e2e25f0
comparison
equal deleted inserted replaced
303:f423a8780832 304:ce676eff002b
1 import os 1 import os
2 import shutil 2 import shutil
3 3
4 from mercurial import hg 4 from mercurial import hg
5 from mercurial import node 5 from mercurial import node
6 from mercurial import util as hgutil
6 7
7 svn_subcommands = { }
8 def register_subcommand(name):
9 def inner(fn):
10 svn_subcommands[name] = fn
11 return fn
12 return inner
13 8
14 svn_commands_nourl = set() 9 def getuserpass(opts):
15 def command_needs_no_url(fn): 10 # DO NOT default the user to hg's getuser(). If you provide
16 svn_commands_nourl.add(fn) 11 # *any* default username to Subversion, it won't use any remembered
17 return fn 12 # username for the desired realm, breaking OS X Keychain support,
13 # GNOME keyring support, and all similar tools.
14 return opts.get('username', None), opts.get('password', '')
18 15
19 16
20 def version(ui): 17 def version(ui):
21 """Guess the version of hgsubversion. 18 """Guess the version of hgsubversion.
22 """ 19 """
24 repo = hg.repository(ui, os.path.dirname(__file__)) 21 repo = hg.repository(ui, os.path.dirname(__file__))
25 ver = repo.dirstate.parents()[0] 22 ver = repo.dirstate.parents()[0]
26 return node.hex(ver)[:12] 23 return node.hex(ver)[:12]
27 24
28 25
29 def generate_help(): 26 def normalize_url(svnurl):
30 ret = ['hg svn ...', '', 27 if svnurl.startswith('svn+http'):
31 'subcommands for Subversion integration', '', 28 svnurl = svnurl[4:]
32 'list of subcommands:', ''] 29 url, revs, checkout = hg.parseurl(svnurl)
30 url = url.rstrip('/')
31 if checkout:
32 url = '%s#%s' % (url, checkout)
33 return url
33 34
34 for name, func in sorted(svn_subcommands.items()):
35 short_description = (func.__doc__ or '').splitlines()[0]
36 ret.append(" %-10s %s" % (name, short_description))
37
38 return "\n".join(ret) + '\n'
39
40
41 def normalize_url(svn_url):
42 return svn_url.rstrip('/')
43
44
45 def wipe_all_files(hg_wc_path):
46 files = [f for f in os.listdir(hg_wc_path) if f != '.hg']
47 for f in files:
48 f = os.path.join(hg_wc_path, f)
49 if os.path.isdir(f):
50 shutil.rmtree(f)
51 else:
52 os.remove(f)
53 35
54 REVMAP_FILE_VERSION = 1 36 REVMAP_FILE_VERSION = 1
55 def parse_revmap(revmap_filename): 37 def parse_revmap(revmap_filename):
56 revmap = {} 38 revmap = {}
57 f = open(revmap_filename) 39 f = open(revmap_filename)
92 sourcerev = repo[sourcerev] 74 sourcerev = repo[sourcerev]
93 while (not sourcerev.node() in reverse_map 75 while (not sourcerev.node() in reverse_map
94 and sourcerev.node() != node.nullid): 76 and sourcerev.node() != node.nullid):
95 outgoing_rev_hashes.append(sourcerev.node()) 77 outgoing_rev_hashes.append(sourcerev.node())
96 sourcerev = sourcerev.parents() 78 sourcerev = sourcerev.parents()
97 assert len(sourcerev) == 1 79 if len(sourcerev) != 1:
80 raise hgutil.Abort("Sorry, can't find svn parent of a merge revision.")
98 sourcerev = sourcerev[0] 81 sourcerev = sourcerev[0]
99 if sourcerev.node() != node.nullid: 82 if sourcerev.node() != node.nullid:
100 return outgoing_rev_hashes 83 return outgoing_rev_hashes
101 84
102 def build_extra(revnum, branch, uuid, subdir): 85 def build_extra(revnum, branch, uuid, subdir):
103 # TODO this needs to be fixed with the new revmap
104 extra = {} 86 extra = {}
105 branchpath = 'trunk' 87 branchpath = 'trunk'
106 if branch: 88 if branch:
107 extra['branch'] = branch 89 extra['branch'] = branch
108 branchpath = 'branches/%s' % branch 90 branchpath = 'branches/%s' % branch
131 113
132 ui.status(('[r%d] %s: %s' % (r.revnum, r.author, msg))[:80] + '\n') 114 ui.status(('[r%d] %s: %s' % (r.revnum, r.author, msg))[:80] + '\n')
133 115
134 def describe_commit(ui, h, b): 116 def describe_commit(ui, h, b):
135 ui.note(' committed to "%s" as %s\n' % ((b or 'default'), node.short(h))) 117 ui.note(' committed to "%s" as %s\n' % ((b or 'default'), node.short(h)))
118
119
120 def swap_out_encoding(new_encoding="UTF-8"):
121 """ Utility for mercurial incompatibility changes, can be removed after 1.3
122 """
123 from mercurial import encoding
124 old = encoding.encoding
125 encoding.encoding = new_encoding
126 return old