annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
1 import os
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
2
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
3 import mercurial
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 from mercurial import cmdutil
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 from mercurial import node
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
6 from mercurial import util as hgutil
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
7 from hgext import rebase as hgrebase
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
9 import svnwrap
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 import util
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11 import hg_delta_editor
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
13 def url(ui, repo, hg_repo_path, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
14 """show the location (URL) of the Subversion repository
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 101
diff changeset
15 """
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 ui_=ui)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 ui.status(hge.url, '\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
21 def find_wc_parent_rev(ui, repo, hge, svn_commit_hashes):
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
22 """Find the svn parent revision of the repo's dirstate.
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
23 """
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
24 workingctx = repo.parents()[0]
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
25 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingctx.node())
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
26 if o_r:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
27 workingctx = repo[o_r[-1]].parents()[0]
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
28 return workingctx
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
29
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
30
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
31 def genignore(ui, repo, hg_repo_path, force=False, **opts):
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
32 """generate .hgignore from svn:ignore properties.
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
33 """
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
34 ignpath = os.path.join(hg_repo_path, '.hgignore')
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
35 if not force and os.path.exists(ignpath):
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
36 raise hgutil.Abort('not overwriting existing .hgignore, try --force?')
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
37 ignorefile = open(ignpath, 'w')
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
38 ignorefile.write('.hgignore\nsyntax:glob\n')
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
39 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
40 ui_=ui)
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
41 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
42 hge.revmap.iterkeys()))
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
43 parent = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes)
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
44 r, br = svn_commit_hashes[parent.node()]
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
45 if br == None:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
46 branchpath = 'trunk'
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
47 else:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
48 branchpath = 'branches/%s' % br
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
49 url = hge.url
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
50 if url[-1] == '/':
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
51 url = url[:-1]
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
52 user = opts.get('username', hgutil.getuser())
234
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 230
diff changeset
53 passwd = opts.get('passwd', '')
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 230
diff changeset
54 svn = svnwrap.SubversionRepo(url, user, passwd)
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
55 dirs = [''] + [d[0] for d in svn.list_files(branchpath, r) if d[1] == 'd']
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
56 for dir in dirs:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
57 props = svn.list_props('%s/%s/' % (branchpath,dir), r)
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
58 if 'svn:ignore' in props:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
59 lines = props['svn:ignore'].strip().split('\n')
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
60 for prop in lines:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
61 if dir:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
62 ignorefile.write('%s/%s\n' % (dir, prop))
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
63 else:
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
64 ignorefile.write('%s\n' % prop)
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
65
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
66
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
67 def info(ui, repo, hg_repo_path, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
68 """show Subversion details similar to `svn info'
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 101
diff changeset
69 """
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
70 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
71 ui_=ui)
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
72 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
73 hge.revmap.iterkeys()))
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
74 parent = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes)
219
794f473b9b49 info: stop failing if the rev is not a child of an svn rev.
Augie Fackler <durin42@gmail.com>
parents: 212
diff changeset
75 pn = parent.node()
794f473b9b49 info: stop failing if the rev is not a child of an svn rev.
Augie Fackler <durin42@gmail.com>
parents: 212
diff changeset
76 if pn not in svn_commit_hashes:
794f473b9b49 info: stop failing if the rev is not a child of an svn rev.
Augie Fackler <durin42@gmail.com>
parents: 212
diff changeset
77 ui.status('Not a child of an svn revision.\n')
794f473b9b49 info: stop failing if the rev is not a child of an svn rev.
Augie Fackler <durin42@gmail.com>
parents: 212
diff changeset
78 return 0
794f473b9b49 info: stop failing if the rev is not a child of an svn rev.
Augie Fackler <durin42@gmail.com>
parents: 212
diff changeset
79 r, br = svn_commit_hashes[pn]
212
a421aca2b0f5 info: produce canonical URLs more of the time.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
80 subdir = parent.extra()['convert_revision'][40:].split('@')[0]
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
81 if br == None:
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
82 branchpath = '/trunk'
212
a421aca2b0f5 info: produce canonical URLs more of the time.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
83 elif br.startswith('../'):
a421aca2b0f5 info: produce canonical URLs more of the time.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
84 branchpath = '/%s' % br[3:]
a421aca2b0f5 info: produce canonical URLs more of the time.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
85 subdir = subdir.replace('branches/../', '')
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
86 else:
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
87 branchpath = '/branches/%s' % br
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
88 url = hge.url
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
89 if url[-1] == '/':
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
90 url = url[:-1]
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
91 url = '%s%s' % (url, branchpath)
226
bb2b78f9f4ce Use a reverse lookup in authormap to determine the author for 'hg svn info'.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 212
diff changeset
92 author = hge.svnauthorforauthor(parent.user())
160
7a5a0b5c8e34 info: Actually determine and show the repo root.
Augie Fackler <durin42@gmail.com>
parents: 157
diff changeset
93 # cleverly figure out repo root w/o actually contacting the server
7a5a0b5c8e34 info: Actually determine and show the repo root.
Augie Fackler <durin42@gmail.com>
parents: 157
diff changeset
94 reporoot = url[:len(url)-len(subdir)]
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
95 ui.status('''URL: %(url)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
96 Repository Root: %(reporoot)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
97 Repository UUID: %(uuid)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
98 Revision: %(revision)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
99 Node Kind: directory
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
100 Last Changed Author: %(author)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
101 Last Changed Rev: %(revision)s
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
102 Last Changed Date: %(date)s\n''' %
160
7a5a0b5c8e34 info: Actually determine and show the repo root.
Augie Fackler <durin42@gmail.com>
parents: 157
diff changeset
103 {'reporoot': reporoot,
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
104 'uuid': open(hge.uuid_file).read(),
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
105 'url': url,
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
106 'author': author,
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
107 'revision': r,
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
108 # TODO I'd like to format this to the user's local TZ if possible
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
109 'date': hgutil.datestr(parent.date(),
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
110 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
111 })
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
112
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
113
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
114 def parent(ui, repo, hg_repo_path, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
115 """show Mercurial & Subversion parents of the working dir or revision
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 101
diff changeset
116 """
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 ui_=ui)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120 hge.revmap.iterkeys()))
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 196
diff changeset
121 ha = find_wc_parent_rev(ui, repo, hge, svn_commit_hashes)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 if ha.node() != node.nullid:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 r, br = svn_commit_hashes[ha.node()]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 ui.status('Working copy parent revision is %s: r%s on %s\n' %
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 (ha, r, br or 'trunk'))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 else:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 ui.status('Working copy seems to have no parent svn revision.\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 return 0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
131 def rebase(ui, repo, extrafn=None, sourcerev=None, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
132 """rebase current unpushed revisions onto the Subversion head
64
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
133
08be8ee73551 Add an hg svn info subsubcommand that prints out what you would expect from svn info.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
134 This moves a line of development from making its own head to the top of
31
05800c403321 Fix up the rebase docstring to be less vague.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
135 Subversion development, linearizing the changes. In order to make sure you
05800c403321 Fix up the rebase docstring to be less vague.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
136 rebase on top of the current top of Subversion work, you should probably run
05800c403321 Fix up the rebase docstring to be less vague.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
137 'hg svn pull' before running this.
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 """
150
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
139 if extrafn is None:
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
140 def extrafn2(ctx, extra):
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
141 """defined here so we can add things easily.
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
142 """
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
143 extra['branch'] = ctx.branch()
58ae90a65f41 push: Improved the rebasing logic for push so that it doesn't break with
Augie Fackler <durin42@gmail.com>
parents: 149
diff changeset
144 extrafn = extrafn2
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 150
diff changeset
145 if sourcerev is None:
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 150
diff changeset
146 sourcerev = repo.parents()[0].node()
230
4c3bad24f950 rebase: cleanup slightly.
Augie Fackler <durin42@gmail.com>
parents: 228
diff changeset
147 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 hge.revmap.iterkeys()))
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 150
diff changeset
150 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 if not o_r:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152 ui.status('Nothing to rebase!\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 return 0
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 150
diff changeset
154 if len(repo[sourcerev].children()):
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 ui.status('Refusing to rebase non-head commit like a coward\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 return 0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 parent_rev = repo[o_r[-1]].parents()[0]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 target_rev = parent_rev
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159 p_n = parent_rev.node()
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 exhausted_choices = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 while target_rev.children() and not exhausted_choices:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 for c in target_rev.children():
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 exhausted_choices = True
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 n = c.node()
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165 if (n in svn_commit_hashes and
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 svn_commit_hashes[n][1] == svn_commit_hashes[p_n][1]):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167 target_rev = c
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 exhausted_choices = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 break
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 if parent_rev == target_rev:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171 ui.status('Already up to date!\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 return 0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 # TODO this is really hacky, there must be a more direct way
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
174 return hgrebase.rebase(ui, repo, dest=node.hex(target_rev.node()),
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 150
diff changeset
175 base=node.hex(sourcerev),
149
04800fda7af5 rebase: preserve local branch names.
Augie Fackler <durin42@gmail.com>
parents: 115
diff changeset
176 extrafn=extrafn)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
179 def outgoing(ui, repo, hg_repo_path, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
180 """show changesets not found in the Subversion repository
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 """
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 ui_=ui)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185 hge.revmap.iterkeys()))
157
91541523ea5c utility_commands: Test outgoing and fix it to work again.
Augie Fackler <durin42@gmail.com>
parents: 152
diff changeset
186 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, repo.parents()[0].node())
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 if not (o_r and len(o_r)):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
188 ui.status('No outgoing changes found.\n')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 return 0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False)
95
10dd34deac3b utility_commands: fix outgoing against crew (required because of crew cset 87158be081b8)
Augie Fackler <durin42@gmail.com>
parents: 64
diff changeset
191 for node in reversed(o_r):
10dd34deac3b utility_commands: fix outgoing against crew (required because of crew cset 87158be081b8)
Augie Fackler <durin42@gmail.com>
parents: 64
diff changeset
192 displayer.show(repo[node])
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
193
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
194
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
195 def listauthors(ui, args, authors=None, **opts):
236
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
196 """list all authors in a Subversion repository
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
197 """
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
198 if not len(args):
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
199 ui.status('No repository specified.\n')
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
200 return
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
201 svn = svnwrap.SubversionRepo(util.normalize_url(args[0]))
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
202 author_set = set()
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
203 for rev in svn.revisions():
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
204 author_set.add(str(rev.author)) # So None becomes 'None'
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
205 if authors:
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
206 authorfile = open(authors, 'w')
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
207 authorfile.write('%s=\n' % '=\n'.join(sorted(author_set)))
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
208 authorfile.close()
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
209 else:
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
210 ui.status('%s\n' % '\n'.join(sorted(author_set)))
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
211
c34abd2448b7 Issue #60: Add a svn sub-command to list all authors in a Subversion repository
Daniel Tang <dytang@cs.purdue.edu>
parents: 234
diff changeset
212
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
213 def version(ui, **opts):
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
214 """Show current version of hg and hgsubversion.
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
215 """
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 236
diff changeset
216 ui.status('hg: %s\n' % hgutil.version())
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
217 ui.status('svn bindings: %s\n' % svnwrap.version())
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
218 ui.status('hgsubversion: %s\n' % util.version(ui))
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
219
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
220
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
221 nourl = ['version', 'listauthors']
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
222 table = {
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
223 'url': url,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
224 'genignore': genignore,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
225 'info': info,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
226 'parent': parent,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
227 'outgoing': outgoing,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
228 'listauthors': listauthors,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
229 'version': version,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
230 'rebase': rebase,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 250
diff changeset
231 }