Mercurial > hgsubversion
annotate util.py @ 133:2242dd1163c6
hg_delta_editor: fix bad parent revision calculation in the case of a branch
recycling a name.
Also implemented marking branches as closed in both replay and stupid paths.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 10 Dec 2008 14:29:05 -0600 |
parents | 291925677a9f |
children | 9ffde8662967 |
rev | line source |
---|---|
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
1 import os |
34
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
2 import pickle |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
3 import shutil |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 |
34
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
5 from mercurial import node |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
6 |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 svn_subcommands = { } |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
8 |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
9 def register_subcommand(name): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
10 def inner(fn): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
11 svn_subcommands[name] = fn |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
12 return fn |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
13 return inner |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
15 |
115
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
16 def generate_help(): |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
17 ret = ['', 'hg svn subcommand\n', 'Subcommands:\n'] |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
18 |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
19 for name, func in sorted(svn_subcommands.items()): |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
20 short_description = (func.__doc__ or '').split('\n')[0] |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
21 ret.append(" %-10s %s" % (name, short_description)) |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
22 |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
23 return "\n".join(ret) + '\n' |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
24 |
ed42f6e5705a
Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents:
99
diff
changeset
|
25 |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
26 def wipe_all_files(hg_wc_path): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
27 files = [f for f in os.listdir(hg_wc_path) if f != '.hg'] |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
28 for f in files: |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
29 f = os.path.join(hg_wc_path, f) |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
30 if os.path.isdir(f): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
31 shutil.rmtree(f) |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
32 else: |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
33 os.remove(f) |
34
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
34 |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
35 REVMAP_FILE_VERSION = 1 |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
36 def parse_revmap(revmap_filename): |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
37 revmap = {} |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
38 f = open(revmap_filename) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
39 try: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
40 # Remove compat code after March of 2009. That should be more than long |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
41 # enough. |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
42 revmap = pickle.load(f) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
43 f.close() |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
44 f = open(revmap_filename, 'w') |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
45 f.write('1\n') |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
46 for key, value in sorted(revmap.items()): |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
47 f.write('%s %s %s\n' % (str(key[0]), node.hex(value), key[1] or '')) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
48 f.close() |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
49 except: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
50 f.close() |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
51 f = open(revmap_filename) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
52 ver = int(f.readline()) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
53 if ver == 1: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
54 for l in f: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
55 revnum, node_hash, branch = l.split(' ', 2) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
56 if branch == '\n': |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
57 branch = None |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
58 else: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
59 branch = branch[:-1] |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
60 revmap[int(revnum), branch] = node.bin(node_hash) |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
61 f.close() |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
62 else: |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
63 print ('Your revmap was made by a newer version of hgsubversion.' |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
64 ' Please upgrade.') |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
65 raise NotImplementedError |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
66 return revmap |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
67 |
39
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
68 |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
69 class PrefixMatch(object): |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
70 def __init__(self, prefix): |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
71 self.p = prefix |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
72 |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
73 def files(self): |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
74 return [] |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
75 |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
76 def __call__(self, fn): |
b3c7b844b782
Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents:
34
diff
changeset
|
77 return fn.startswith(self.p) |
99
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
78 |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
79 def outgoing_revisions(ui, repo, hg_editor, reverse_map): |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
80 """Given a repo and an hg_editor, determines outgoing revisions for the |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
81 current working copy state. |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
82 """ |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
83 outgoing_rev_hashes = [] |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
84 working_rev = repo.parents() |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
85 assert len(working_rev) == 1 |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
86 working_rev = working_rev[0] |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
87 if working_rev.node() in reverse_map: |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
88 return |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
89 while (not working_rev.node() in reverse_map |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
90 and working_rev.node() != node.nullid): |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
91 outgoing_rev_hashes.append(working_rev.node()) |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
92 working_rev = working_rev.parents() |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
93 assert len(working_rev) == 1 |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
94 working_rev = working_rev[0] |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
95 if working_rev.node() != node.nullid: |
1da7aafdd323
Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
96 return outgoing_rev_hashes |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
115
diff
changeset
|
97 |
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
115
diff
changeset
|
98 |
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
115
diff
changeset
|
99 def is_svn_repo(repo): |
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
115
diff
changeset
|
100 return os.path.exists(os.path.join(repo.path, 'svn')) |