comparison utility_commands.py @ 254:9ba31af57e4b

Move utility_commands.find_wc_parent_rev() to cmdutil.parentrev().
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 10 Apr 2009 17:29:45 +0200
parents c3d5c4ae9c7c
children 7932d098cb5f
comparison
equal deleted inserted replaced
253:c3d5c4ae9c7c 254:9ba31af57e4b
1 import os 1 import os
2 2
3 import mercurial 3 import mercurial
4 from mercurial import cmdutil 4 from mercurial import cmdutil as hgcmdutil
5 from mercurial import node 5 from mercurial import node
6 from mercurial import util as hgutil 6 from mercurial import util as hgutil
7 from hgext import rebase as hgrebase 7 from hgext import rebase as hgrebase
8 8
9 import svnwrap 9 import svnwrap
10 import cmdutil
10 import util 11 import util
11 import hg_delta_editor 12 import hg_delta_editor
12 13
13 def url(ui, repo, hg_repo_path, **opts): 14 def url(ui, repo, hg_repo_path, **opts):
14 """show the location (URL) of the Subversion repository 15 """show the location (URL) of the Subversion repository
15 """ 16 """
16 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 17 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
17 ui_=ui) 18 ui_=ui)
18 ui.status(hge.url, '\n') 19 ui.status(hge.url, '\n')
19
20
21 def find_wc_parent_rev(ui, repo, hge, svn_commit_hashes):
22 """Find the svn parent revision of the repo's dirstate.
23 """
24 workingctx = repo.parents()[0]
25 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingctx.node())
26 if o_r:
27 workingctx = repo[o_r[-1]].parents()[0]
28 return workingctx
29 20
30 21
31 def genignore(ui, repo, hg_repo_path, force=False, **opts): 22 def genignore(ui, repo, hg_repo_path, force=False, **opts):
32 """generate .hgignore from svn:ignore properties. 23 """generate .hgignore from svn:ignore properties.
33 """ 24 """
38 ignorefile.write('.hgignore\nsyntax:glob\n') 29 ignorefile.write('.hgignore\nsyntax:glob\n')
39 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 30 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
40 ui_=ui) 31 ui_=ui)
41 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 32 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
42 hge.revmap.iterkeys())) 33 hge.revmap.iterkeys()))
43 parent = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes) 34 parent = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes)
44 r, br = svn_commit_hashes[parent.node()] 35 r, br = svn_commit_hashes[parent.node()]
45 if br == None: 36 if br == None:
46 branchpath = 'trunk' 37 branchpath = 'trunk'
47 else: 38 else:
48 branchpath = 'branches/%s' % br 39 branchpath = 'branches/%s' % br
69 """ 60 """
70 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 61 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
71 ui_=ui) 62 ui_=ui)
72 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 63 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
73 hge.revmap.iterkeys())) 64 hge.revmap.iterkeys()))
74 parent = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes) 65 parent = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes)
75 pn = parent.node() 66 pn = parent.node()
76 if pn not in svn_commit_hashes: 67 if pn not in svn_commit_hashes:
77 ui.status('Not a child of an svn revision.\n') 68 ui.status('Not a child of an svn revision.\n')
78 return 0 69 return 0
79 r, br = svn_commit_hashes[pn] 70 r, br = svn_commit_hashes[pn]
116 """ 107 """
117 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 108 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
118 ui_=ui) 109 ui_=ui)
119 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 110 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
120 hge.revmap.iterkeys())) 111 hge.revmap.iterkeys()))
121 ha = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes) 112 ha = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes)
122 if ha.node() != node.nullid: 113 if ha.node() != node.nullid:
123 r, br = svn_commit_hashes[ha.node()] 114 r, br = svn_commit_hashes[ha.node()]
124 ui.status('Working copy parent revision is %s: r%s on %s\n' % 115 ui.status('Working copy parent revision is %s: r%s on %s\n' %
125 (ha, r, br or 'trunk')) 116 (ha, r, br or 'trunk'))
126 else: 117 else:
185 hge.revmap.iterkeys())) 176 hge.revmap.iterkeys()))
186 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, repo.parents()[0].node()) 177 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, repo.parents()[0].node())
187 if not (o_r and len(o_r)): 178 if not (o_r and len(o_r)):
188 ui.status('No outgoing changes found.\n') 179 ui.status('No outgoing changes found.\n')
189 return 0 180 return 0
190 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) 181 displayer = hgcmdutil.show_changeset(ui, repo, opts, buffered=False)
191 for node in reversed(o_r): 182 for node in reversed(o_r):
192 displayer.show(repo[node]) 183 displayer.show(repo[node])
193 184
194 185
195 def listauthors(ui, args, authors=None, **opts): 186 def listauthors(ui, args, authors=None, **opts):