comparison utility_commands.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 58ae90a65f41
children 91541523ea5c
comparison
equal deleted inserted replaced
151:2decec74ad0c 152:1fde85a10f9e
21 """ 21 """
22 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 22 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
23 ui_=ui) 23 ui_=ui)
24 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 24 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
25 hge.revmap.iterkeys())) 25 hge.revmap.iterkeys()))
26 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) 26 workingctx = repo.parents()[0]
27 ha = repo.parents()[0] 27 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingctx.node())
28 if o_r: 28 if o_r:
29 ha = repo[o_r[-1]].parents()[0] 29 workingctx = repo[o_r[-1]].parents()[0]
30 r, br = svn_commit_hashes[ha.node()] 30 r, br = svn_commit_hashes[workingctx.node()]
31 if br == None: 31 if br == None:
32 branchpath = '/trunk' 32 branchpath = '/trunk'
33 else: 33 else:
34 branchpath = '/branches/%s' % br 34 branchpath = '/branches/%s' % br
35 url = hge.url 35 url = hge.url
36 if url[-1] == '/': 36 if url[-1] == '/':
37 url = url[:-1] 37 url = url[:-1]
38 url = '%s%s' % (url, branchpath) 38 url = '%s%s' % (url, branchpath)
39 author = '@'.join(ha.user().split('@')[:-1]) 39 author = '@'.join(workingctx.user().split('@')[:-1])
40 ui.status('''URL: %(url)s 40 ui.status('''URL: %(url)s
41 Repository Root: %(reporoot)s 41 Repository Root: %(reporoot)s
42 Repository UUID: %(uuid)s 42 Repository UUID: %(uuid)s
43 Revision: %(revision)s 43 Revision: %(revision)s
44 Node Kind: directory 44 Node Kind: directory
49 'uuid': open(hge.uuid_file).read(), 49 'uuid': open(hge.uuid_file).read(),
50 'url': url, 50 'url': url,
51 'author': author, 51 'author': author,
52 'revision': r, 52 'revision': r,
53 # TODO I'd like to format this to the user's local TZ if possible 53 # TODO I'd like to format this to the user's local TZ if possible
54 'date': mutil.datestr(ha.date(), 54 'date': mutil.datestr(workingctx.date(),
55 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') 55 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
56 }) 56 })
57 57
58 58
59 @util.register_subcommand('parent') 59 @util.register_subcommand('parent')
63 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 63 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
64 ui_=ui) 64 ui_=ui)
65 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 65 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
66 hge.revmap.iterkeys())) 66 hge.revmap.iterkeys()))
67 ha = repo.parents()[0] 67 ha = repo.parents()[0]
68 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) 68 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, ha.node())
69 if o_r: 69 if o_r:
70 ha = repo[o_r[-1]].parents()[0] 70 ha = repo[o_r[-1]].parents()[0]
71 if ha.node() != node.nullid: 71 if ha.node() != node.nullid:
72 r, br = svn_commit_hashes[ha.node()] 72 r, br = svn_commit_hashes[ha.node()]
73 ui.status('Working copy parent revision is %s: r%s on %s\n' % 73 ui.status('Working copy parent revision is %s: r%s on %s\n' %
76 ui.status('Working copy seems to have no parent svn revision.\n') 76 ui.status('Working copy seems to have no parent svn revision.\n')
77 return 0 77 return 0
78 78
79 79
80 @util.register_subcommand('rebase') 80 @util.register_subcommand('rebase')
81 def rebase_commits(ui, repo, hg_repo_path, extrafn=None, **opts): 81 def rebase_commits(ui, repo, hg_repo_path, extrafn=None, sourcerev=None, **opts):
82 """Rebases current unpushed revisions onto Subversion head 82 """Rebases current unpushed revisions onto Subversion head
83 83
84 This moves a line of development from making its own head to the top of 84 This moves a line of development from making its own head to the top of
85 Subversion development, linearizing the changes. In order to make sure you 85 Subversion development, linearizing the changes. In order to make sure you
86 rebase on top of the current top of Subversion work, you should probably run 86 rebase on top of the current top of Subversion work, you should probably run
90 def extrafn2(ctx, extra): 90 def extrafn2(ctx, extra):
91 """defined here so we can add things easily. 91 """defined here so we can add things easily.
92 """ 92 """
93 extra['branch'] = ctx.branch() 93 extra['branch'] = ctx.branch()
94 extrafn = extrafn2 94 extrafn = extrafn2
95 if sourcerev is None:
96 sourcerev = repo.parents()[0].node()
95 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 97 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
96 ui_=ui) 98 ui_=ui)
97 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 99 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
98 hge.revmap.iterkeys())) 100 hge.revmap.iterkeys()))
99 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) 101 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev)
100 if not o_r: 102 if not o_r:
101 ui.status('Nothing to rebase!\n') 103 ui.status('Nothing to rebase!\n')
102 return 0 104 return 0
103 if len(repo.parents()[0].children()): 105 if len(repo[sourcerev].children()):
104 ui.status('Refusing to rebase non-head commit like a coward\n') 106 ui.status('Refusing to rebase non-head commit like a coward\n')
105 return 0 107 return 0
106 parent_rev = repo[o_r[-1]].parents()[0] 108 parent_rev = repo[o_r[-1]].parents()[0]
107 target_rev = parent_rev 109 target_rev = parent_rev
108 p_n = parent_rev.node() 110 p_n = parent_rev.node()
119 if parent_rev == target_rev: 121 if parent_rev == target_rev:
120 ui.status('Already up to date!\n') 122 ui.status('Already up to date!\n')
121 return 0 123 return 0
122 # TODO this is really hacky, there must be a more direct way 124 # TODO this is really hacky, there must be a more direct way
123 return rebase.rebase(ui, repo, dest=node.hex(target_rev.node()), 125 return rebase.rebase(ui, repo, dest=node.hex(target_rev.node()),
124 base=node.hex(repo.parents()[0].node()), 126 base=node.hex(sourcerev),
125 extrafn=extrafn) 127 extrafn=extrafn)
126 128
127 129
128 @util.register_subcommand('outgoing') 130 @util.register_subcommand('outgoing')
129 def show_outgoing_to_svn(ui, repo, hg_repo_path, **opts): 131 def show_outgoing_to_svn(ui, repo, hg_repo_path, **opts):
131 """ 133 """
132 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 134 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
133 ui_=ui) 135 ui_=ui)
134 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 136 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
135 hge.revmap.iterkeys())) 137 hge.revmap.iterkeys()))
136 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes) 138 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, repo.parents()[0])
137 if not (o_r and len(o_r)): 139 if not (o_r and len(o_r)):
138 ui.status('No outgoing changes found.\n') 140 ui.status('No outgoing changes found.\n')
139 return 0 141 return 0
140 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) 142 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False)
141 for node in reversed(o_r): 143 for node in reversed(o_r):