annotate svncommand.py @ 246:074f27c68818

Move rebuildmeta into svncommands.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Apr 2009 18:49:44 +0200
parents 28d0ee605308
children 1272e87546ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 import os
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
2 import sys
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
3 import traceback
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 from mercurial import hg
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 from mercurial import node
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 import util
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 from util import register_subcommand, svn_subcommands, generate_help, svn_commands_nourl
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 # dirty trick to force demandimport to run my decorator anyway.
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
11 from svncommands import pull, diff, rebuildmeta
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 from utility_commands import print_wc_url
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 # shut up, pyflakes, we must import those
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 243
diff changeset
14 __x = [print_wc_url, pull, diff, rebuildmeta]
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 def svncmd(ui, repo, subcommand, *args, **opts):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 if subcommand not in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 candidates = []
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 for c in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 if c.startswith(subcommand):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 candidates.append(c)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 if len(candidates) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 subcommand = candidates[0]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 path = os.path.dirname(repo.path)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 try:
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
27 commandfunc = svn_subcommands[subcommand]
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
28 if commandfunc not in svn_commands_nourl:
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
29 opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read()
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
30 return commandfunc(ui, args=args,
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
31 hg_repo_path=path,
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
32 repo=repo,
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
33 **opts)
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
34 except TypeError:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
35 tb = traceback.extract_tb(sys.exc_info()[2])
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
36 if len(tb) == 1:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
37 ui.status('Bad arguments for subcommand %s\n' % subcommand)
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
38 else:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
39 raise
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 except KeyError, e:
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
41 tb = traceback.extract_tb(sys.exc_info()[2])
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
42 if len(tb) == 1:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
43 ui.status('Unknown subcommand %s\n' % subcommand)
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
44 else:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
45 raise
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
47
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 def help_command(ui, args=None, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
49 """show help for a given subcommands or a help overview
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 """
94
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
51 if args:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
52 subcommand = args[0]
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
53 if subcommand not in svn_subcommands:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
54 candidates = []
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
55 for c in svn_subcommands:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
56 if c.startswith(subcommand):
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
57 candidates.append(c)
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
58 if len(candidates) == 1:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
59 subcommand = candidates[0]
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
60 elif len(candidates) > 1:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
61 ui.status('Ambiguous command. Could have been:\n%s\n' %
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
62 ' '.join(candidates))
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
63 return
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
64 doc = svn_subcommands[subcommand].__doc__
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
65 if doc is None:
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
66 doc = "No documentation available for %s." % subcommand
b5651f53e7ae svncommand: Fix help to use ui.status() and be a bit smarter about displaying
Augie Fackler <durin42@gmail.com>
parents: 93
diff changeset
67 ui.status(doc.strip(), '\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 return
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
69 ui.status(generate_help())
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
70 help_command = register_subcommand('help')(help_command)
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
71
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 def update(ui, args, repo, clean=False, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 181
diff changeset
73 """update to a specified Subversion revision number
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 """
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 assert len(args) == 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 rev = int(args[0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 path = os.path.join(repo.path, 'svn', 'rev_map')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 answers = []
34
50d55c3e0d85 Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
79 for k,v in util.parse_revmap(path).iteritems():
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 if k[0] == rev:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 answers.append((v, k[1]))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 if len(answers) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 if clean:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 return hg.clean(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 return hg.update(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 elif len(answers) == 0:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 ui.status('Revision %s did not produce an hg revision.\n' % rev)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 return 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 else:
35
ef5d7a7aabb0 I meant ambiguous.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
90 ui.status('Ambiguous revision!\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 answers]+['']))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 return 1
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
94 update = register_subcommand('up')(update)