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