annotate svncommands.py @ 257:ffccf0080e54

Move wrappers for hg commands to their own module.
author Augie Fackler <durin42@gmail.com>
date Fri, 10 Apr 2009 22:38:29 -0500
parents 7932d098cb5f
children 9f0738587f94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
1 import os
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
2 import cPickle as pickle
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
3
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
4 from mercurial import hg
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
5 from mercurial import node
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
6 from mercurial import util as hgutil
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
7
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
8
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
9 import hg_delta_editor
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
10 import svnwrap
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
11 import util
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
12 import utility_commands
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
13
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
14
255
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
15 def incoming(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
16 tag_locations='tags', authors=None, filemap=None, **opts):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
17 """show incoming revisions from Subversion
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
18 """
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
19 svn_url = util.normalize_url(svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
20
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
21 initializing_repo = False
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
22 user = opts.get('username', hgutil.getuser())
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
23 passwd = opts.get('password', '')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
24 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
25 author_host = "@%s" % svn.uuid
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
26 tag_locations = tag_locations.split(',')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
27 hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
28 ui_=ui,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
29 subdir=svn.subdir,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
30 author_host=author_host,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
31 tag_locations=tag_locations,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
32 authors=authors,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
33 filemap=filemap)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
34 if os.path.exists(hg_editor.uuid_file):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
35 uuid = open(hg_editor.uuid_file).read()
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
36 assert uuid == svn.uuid
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
37 start = hg_editor.last_known_revision()
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
38 else:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
39 open(hg_editor.uuid_file, 'w').write(svn.uuid)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
40 open(hg_editor.svn_url_file, 'w').write(svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
41 initializing_repo = True
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
42 start = skipto_rev
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
43
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
44 if initializing_repo and start > 0:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
45 raise hgutil.Abort('Revision skipping at repository initialization '
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
46 'remains unimplemented.')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
47
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
48 rev_stuff = (('revision', 'revnum'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
49 ('user', 'author'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
50 ('date', 'date'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
51 ('message', 'message')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
52 )
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
53
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
54 ui.status('incoming changes from %s\n' % svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
55
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
56 for r in svn.revisions(start=start):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
57 ui.status('\n')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
58 for label, attr in rev_stuff:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
59 l1 = label+':'
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
60 ui.status('%s%s\n' % (l1.ljust(13),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
61 str(r.__getattribute__(attr)).strip(), ))
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
62
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
63
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
64 def rebuildmeta(ui, repo, hg_repo_path, args, **opts):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
65 """rebuild hgsubversion metadata using values stored in revisions
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
66 """
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
67 if len(args) != 1:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
68 raise hgutil.Abort('You must pass the svn URI used to create this repo.')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
69 uuid = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
70 url = args[0].rstrip('/')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
71 user = opts.get('username', hgutil.getuser())
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
72 passwd = opts.get('password', '')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
73 svn = svnwrap.SubversionRepo(url, user, passwd)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
74 subdir = svn.subdir
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
75 svnmetadir = os.path.join(repo.path, 'svn')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
76 if not os.path.exists(svnmetadir):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
77 os.makedirs(svnmetadir)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
78
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
79 revmap = open(os.path.join(svnmetadir, 'rev_map'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
80 revmap.write('1\n')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
81 last_rev = -1
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
82 branchinfo = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
83 noderevnums = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
84 for rev in repo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
85 ctx = repo[rev]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
86 convinfo = ctx.extra().get('convert_revision', None)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
87 if convinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
88 assert convinfo.startswith('svn:')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
89 revpath, revision = convinfo[40:].split('@')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
90 if subdir and subdir[0] != '/':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
91 subdir = '/' + subdir
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
92 if subdir and subdir[-1] == '/':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
93 subdir = subdir[:-1]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
94 assert revpath.startswith(subdir), ('That does not look like the '
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
95 'right location in the repo.')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
96 if uuid is None:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
97 uuid = convinfo[4:40]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
98 assert uuid == svn.uuid, 'UUIDs did not match!'
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
99 urlfile = open(os.path.join(svnmetadir, 'url'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
100 urlfile.write(url)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
101 urlfile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
102 uuidfile = open(os.path.join(svnmetadir, 'uuid'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
103 uuidfile.write(uuid)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
104 uuidfile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
105 commitpath = revpath[len(subdir)+1:]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
106 if commitpath.startswith('branches'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
107 commitpath = commitpath[len('branches/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
108 elif commitpath == 'trunk':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
109 commitpath = ''
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
110 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
111 assert False, 'Unhandled case in rebuildmeta'
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
112 revmap.write('%s %s %s\n' % (revision,
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
113 node.hex(ctx.node()),
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
114 commitpath))
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
115 revision = int(revision)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
116 noderevnums[ctx.node()] = revision
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
117 if revision > last_rev:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
118 last_rev = revision
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
119 branch = ctx.branch()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
120 if branch == 'default':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
121 branch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
122 if branch not in branchinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
123 parent = ctx.parents()[0]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
124 if (parent.node() in noderevnums
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
125 and parent.branch() != ctx.branch()):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
126 parentbranch = parent.branch()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
127 if parentbranch == 'default':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
128 parentbranch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
129 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
130 parentbranch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
131 branchinfo[branch] = (parentbranch,
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
132 noderevnums.get(parent.node(), 0),
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
133 revision)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
134 for c in ctx.children():
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
135 if c.branch() == 'closed-branches':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
136 if branch in branchinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
137 del branchinfo[branch]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
138 branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
139 pickle.dump(branchinfo, branchinfofile)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
140 branchinfofile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
141
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
142 # now handle tags
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
143 tagsinfo = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
144 realtags = svn.tags
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
145 tagsleft = realtags.items()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
146 while tagsleft:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
147 tag, tagparent = tagsleft.pop(0)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
148 source, rev = tagparent
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
149 if source.startswith('tags/'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
150 src = source[len('tags/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
151 if src in tagsinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
152 tagsinfo[tag] = tagsinfo[src]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
153 elif src in realtags:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
154 if (realtags[src][1] <= last_rev
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
155 or realtags[src][0].startswith('tags/')):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
156 tagsleft.append(src)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
157 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
158 older_tags = svn.tags_at_rev(rev)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
159 newsrc, newrev = older_tags[src]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
160 tagsleft.append((tag, (newsrc, newrev)))
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
161 continue
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
162 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
163 # determine the branch
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
164 assert not source.startswith('tags/'), "Tags can't be tags of other tags."
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
165 if source.startswith('branches/'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
166 source = source[len('branches/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
167 elif source == 'trunk':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
168 source = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
169 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
170 source = '../' + source
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
171 if rev <= last_rev and (source or 'default') in repo.branchtags():
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
172 tagsinfo[tag] = source, rev
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
173
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
174 tagsinfofile = open(os.path.join(svnmetadir, 'tag_info'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
175 pickle.dump(tagsinfo, tagsinfofile)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
176 tagsinfofile.close()
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
177
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
178
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
179 def help(ui, args=None, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
180 """show help for a given subcommands or a help overview
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
181 """
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
182 if args:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
183 subcommand = args[0]
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
184 if subcommand not in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
185 candidates = []
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
186 for c in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
187 if c.startswith(subcommand):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
188 candidates.append(c)
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
189 if len(candidates) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
190 subcommand = candidates[0]
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
191 elif len(candidates) > 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
192 ui.status('Ambiguous command. Could have been:\n%s\n' %
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
193 ' '.join(candidates))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
194 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
195 doc = table[subcommand].__doc__
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
196 if doc is None:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
197 doc = "No documentation available for %s." % subcommand
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
198 ui.status(doc.strip(), '\n')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
199 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
200 ui.status(_helpgen())
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
201
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
202
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
203 def update(ui, args, repo, clean=False, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
204 """update to a specified Subversion revision number
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
205 """
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
206 assert len(args) == 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
207 rev = int(args[0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
208 path = os.path.join(repo.path, 'svn', 'rev_map')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
209 answers = []
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
210 for k,v in util.parse_revmap(path).iteritems():
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
211 if k[0] == rev:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
212 answers.append((v, k[1]))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
213 if len(answers) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
214 if clean:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
215 return hg.clean(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
216 return hg.update(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
217 elif len(answers) == 0:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
218 ui.status('Revision %s did not produce an hg revision.\n' % rev)
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
219 return 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
220 else:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
221 ui.status('Ambiguous revision!\n')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
222 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
223 answers]+['']))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
224 return 1
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
225
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
226
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
227 nourl = ['rebuildmeta'] + utility_commands.nourl
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
228 table = {
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
229 'update': update,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
230 'help': help,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
231 'rebuildmeta': rebuildmeta,
255
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
232 'incoming': incoming,
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
233 }
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
234
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
235 table.update(utility_commands.table)
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
236
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
237
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
238 def _helpgen():
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
239 ret = ['hg svn ...', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
240 'subcommands for Subversion integration', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
241 'list of subcommands:', '']
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
242 for name, func in sorted(table.items()):
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
243 short_description = (func.__doc__ or '').splitlines()[0]
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
244 ret.append(" %-10s %s" % (name, short_description))
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
245 return '\n'.join(ret) + '\n'