Mercurial > hgsubversion
comparison utility_commands.py @ 253:c3d5c4ae9c7c
Work with simple command table instead of decorators.
| author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
|---|---|
| date | Fri, 10 Apr 2009 23:09:59 +0200 |
| parents | 79349fd04836 |
| children | 9ba31af57e4b |
comparison
equal
deleted
inserted
replaced
| 252:4d3bcd2f26ed | 253:c3d5c4ae9c7c |
|---|---|
| 2 | 2 |
| 3 import mercurial | 3 import mercurial |
| 4 from mercurial import cmdutil | 4 from mercurial import cmdutil |
| 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 | 7 from hgext import rebase as hgrebase |
| 8 | 8 |
| 9 import svnwrap | 9 import svnwrap |
| 10 import util | 10 import util |
| 11 import hg_delta_editor | 11 import hg_delta_editor |
| 12 | 12 |
| 13 def print_wc_url(ui, repo, hg_repo_path, **opts): | 13 def url(ui, repo, hg_repo_path, **opts): |
| 14 """show the location (URL) of the Subversion repository | 14 """show the location (URL) of the Subversion repository |
| 15 """ | 15 """ |
| 16 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, | 16 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, |
| 17 ui_=ui) | 17 ui_=ui) |
| 18 ui.status(hge.url, '\n') | 18 ui.status(hge.url, '\n') |
| 19 print_wc_url = util.register_subcommand('url')(print_wc_url) | |
| 20 | 19 |
| 21 | 20 |
| 22 def find_wc_parent_rev(ui, repo, hge, svn_commit_hashes): | 21 def find_wc_parent_rev(ui, repo, hge, svn_commit_hashes): |
| 23 """Find the svn parent revision of the repo's dirstate. | 22 """Find the svn parent revision of the repo's dirstate. |
| 24 """ | 23 """ |
| 27 if o_r: | 26 if o_r: |
| 28 workingctx = repo[o_r[-1]].parents()[0] | 27 workingctx = repo[o_r[-1]].parents()[0] |
| 29 return workingctx | 28 return workingctx |
| 30 | 29 |
| 31 | 30 |
| 32 def generate_ignore(ui, repo, hg_repo_path, force=False, **opts): | 31 def genignore(ui, repo, hg_repo_path, force=False, **opts): |
| 33 """generate .hgignore from svn:ignore properties. | 32 """generate .hgignore from svn:ignore properties. |
| 34 """ | 33 """ |
| 35 ignpath = os.path.join(hg_repo_path, '.hgignore') | 34 ignpath = os.path.join(hg_repo_path, '.hgignore') |
| 36 if not force and os.path.exists(ignpath): | 35 if not force and os.path.exists(ignpath): |
| 37 raise hgutil.Abort('not overwriting existing .hgignore, try --force?') | 36 raise hgutil.Abort('not overwriting existing .hgignore, try --force?') |
| 61 for prop in lines: | 60 for prop in lines: |
| 62 if dir: | 61 if dir: |
| 63 ignorefile.write('%s/%s\n' % (dir, prop)) | 62 ignorefile.write('%s/%s\n' % (dir, prop)) |
| 64 else: | 63 else: |
| 65 ignorefile.write('%s\n' % prop) | 64 ignorefile.write('%s\n' % prop) |
| 66 generate_ignore = util.register_subcommand('genignore')(generate_ignore) | 65 |
| 67 | 66 |
| 68 | 67 def info(ui, repo, hg_repo_path, **opts): |
| 69 def run_svn_info(ui, repo, hg_repo_path, **opts): | |
| 70 """show Subversion details similar to `svn info' | 68 """show Subversion details similar to `svn info' |
| 71 """ | 69 """ |
| 72 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, | 70 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, |
| 73 ui_=ui) | 71 ui_=ui) |
| 74 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), | 72 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), |
| 109 'revision': r, | 107 'revision': r, |
| 110 # TODO I'd like to format this to the user's local TZ if possible | 108 # TODO I'd like to format this to the user's local TZ if possible |
| 111 'date': hgutil.datestr(parent.date(), | 109 'date': hgutil.datestr(parent.date(), |
| 112 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') | 110 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') |
| 113 }) | 111 }) |
| 114 run_svn_info = util.register_subcommand('info')(run_svn_info) | 112 |
| 115 | 113 |
| 116 | 114 def parent(ui, repo, hg_repo_path, **opts): |
| 117 def print_parent_revision(ui, repo, hg_repo_path, **opts): | |
| 118 """show Mercurial & Subversion parents of the working dir or revision | 115 """show Mercurial & Subversion parents of the working dir or revision |
| 119 """ | 116 """ |
| 120 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, | 117 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, |
| 121 ui_=ui) | 118 ui_=ui) |
| 122 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), | 119 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), |
| 127 ui.status('Working copy parent revision is %s: r%s on %s\n' % | 124 ui.status('Working copy parent revision is %s: r%s on %s\n' % |
| 128 (ha, r, br or 'trunk')) | 125 (ha, r, br or 'trunk')) |
| 129 else: | 126 else: |
| 130 ui.status('Working copy seems to have no parent svn revision.\n') | 127 ui.status('Working copy seems to have no parent svn revision.\n') |
| 131 return 0 | 128 return 0 |
| 132 print_parent_revision = util.register_subcommand('parent')(print_parent_revision) | 129 |
| 133 | 130 |
| 134 | 131 def rebase(ui, repo, extrafn=None, sourcerev=None, **opts): |
| 135 def rebase_commits(ui, repo, extrafn=None, sourcerev=None, **opts): | |
| 136 """rebase current unpushed revisions onto the Subversion head | 132 """rebase current unpushed revisions onto the Subversion head |
| 137 | 133 |
| 138 This moves a line of development from making its own head to the top of | 134 This moves a line of development from making its own head to the top of |
| 139 Subversion development, linearizing the changes. In order to make sure you | 135 Subversion development, linearizing the changes. In order to make sure you |
| 140 rebase on top of the current top of Subversion work, you should probably run | 136 rebase on top of the current top of Subversion work, you should probably run |
| 173 break | 169 break |
| 174 if parent_rev == target_rev: | 170 if parent_rev == target_rev: |
| 175 ui.status('Already up to date!\n') | 171 ui.status('Already up to date!\n') |
| 176 return 0 | 172 return 0 |
| 177 # TODO this is really hacky, there must be a more direct way | 173 # TODO this is really hacky, there must be a more direct way |
| 178 return rebase.rebase(ui, repo, dest=node.hex(target_rev.node()), | 174 return hgrebase.rebase(ui, repo, dest=node.hex(target_rev.node()), |
| 179 base=node.hex(sourcerev), | 175 base=node.hex(sourcerev), |
| 180 extrafn=extrafn) | 176 extrafn=extrafn) |
| 181 rebase_commits = util.register_subcommand('rebase')(rebase_commits) | 177 |
| 182 | 178 |
| 183 | 179 def outgoing(ui, repo, hg_repo_path, **opts): |
| 184 def show_outgoing_to_svn(ui, repo, hg_repo_path, **opts): | |
| 185 """show changesets not found in the Subversion repository | 180 """show changesets not found in the Subversion repository |
| 186 """ | 181 """ |
| 187 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, | 182 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, |
| 188 ui_=ui) | 183 ui_=ui) |
| 189 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), | 184 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), |
| 193 ui.status('No outgoing changes found.\n') | 188 ui.status('No outgoing changes found.\n') |
| 194 return 0 | 189 return 0 |
| 195 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) | 190 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) |
| 196 for node in reversed(o_r): | 191 for node in reversed(o_r): |
| 197 displayer.show(repo[node]) | 192 displayer.show(repo[node]) |
| 198 show_outgoing_to_svn = util.register_subcommand('outgoing')(show_outgoing_to_svn) | 193 |
| 199 | 194 |
| 200 | 195 def listauthors(ui, args, authors=None, **opts): |
| 201 def list_authors(ui, args, authors=None, **opts): | |
| 202 """list all authors in a Subversion repository | 196 """list all authors in a Subversion repository |
| 203 """ | 197 """ |
| 204 if not len(args): | 198 if not len(args): |
| 205 ui.status('No repository specified.\n') | 199 ui.status('No repository specified.\n') |
| 206 return | 200 return |
| 212 authorfile = open(authors, 'w') | 206 authorfile = open(authors, 'w') |
| 213 authorfile.write('%s=\n' % '=\n'.join(sorted(author_set))) | 207 authorfile.write('%s=\n' % '=\n'.join(sorted(author_set))) |
| 214 authorfile.close() | 208 authorfile.close() |
| 215 else: | 209 else: |
| 216 ui.status('%s\n' % '\n'.join(sorted(author_set))) | 210 ui.status('%s\n' % '\n'.join(sorted(author_set))) |
| 217 list_authors = util.register_subcommand('listauthors')(list_authors) | |
| 218 list_authors = util.command_needs_no_url(list_authors) | |
| 219 | 211 |
| 220 | 212 |
| 221 def version(ui, **opts): | 213 def version(ui, **opts): |
| 222 """Show current version of hg and hgsubversion. | 214 """Show current version of hg and hgsubversion. |
| 223 """ | 215 """ |
| 224 ui.status('hg: %s\n' % hgutil.version()) | 216 ui.status('hg: %s\n' % hgutil.version()) |
| 225 ui.status('svn bindings: %s\n' % svnwrap.version()) | 217 ui.status('svn bindings: %s\n' % svnwrap.version()) |
| 226 ui.status('hgsubversion: %s\n' % util.version(ui)) | 218 ui.status('hgsubversion: %s\n' % util.version(ui)) |
| 227 version = util.register_subcommand('version')(version) | 219 |
| 228 version = util.command_needs_no_url(version) | 220 |
| 221 nourl = ['version', 'listauthors'] | |
| 222 table = { | |
| 223 'url': url, | |
| 224 'genignore': genignore, | |
| 225 'info': info, | |
| 226 'parent': parent, | |
| 227 'outgoing': outgoing, | |
| 228 'listauthors': listauthors, | |
| 229 'version': version, | |
| 230 'rebase': rebase, | |
| 231 } |
