Mercurial > hgsubversion
annotate util.py @ 34:50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Fri, 17 Oct 2008 11:03:52 -0500 |
parents | 1267b1944cd7 |
children | b3c7b844b782 |
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 |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
16 def wipe_all_files(hg_wc_path): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
17 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
|
18 for f in files: |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
19 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
|
20 if os.path.isdir(f): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
21 shutil.rmtree(f) |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
22 else: |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
23 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
|
24 |
50d55c3e0d85
Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents:
19
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 # 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
|
31 # 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 ' 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
|
55 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
|
56 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
|
57 |