annotate hgsubversion/svncommands.py @ 453:bb612e625be6

tags: handle copyfrom old versions of tags more correctly
author Augie Fackler <durin42@gmail.com>
date Wed, 01 Jul 2009 14:42:46 -0500
parents ae35c389cdef
children 974102998578
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
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
8 import maps
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
9 import svnwrap
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
10 import svnmeta
241
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
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 274
diff changeset
13 import svnexternals
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
14
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
15
395
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
16 def verify(ui, repo, *args, **opts):
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
17 '''verify current revision against Subversion repository
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
18 '''
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
19
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
20 if not args:
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
21 url = repo.ui.expandpath('default')
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
22 else:
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
23 url = args[0]
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
24
441
de085126dbd4 svncommands: use rev instead of verifynode -- should not have to be a node
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 427
diff changeset
25 ctx = repo[opts.get('rev', '.')]
395
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
26 if 'close' in ctx.extra():
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
27 ui.write('cannot verify closed branch')
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
28 return 0
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
29 srev = ctx.extra().get('convert_revision')
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
30 if srev is None:
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
31 raise hgutil.Abort('revision %s not from SVN' % ctx)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
32
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
33 srev = int(srev.split('@')[1])
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
34 ui.write('verifying %s against r%i\n' % (ctx, srev))
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
35
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
36 url = util.normalize_url(url.rstrip('/'))
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
37 user, passwd = util.getuserpass(opts)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
38 svn = svnwrap.SubversionRepo(url, user, passwd)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
39
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
40 btypes = {'default': 'trunk'}
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
41 branchpath = btypes.get(ctx.branch(), 'branches/%s' % ctx.branch())
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
42 svnfiles = set()
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
43 result = 0
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
44 for fn, type in svn.list_files(branchpath, srev):
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
45 if type != 'f':
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
46 continue
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
47 svnfiles.add(fn)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
48 data, mode = svn.get_file(branchpath + '/' + fn, srev)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
49 fctx = ctx[fn]
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
50 dmatch = fctx.data() == data
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
51 mmatch = fctx.flags() == mode
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
52 if not (dmatch and mmatch):
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
53 ui.write('difference in file %s' % fn)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
54 result = 1
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
55
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
56 hgfiles = set(ctx)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
57 hgfiles.discard('.hgtags')
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
58 hgfiles.discard('.hgsvnexternals')
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
59 if hgfiles != svnfiles:
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
60 missing = set(hgfiles).symmetric_difference(svnfiles)
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
61 ui.write('missing files: %s' % (', '.join(missing)))
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
62 result = 1
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
63
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
64 return result
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
65
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
66
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
67 def rebuildmeta(ui, repo, hg_repo_path, args, **opts):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
68 """rebuild hgsubversion metadata using values stored in revisions
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
69 """
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
70 dest = None
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
71 if len(args) == 1:
419
3ed71e63f64c imported patch import-cleanup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 414
diff changeset
72 dest = args[0]
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
73 elif len(args) > 1:
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
74 raise hgutil.Abort('rebuildmeta takes 1 or no arguments')
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
75 url = repo.ui.expandpath(dest or 'default-push', dest or 'default')
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
76 uuid = None
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 307
diff changeset
77 url = util.normalize_url(url.rstrip('/'))
265
9f0738587f94 Re-re-refix username support, add a comment so maybe I remember this time.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
78 user, passwd = util.getuserpass(opts)
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
79 svn = svnwrap.SubversionRepo(url, user, passwd)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
80 subdir = svn.subdir
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
81 svnmetadir = os.path.join(repo.path, 'svn')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
82 if not os.path.exists(svnmetadir):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
83 os.makedirs(svnmetadir)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
84
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
85 revmap = open(os.path.join(svnmetadir, 'rev_map'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
86 revmap.write('1\n')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
87 last_rev = -1
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
88 branchinfo = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
89 noderevnums = {}
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
90 tags = maps.TagMap(repo)
452
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
91
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
92 skipped = set()
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
93
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
94 for rev in repo:
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
95
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
96 ctx = repo[rev]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
97 convinfo = ctx.extra().get('convert_revision', None)
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
98 if not convinfo:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
99 continue
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
100 if '.hgtags' in ctx.files():
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
101 parent = ctx.parents()[0]
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
102 parentdata = ''
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
103 if '.hgtags' in parent:
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
104 parentdata = parent.filectx('.hgtags').data()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
105 newdata = ctx.filectx('.hgtags').data()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
106 for newtag in newdata[len(parentdata):-1].split('\n'):
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 447
diff changeset
107 ha, tag = newtag.split(' ', 1)
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
108 tagged = repo[ha].extra().get('convert_revision', None)
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
109 if tagged is None:
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
110 tagged = -1
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
111 else:
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
112 tagged = int(tagged[40:].split('@')[1])
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
113 # This is max(tagged rev, tagging rev) because if it is a normal
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
114 # tag, the tagging revision has the right rev number. However, if it
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
115 # was an edited tag, then the tagged revision has the correct revision
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
116 # number.
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
117 tagging = int(convinfo[40:].split('@')[1])
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
118 tagrev = max(tagged, tagging)
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 452
diff changeset
119 tags[tag] = node.bin(ha), tagrev
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
120
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
121 # check that the conversion metadata matches expectations
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
122 assert convinfo.startswith('svn:')
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
123 revpath, revision = convinfo[40:].split('@')
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
124 if subdir and subdir[0] != '/':
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
125 subdir = '/' + subdir
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
126 if subdir and subdir[-1] == '/':
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
127 subdir = subdir[:-1]
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
128 assert revpath.startswith(subdir), ('That does not look like the '
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
129 'right location in the repo.')
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
130
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
131 # write repository uuid if required
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
132 if uuid is None:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
133 uuid = convinfo[4:40]
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
134 assert uuid == svn.uuid, 'UUIDs did not match!'
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
135 uuidfile = open(os.path.join(svnmetadir, 'uuid'), 'w')
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
136 uuidfile.write(uuid)
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
137 uuidfile.close()
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
138
423
021bdbf391bb put convert_revision in branch-closing csets
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 419
diff changeset
139 # don't reflect closed branches
452
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
140 if (ctx.extra().get('close') and not ctx.files() or
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
141 ctx.parents()[0].node() in skipped):
ae35c389cdef tags: allow editing tags of closed branches without reopening the branch
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
142 skipped.add(ctx.node())
423
021bdbf391bb put convert_revision in branch-closing csets
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 419
diff changeset
143 continue
021bdbf391bb put convert_revision in branch-closing csets
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 419
diff changeset
144
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
145 # find commitpath, write to revmap
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
146 commitpath = revpath[len(subdir)+1:]
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
147 if commitpath.startswith('branches'):
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
148 commitpath = commitpath[len('branches/'):]
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
149 elif commitpath == 'trunk':
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
150 commitpath = ''
447
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 446
diff changeset
151 elif commitpath.startswith('tags'):
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 446
diff changeset
152 if ctx.extra().get('close'):
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 446
diff changeset
153 continue
0d3b5acb1d51 tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents: 446
diff changeset
154 commitpath = '../' + commitpath
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
155 else:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
156 assert False, 'Unhandled case in rebuildmeta'
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
157 revmap.write('%s %s %s\n' % (revision, ctx.hex(), commitpath))
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
158
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
159 revision = int(revision)
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
160 noderevnums[ctx.node()] = revision
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
161 if revision > last_rev:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
162 last_rev = revision
375
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
163
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
164 # deal with branches
423
021bdbf391bb put convert_revision in branch-closing csets
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 419
diff changeset
165 if ctx.extra().get('close'):
375
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
166 continue
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
167 branch = ctx.branch()
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
168 if branch == 'default':
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
169 branch = None
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
170 if branch not in branchinfo:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
171 parent = ctx.parents()[0]
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
172 if (parent.node() in noderevnums
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
173 and parent.branch() != ctx.branch()):
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
174 parentbranch = parent.branch()
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
175 if parentbranch == 'default':
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
176 parentbranch = None
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
177 else:
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
178 parentbranch = None
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
179 branchinfo[branch] = (parentbranch,
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
180 noderevnums.get(parent.node(), 0),
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
181 revision)
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
182
375
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
183 for cctx in ctx.children():
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
184 if cctx.extra().get('close'):
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
185 branchinfo.pop(branch, None)
375
af9fc01299b4 Make branch closing more Mercurial-like.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 371
diff changeset
186 break
371
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
187
b45671850969 Add some comments for rebuildmeta, simplify a little.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 342
diff changeset
188 # save off branch info
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
189 branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
190 pickle.dump(branchinfo, branchinfofile)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
191 branchinfofile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
192
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
193
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
194 def help(ui, args=None, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
195 """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
196 """
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
197 if args:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
198 subcommand = args[0]
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
199 if subcommand not in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
200 candidates = []
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
201 for c in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
202 if c.startswith(subcommand):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
203 candidates.append(c)
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
204 if len(candidates) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
205 subcommand = candidates[0]
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
206 elif len(candidates) > 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
207 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
208 ' '.join(candidates))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
209 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
210 doc = table[subcommand].__doc__
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
211 if doc is None:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
212 doc = "No documentation available for %s." % subcommand
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
213 ui.status(doc.strip(), '\n')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
214 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
215 ui.status(_helpgen())
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
216
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
217
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
218 def update(ui, args, repo, clean=False, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
219 """update to a specified Subversion revision number
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
220 """
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
221
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
222 assert len(args) == 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
223 rev = int(args[0])
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
224 meta = svnmeta.SVNMeta(repo)
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
225
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
226 answers = []
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
227 for k, v in meta.revmap.iteritems():
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
228 if k[0] == rev:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
229 answers.append((v, k[1]))
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
230
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
231 if len(answers) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
232 if clean:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
233 return hg.clean(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
234 return hg.update(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
235 elif len(answers) == 0:
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
236 ui.status('revision %s did not produce an hg revision\n' % rev)
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
237 return 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
238 else:
446
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
239 ui.status('ambiguous revision!\n')
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
240 revs = ['%s on %s' % (node.hex(a[0]), a[1]) for a in answers] + ['']
cbd230043379 svncommands: get update working again
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 441
diff changeset
241 ui.status('\n'.join(revs))
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
242 return 1
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
243
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
244
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
245 table = {
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
246 'update': update,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
247 'help': help,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
248 'rebuildmeta': rebuildmeta,
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 274
diff changeset
249 'updateexternals': svnexternals.updateexternals,
395
636e9bf5d49c svncommands: add verify command
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 384
diff changeset
250 'verify': verify,
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
251 }
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
252
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
253 table.update(utility_commands.table)
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
254
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
255
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
256 def _helpgen():
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
257 ret = ['hg svn ...', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
258 'subcommands for Subversion integration', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
259 'list of subcommands:', '']
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
260 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
261 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
262 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
263 return '\n'.join(ret) + '\n'