Mercurial > hgsubversion
annotate hgsubversion/maps.py @ 1193:a55339d35066
maps: load commandline authormap in __init__
Funcationally, this is the same as before but consolidates the logic to its own
object so we later refactor all the map objects to inherit from a common base
object.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 11:20:46 -0500 |
parents | 38dd8721fb0d |
children | 49791c40a8a5 |
rev | line source |
---|---|
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
1 ''' Module for self-contained maps. ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
2 |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
3 import errno |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
4 import os |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
5 from mercurial import util as hgutil |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
6 from mercurial import node |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
7 |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
8 import svncommands |
829
5061640fe5bc
revmap: load/save _youngest using new load_string and save_string API
Yonggang Luo <luoyonggang@gmail.com>
parents:
826
diff
changeset
|
9 import util |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
10 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
11 class AuthorMap(dict): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
12 '''A mapping from Subversion-style authors to Mercurial-style |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
13 authors, and back. The data is stored persistently on disk. |
322
05cd4a5138bf
Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents:
310
diff
changeset
|
14 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
15 If the 'hgsubversion.defaultauthors' configuration option is set to false, |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
16 attempting to obtain an unknown author will fail with an Abort. |
1188
38dd8721fb0d
maps: remove trailing whitespace
Sean Farley <sean.michael.farley@gmail.com>
parents:
1187
diff
changeset
|
17 |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
18 If the 'hgsubversion.caseignoreauthors' configuration option is set to true, |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
19 the userid from Subversion is always compared lowercase. |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
20 ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
21 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
22 def __init__(self, ui, path, defaulthost=None): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
23 '''Initialise a new AuthorMap. |
322
05cd4a5138bf
Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents:
310
diff
changeset
|
24 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
25 The ui argument is used to print diagnostic messages. |
322
05cd4a5138bf
Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents:
310
diff
changeset
|
26 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
27 The path argument is the location of the backing store, |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
28 typically .hg/svn/authors. |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
29 ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
30 self.ui = ui |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
31 self.path = path |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
32 self.use_defaultauthors = self.ui.configbool('hgsubversion', 'defaultauthors', True) |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
33 self.caseignoreauthors = self.ui.configbool('hgsubversion', 'caseignoreauthors', False) |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
34 if defaulthost: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
35 self.defaulthost = '@%s' % defaulthost.lstrip('@') |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
36 else: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
37 self.defaulthost = '' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
38 self.super = super(AuthorMap, self) |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
39 self.super.__init__() |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
40 self.load(path) |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
41 |
1193
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
42 # append authors specified from the commandline |
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
43 clmap = util.configpath(self.ui, 'authormap') |
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
44 if clmap: |
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
45 self.load(clmap) |
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
46 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
47 def load(self, path): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
48 ''' Load mappings from a file at the specified path. ''' |
818
9aed3bfc92d6
authormap: expand environment variables when evaluating map path
maugustin <maugustin@gmx.net>
parents:
809
diff
changeset
|
49 |
9aed3bfc92d6
authormap: expand environment variables when evaluating map path
maugustin <maugustin@gmx.net>
parents:
809
diff
changeset
|
50 path = os.path.expandvars(path) |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
51 if not os.path.exists(path): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
52 return |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
53 |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
54 writing = False |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
55 if path != self.path: |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
56 writing = open(self.path, 'a') |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
57 |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
58 self.ui.debug('reading authormap from %s\n' % path) |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
59 f = open(path, 'r') |
820
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
60 for number, line_org in enumerate(f): |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
61 |
820
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
62 line = line_org.split('#')[0] |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
63 if not line.strip(): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
64 continue |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
65 |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
66 try: |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
67 src, dst = line.split('=', 1) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
68 except (IndexError, ValueError): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
69 msg = 'ignoring line %i in author map %s: %s\n' |
579
21a389e4d8b5
maps: if operation can continue, it should probably not use ui.warn()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
574
diff
changeset
|
70 self.ui.status(msg % (number, path, line.rstrip())) |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
71 continue |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
72 |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
73 src = src.strip() |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
74 dst = dst.strip() |
820
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
75 |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
76 if self.caseignoreauthors: |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
77 src = src.lower() |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
78 |
820
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
79 if writing: |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
80 if not src in self: |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
81 self.ui.debug('adding author %s to author map\n' % src) |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
82 elif dst != self[src]: |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
83 msg = 'overriding author: "%s" to "%s" (%s)\n' |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
84 self.ui.status(msg % (self[src], dst, src)) |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
85 writing.write(line_org) |
09f7c1c09207
authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents:
818
diff
changeset
|
86 |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
87 self[src] = dst |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
88 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
89 f.close() |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
90 if writing: |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
91 writing.close() |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
92 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
93 def __getitem__(self, author): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
94 ''' Similar to dict.__getitem__, except in case of an unknown author. |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
95 In such cases, a new value is generated and added to the dictionary |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
96 as well as the backing store. ''' |
735
c2b9e08ecf10
maps: map a missing author to '(no author)'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
729
diff
changeset
|
97 if author is None: |
c2b9e08ecf10
maps: map a missing author to '(no author)'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
729
diff
changeset
|
98 author = '(no author)' |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
99 |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
100 if self.caseignoreauthors: |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
101 search_author = author.lower() |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
102 else: |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
103 search_author = author |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
104 |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
105 if search_author in self: |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
106 result = self.super.__getitem__(search_author) |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
107 elif self.use_defaultauthors: |
310
15b8bab03504
Change default author substitution to avoid updating test hashes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
307
diff
changeset
|
108 self[author] = result = '%s%s' % (author, self.defaulthost) |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
109 msg = 'substituting author "%s" for default "%s"\n' |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
110 self.ui.debug(msg % (author, result)) |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
111 else: |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
112 msg = 'author %s has no entry in the author map!' |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
113 raise hgutil.Abort(msg % author) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
114 self.ui.debug('mapping author "%s" to "%s"\n' % (author, result)) |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
115 return result |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
116 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
117 def reverselookup(self, author): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
118 for svnauthor, hgauthor in self.iteritems(): |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
119 if author == hgauthor: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
120 return svnauthor |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
121 else: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
122 # Mercurial incorrectly splits at e.g. '.', so we roll our own. |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
123 return author.rsplit('@', 1)[0] |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
124 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
125 |
728
cfefeefad199
rename TagMap to Tags, to free up the TagMap name
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
725
diff
changeset
|
126 class Tags(dict): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
127 """Map tags to converted node identifier. |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
128 |
729 | 129 tag names are non-empty strings. Tags are saved in a file |
130 called tagmap, for backwards compatibility reasons. | |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
131 """ |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
132 VERSION = 2 |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
133 |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
134 def __init__(self, meta, endrev=None): |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
135 dict.__init__(self) |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
136 self.meta = meta |
725 | 137 self.endrev = endrev |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
138 if os.path.isfile(self.meta.tagfile): |
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
139 self._load() |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
140 else: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
141 self._write() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
142 |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
143 def _load(self): |
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
144 f = open(self.meta.tagfile) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
145 ver = int(f.readline()) |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
146 if ver < self.VERSION: |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
147 self.meta.ui.status('tag map outdated, running rebuildmeta...\n') |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
148 f.close() |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
149 os.unlink(self.meta.tagfile) |
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
150 svncommands.rebuildmeta(self.meta.ui, self.meta.repo, ()) |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
151 return |
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
152 elif ver != self.VERSION: |
891
83cc6e9e8425
kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
889
diff
changeset
|
153 raise hgutil.Abort('tagmap too new -- please upgrade') |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
154 for l in f: |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
155 ha, revision, tag = l.split(' ', 2) |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
156 revision = int(revision) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
157 tag = tag[:-1] |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
158 if self.endrev is not None and revision > self.endrev: |
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
159 break |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
160 if not tag: |
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
161 continue |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
162 dict.__setitem__(self, tag, node.bin(ha)) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
163 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
164 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
165 def _write(self): |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
166 assert self.endrev is None |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
167 f = open(self.meta.tagfile, 'w') |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
168 f.write('%s\n' % self.VERSION) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
169 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
170 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
171 def update(self, other): |
725 | 172 for k, v in other.iteritems(): |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
173 self[k] = v |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
174 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
175 def __contains__(self, tag): |
593
eb16630bceb1
maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents:
579
diff
changeset
|
176 return (tag and dict.__contains__(self, tag) |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
177 and dict.__getitem__(self, tag) != node.nullid) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
178 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
179 def __getitem__(self, tag): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
180 if tag and tag in self: |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
181 return dict.__getitem__(self, tag) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
182 raise KeyError() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
183 |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
184 def __setitem__(self, tag, info): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
185 if not tag: |
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
186 raise hgutil.Abort('tag cannot be empty') |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
187 ha, revision = info |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
188 f = open(self.meta.tagfile, 'a') |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
189 f.write('%s %s %s\n' % (node.hex(ha), revision, tag)) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
190 f.close() |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
191 dict.__setitem__(self, tag, ha) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
192 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
193 |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
194 class RevMap(dict): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
195 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
196 VERSION = 1 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
197 |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
198 def __init__(self, meta): |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
199 dict.__init__(self) |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
200 self.meta = meta |
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
201 |
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
202 if os.path.isfile(self.meta.revmap_file): |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
203 self._load() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
204 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
205 self._write() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
206 |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
207 def hashes(self): |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
208 return dict((v, k) for (k, v) in self.iteritems()) |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
209 |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
210 def branchedits(self, branch, rev): |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
211 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
212 return sorted(filter(check, self.iteritems()), reverse=True) |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
213 |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
214 @classmethod |
1182
8f9619a67565
maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1144
diff
changeset
|
215 def readmapfile(cls, path, missingok=True): |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
216 try: |
1182
8f9619a67565
maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1144
diff
changeset
|
217 f = open(path) |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
218 except IOError, err: |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
219 if not missingok or err.errno != errno.ENOENT: |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
220 raise |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
221 return iter([]) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
222 ver = int(f.readline()) |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
223 if ver != cls.VERSION: |
891
83cc6e9e8425
kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
889
diff
changeset
|
224 raise hgutil.Abort('revmap too new -- please upgrade') |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
225 return f |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
226 |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
227 def _load(self): |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
228 for l in self.readmapfile(self.meta.revmap_file): |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
229 revnum, ha, branch = l.split(' ', 2) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
230 if branch == '\n': |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
231 branch = None |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
232 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
233 branch = branch[:-1] |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
234 revnum = int(revnum) |
1184
43384d2782dc
svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1183
diff
changeset
|
235 if revnum > self.meta.lastpulled or not self.meta.lastpulled: |
43384d2782dc
svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1183
diff
changeset
|
236 self.meta.lastpulled = revnum |
1186
f9650d24464a
svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1184
diff
changeset
|
237 if revnum < self.meta.firstpulled or not self.meta.firstpulled: |
f9650d24464a
svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1184
diff
changeset
|
238 self.meta.firstpulled = revnum |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
239 dict.__setitem__(self, (revnum, branch), node.bin(ha)) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
240 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
241 def _write(self): |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
242 f = open(self.meta.revmap_file, 'w') |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
243 f.write('%s\n' % self.VERSION) |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
244 f.close() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
245 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
246 def __setitem__(self, key, ha): |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
247 revnum, branch = key |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
248 f = open(self.meta.revmap_file, 'a') |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
249 b = branch or '' |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
250 f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n') |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
251 f.close() |
1184
43384d2782dc
svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1183
diff
changeset
|
252 if revnum > self.meta.lastpulled or not self.meta.lastpulled: |
43384d2782dc
svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1183
diff
changeset
|
253 self.meta.lastpulled = revnum |
1186
f9650d24464a
svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1184
diff
changeset
|
254 if revnum < self.meta.firstpulled or not self.meta.firstpulled: |
f9650d24464a
svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents:
1184
diff
changeset
|
255 self.meta.firstpulled = revnum |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
256 dict.__setitem__(self, (revnum, branch), ha) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
257 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
258 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
259 class FileMap(object): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
260 |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
261 VERSION = 1 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
262 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
263 def __init__(self, ui, path): |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
264 '''Initialise a new FileMap. |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
265 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
266 The ui argument is used to print diagnostic messages. |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
267 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
268 The path argument is the location of the backing store, |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
269 typically .hg/svn/filemap. |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
270 ''' |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
271 self.ui = ui |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
272 self.path = path |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
273 self.include = {} |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
274 self.exclude = {} |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
275 if os.path.isfile(self.path): |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
276 self._load() |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
277 else: |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
278 self._write() |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
279 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
280 def _rpairs(self, name): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
281 e = len(name) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
282 while e != -1: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
283 yield name[:e], name[e+1:] |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
284 e = name.rfind('/', 0, e) |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
285 yield '.', name |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
286 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
287 def check(self, m, path): |
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
288 m = getattr(self, m) |
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
289 for pre, _suf in self._rpairs(path): |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
290 if pre in m: |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
291 return m[pre] |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
292 return -1 |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
293 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
294 def __contains__(self, path): |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
295 if not len(path): |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
296 return True |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
297 if len(self.include): |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
298 inc = self.check('include', path) |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
299 elif not len(self.exclude): |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
300 return True |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
301 else: |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
302 inc = 0 |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
303 if len(self.exclude): |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
304 exc = self.check('exclude', path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
305 else: |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
306 exc = -1 |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
307 # respect rule order: newer rules override older |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
308 return inc > exc |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
309 |
822
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
310 # Needed so empty filemaps are false |
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
311 def __len__(self): |
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
312 return len(self.include) + len(self.exclude) |
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
313 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
314 def add(self, fn, m, path): |
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
315 mapping = getattr(self, m) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
316 if path in mapping: |
593
eb16630bceb1
maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents:
579
diff
changeset
|
317 msg = 'duplicate %s entry in %s: "%s"\n' |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
318 self.ui.status(msg % (m, fn, path)) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
319 return |
956
24fbba02cb8f
maps: fix filemap loading --verbose message
Patrick Mezard <patrick@mezard.eu>
parents:
891
diff
changeset
|
320 bits = m.rstrip('e'), path |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
321 self.ui.debug('%sing %s\n' % bits) |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
322 # respect rule order |
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
323 mapping[path] = len(self) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
324 if fn != self.path: |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
325 f = open(self.path, 'a') |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
326 f.write(m + ' ' + path + '\n') |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
327 f.close() |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
328 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
329 def load(self, fn): |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
330 self.ui.debug('reading file map from %s\n' % fn) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
331 f = open(fn, 'r') |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
332 self.load_fd(f, fn) |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
333 f.close() |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
334 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
335 def load_fd(self, f, fn): |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
336 for line in f: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
337 if line.strip() == '' or line.strip()[0] == '#': |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
338 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
339 try: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
340 cmd, path = line.split(' ', 1) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
341 cmd = cmd.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
342 path = path.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
343 if cmd in ('include', 'exclude'): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
344 self.add(fn, cmd, path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
345 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
346 self.ui.warn('unknown filemap command %s\n' % cmd) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
347 except IndexError: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
348 msg = 'ignoring bad line in filemap %s: %s\n' |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
349 self.ui.warn(msg % (fn, line.rstrip())) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
350 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
351 def _load(self): |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
352 self.ui.debug('reading in-repo file map from %s\n' % self.path) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
353 f = open(self.path) |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
354 ver = int(f.readline()) |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
355 if ver != self.VERSION: |
891
83cc6e9e8425
kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
889
diff
changeset
|
356 raise hgutil.Abort('filemap too new -- please upgrade') |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
357 self.load_fd(f, self.path) |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
358 f.close() |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
359 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
360 def _write(self): |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
361 f = open(self.path, 'w') |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
362 f.write('%s\n' % self.VERSION) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
363 f.close() |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
364 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
365 class BranchMap(dict): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
366 '''Facility for controlled renaming of branch names. Example: |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
367 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
368 oldname = newname |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
369 other = default |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
370 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
371 All changes on the oldname branch will now be on the newname branch; all |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
372 changes on other will now be on default (have no branch name set). |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
373 ''' |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
374 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
375 def __init__(self, ui, path): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
376 self.ui = ui |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
377 self.path = path |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
378 self.super = super(BranchMap, self) |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
379 self.super.__init__() |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
380 self.load(path) |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
381 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
382 def load(self, path): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
383 '''Load mappings from a file at the specified path.''' |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
384 if not os.path.exists(path): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
385 return |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
386 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
387 writing = False |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
388 if path != self.path: |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
389 writing = open(self.path, 'a') |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
390 |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
391 self.ui.debug('reading branchmap from %s\n' % path) |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
392 f = open(path, 'r') |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
393 for number, line in enumerate(f): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
394 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
395 if writing: |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
396 writing.write(line) |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
397 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
398 line = line.split('#')[0] |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
399 if not line.strip(): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
400 continue |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
401 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
402 try: |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
403 src, dst = line.split('=', 1) |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
404 except (IndexError, ValueError): |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
405 msg = 'ignoring line %i in branch map %s: %s\n' |
579
21a389e4d8b5
maps: if operation can continue, it should probably not use ui.warn()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
574
diff
changeset
|
406 self.ui.status(msg % (number, path, line.rstrip())) |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
407 continue |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
408 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
409 src = src.strip() |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
410 dst = dst.strip() |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
411 self.ui.debug('adding branch %s to branch map\n' % src) |
636
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
412 |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
413 if not dst: |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
414 # prevent people from assuming such lines are valid |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
415 raise hgutil.Abort('removing branches is not supported, yet\n' |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
416 '(line %i in branch map %s)' |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
417 % (number, path)) |
d4f433ee709a
branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
624
diff
changeset
|
418 elif src in self and dst != self[src]: |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
419 msg = 'overriding branch: "%s" to "%s" (%s)\n' |
579
21a389e4d8b5
maps: if operation can continue, it should probably not use ui.warn()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
574
diff
changeset
|
420 self.ui.status(msg % (self[src], dst, src)) |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
421 self[src] = dst |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
422 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
423 f.close() |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
424 if writing: |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
425 writing.close() |
729 | 426 |
427 class TagMap(dict): | |
428 '''Facility for controlled renaming of tags. Example: | |
429 | |
430 oldname = newname | |
431 other = | |
432 | |
809
ab372e38fb6c
maps: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents:
742
diff
changeset
|
433 The oldname tag from SVN will be represented as newname in the hg tags; |
ab372e38fb6c
maps: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents:
742
diff
changeset
|
434 the other tag will not be reflected in the hg repository. |
729 | 435 ''' |
436 | |
437 def __init__(self, ui, path): | |
438 self.ui = ui | |
439 self.path = path | |
440 self.super = super(TagMap, self) | |
441 self.super.__init__() | |
442 self.load(path) | |
443 | |
444 def load(self, path): | |
445 '''Load mappings from a file at the specified path.''' | |
446 if not os.path.exists(path): | |
447 return | |
448 | |
449 writing = False | |
450 if path != self.path: | |
451 writing = open(self.path, 'a') | |
452 | |
976
ab3c02dad95c
maps: only show 'reading ...' as debug output
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
956
diff
changeset
|
453 self.ui.debug('reading tag renames from %s\n' % path) |
729 | 454 f = open(path, 'r') |
455 for number, line in enumerate(f): | |
456 | |
457 if writing: | |
458 writing.write(line) | |
459 | |
460 line = line.split('#')[0] | |
461 if not line.strip(): | |
462 continue | |
463 | |
464 try: | |
465 src, dst = line.split('=', 1) | |
466 except (IndexError, ValueError): | |
467 msg = 'ignoring line %i in tag renames %s: %s\n' | |
468 self.ui.status(msg % (number, path, line.rstrip())) | |
469 continue | |
470 | |
471 src = src.strip() | |
472 dst = dst.strip() | |
473 self.ui.debug('adding tag %s to tag renames\n' % src) | |
474 | |
475 if src in self and dst != self[src]: | |
476 msg = 'overriding tag rename: "%s" to "%s" (%s)\n' | |
477 self.ui.status(msg % (self[src], dst, src)) | |
478 self[src] = dst | |
479 | |
480 f.close() | |
481 if writing: | |
482 writing.close() |