annotate svncommand.py @ 303:f423a8780832

Minor tweaks to how the tests are run.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 27 Mar 2009 03:42:52 +0100
parents 1611834e39ee
children
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
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
6
1a5bb173170b Fixes for win32 compatibility. Changes suggested by Shun-ichi GOTO, with some alterations by me.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
8 from mercurial import util as merc_util
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 import svnwrap
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11 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
12 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
13 # dirty trick to force demandimport to run my decorator anyway.
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
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 from fetch_command import fetch_revisions
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 from push_cmd import commit_from_rev
100
91ce18fa0375 Add a diff command that behaves kind of like svn diff.
Augie Fackler <durin42@gmail.com>
parents: 94
diff changeset
17 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
18 from rebuildmeta import rebuildmeta
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 # shut up, pyflakes, we must import those
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
20 __x = [print_wc_url, fetch_revisions, commit_from_rev, diff_command, rebuildmeta]
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 mode755 = (stat.S_IXUSR | stat.S_IXGRP| stat.S_IXOTH | stat.S_IRUSR |
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 stat.S_IRGRP| stat.S_IROTH | stat.S_IWUSR)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 mode644 = (stat.S_IRUSR | stat.S_IRGRP| stat.S_IROTH | stat.S_IWUSR)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 def svncmd(ui, repo, subcommand, *args, **opts):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 if subcommand not in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 candidates = []
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 for c in svn_subcommands:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 if c.startswith(subcommand):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 candidates.append(c)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 if len(candidates) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 subcommand = candidates[0]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 path = os.path.dirname(repo.path)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 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
37 commandfunc = svn_subcommands[subcommand]
297
1611834e39ee Prevent '.hg/svn/url' from overriding a URL specified on the command line.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 208
diff changeset
38 if commandfunc not in svn_commands_nourl and not opts['svn_url']:
155
ba801f44d240 utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
39 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
40 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
41 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
42 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
43 **opts)
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
44 except TypeError:
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('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
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 except KeyError, e:
93
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
51 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
52 if len(tb) == 1:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
53 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
54 else:
f537eb456cf7 svncommand: Check traceback length to stop masking real exceptions.
Augie Fackler <durin42@gmail.com>
parents: 35
diff changeset
55 raise
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
57
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 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
59 """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
60 """
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
61 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
62 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
63 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
64 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 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
66 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
67 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
68 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
69 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
70 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
71 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
72 ' '.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
73 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
74 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
75 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
76 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
77 ui.status(doc.strip(), '\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 return
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
79 ui.status(generate_help())
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
80 help_command = register_subcommand('help')(help_command)
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 100
diff changeset
81
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 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
83 """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
84 """
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 assert len(args) == 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 rev = int(args[0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 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
88 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
89 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
90 if k[0] == rev:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 answers.append((v, k[1]))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 if len(answers) == 1:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 if clean:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 return hg.clean(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 return hg.update(repo, answers[0][0])
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96 elif len(answers) == 0:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
97 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
98 return 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99 else:
35
ef5d7a7aabb0 I meant ambiguous.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
100 ui.status('Ambiguous revision!\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 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
102 answers]+['']))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 return 1
181
e37f9d3fd5e7 remove decorators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 155
diff changeset
104 update = register_subcommand('up')(update)