annotate svncommand.py @ 243:2027f851d60c

Small cleanups: remove unneeded imports, useless superclass.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Apr 2009 17:54:30 +0200
parents 06130689a2c8
children 28d0ee605308
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.
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 240
diff changeset
11 from svncommands import pull
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
100
91ce18fa0375 Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents: 94
diff changeset
13 from diff_cmd import diff_command
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
14 from rebuildmeta import rebuildmeta
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 # shut up, pyflakes, we must import those
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
16 __x = [print_wc_url, pull, diff_command, rebuildmeta]
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 def svncmd(ui, repo, subcommand, *args, **opts):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 if subcommand not in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 candidates = []
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 for c in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 if c.startswith(subcommand):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 candidates.append(c)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 if len(candidates) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 subcommand = candidates[0]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 path = os.path.dirname(repo.path)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 **opts)
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
36 except TypeError:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
37 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
38 if len(tb) == 1:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
39 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
40 else:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
41 raise
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 except KeyError, e:
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
43 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
44 if len(tb) == 1:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
45 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
46 else:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
47 raise
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
49
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 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
51 """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
52 """
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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 ' '.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
65 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
66 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
67 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
68 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
69 ui.status(doc.strip(), '\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 return
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
71 ui.status(generate_help())
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
72 help_command = register_subcommand('help')(help_command)
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
73
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 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
75 """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
76 """
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 assert len(args) == 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 rev = int(args[0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 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
80 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
81 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
82 if k[0] == rev:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 answers.append((v, k[1]))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 if len(answers) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 if clean:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 return hg.clean(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 return hg.update(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 elif len(answers) == 0:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 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
90 return 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 else:
35
ef5d7a7aabb0 I meant ambiguous.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
92 ui.status('Ambiguous revision!\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 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
94 answers]+['']))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 return 1
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
96 update = register_subcommand('up')(update)