Mercurial > hgsubversion
annotate hgsubversion/maps.py @ 448:fbc7cf4fd701
tags: reinstate a tag map file in a better way
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 23 Jun 2009 21:33:40 -0500 |
parents | 2851b81c65ce |
children | bb612e625be6 |
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 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
3 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
|
4 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
|
5 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
|
6 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
7 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
|
8 '''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
|
9 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
|
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 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
|
12 attempting to obtain an unknown author will fail with an Abort. |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
13 ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
14 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
15 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
|
16 '''Initialise a new AuthorMap. |
322
05cd4a5138bf
Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents:
310
diff
changeset
|
17 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
18 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
|
19 |
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 The path argument is the location of the backing store, |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
21 typically .hg/authormap. |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
22 ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
23 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
|
24 self.path = path |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
25 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
|
26 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
|
27 else: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
33 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
|
34 ''' Load mappings from a file at the specified path. ''' |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
35 if not os.path.exists(path): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
36 return |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
37 |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
38 writing = False |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
39 if path != self.path: |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
40 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
|
41 |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
42 self.ui.note('reading authormap from %s\n' % path) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
43 f = open(path, 'r') |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
44 for number, line in enumerate(f): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
45 |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
46 if writing: |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
47 writing.write(line) |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
48 |
360
27e9fea5d114
Author maps: strip comments.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
359
diff
changeset
|
49 line = line.split('#')[0] |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
50 if not line.strip(): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
51 continue |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
52 |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
53 try: |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
54 src, dst = line.split('=', 1) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
55 except (IndexError, ValueError): |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
56 msg = 'ignoring line %i in author map %s: %s\n' |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
57 self.ui.warn(msg % (number, path, line.rstrip())) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
58 continue |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
59 |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
60 src = src.strip() |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
61 dst = dst.strip() |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
62 self.ui.debug('adding author %s to author map\n' % src) |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
63 if src in self and dst != self[src]: |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
64 msg = 'overriding author: "%s" to "%s" (%s)\n' |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
65 self.ui.warn(msg % (self[src], dst, src)) |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
66 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
|
67 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
68 f.close() |
430
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
69 if writing: |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
70 writing.flush() |
2851b81c65ce
maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
415
diff
changeset
|
71 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
|
72 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
73 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
|
74 ''' 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
|
75 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
|
76 as well as the backing store. ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
77 if author in self: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
78 result = self.super.__getitem__(author) |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
79 elif self.ui.configbool('hgsubversion', 'defaultauthors', True): |
310
15b8bab03504
Change default author substitution to avoid updating test hashes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
307
diff
changeset
|
80 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
|
81 msg = 'substituting author "%s" for default "%s"\n' |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
82 self.ui.note(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
|
83 else: |
359
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
84 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
|
85 raise hgutil.Abort(msg % author) |
e74321f6f8a1
Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
358
diff
changeset
|
86 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
|
87 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
|
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 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
|
90 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
|
91 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
|
92 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
|
93 else: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
94 # 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
|
95 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
|
96 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
97 |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
98 class TagMap(dict): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
99 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
100 VERSION = 1 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
101 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
102 def __init__(self, repo): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
103 dict.__init__(self) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
104 self.path = os.path.join(repo.path, 'svn', 'tagmap') |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
105 self.seen = 0 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
106 if os.path.isfile(self.path): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
107 self._load() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
108 else: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
109 self._write() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
110 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
111 def _load(self): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
112 f = open(self.path) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
113 ver = int(f.readline()) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
114 if ver != self.VERSION: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
115 print 'tagmap too new -- please upgrade' |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
116 raise NotImplementedError |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
117 for l in f: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
118 hash, tag = l.split(' ', 1) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
119 tag = tag[:-1] |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
120 dict.__setitem__(self, tag, node.bin(hash)) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
121 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
122 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
123 def _write(self): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
124 f = open(self.path, 'w') |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
125 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
|
126 f.flush() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
127 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
128 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
129 def update(self, other): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
130 for k,v in other.iteritems(): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
131 self[k] = v |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
132 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
133 def __contains__(self, tag): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
134 return dict.__contains__(self, tag) and dict.__getitem__(self, tag) != node.nullid |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
135 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
136 def __getitem__(self, tag): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
137 if tag in self: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
138 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
|
139 raise KeyError() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
140 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
141 def __setitem__(self, tag, hash): |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
142 f = open(self.path, 'a') |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
143 f.write(node.hex(hash) + ' ' + tag + '\n') |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
144 f.flush() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
145 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
146 dict.__setitem__(self, tag, hash) |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
147 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
148 |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
149 class RevMap(dict): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
150 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
151 VERSION = 1 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
152 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
153 def __init__(self, repo): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
154 dict.__init__(self) |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
155 self.path = os.path.join(repo.path, 'svn', 'rev_map') |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
156 self.seen = 0 |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
157 if os.path.isfile(self.path): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
158 self._load() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
159 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
160 self._write() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
161 |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
162 def hashes(self): |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
163 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
|
164 |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
169 def _load(self): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
170 f = open(self.path) |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
171 ver = int(f.readline()) |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
172 if ver != self.VERSION: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
173 print 'revmap too new -- please upgrade' |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
174 raise NotImplementedError |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
175 for l in f: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
176 revnum, hash, branch = l.split(' ', 2) |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
177 if branch == '\n': |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
178 branch = None |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
179 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
180 branch = branch[:-1] |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
181 revnum = int(revnum) |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
182 self.seen = max(self.seen, revnum) |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
183 dict.__setitem__(self, (revnum, branch), node.bin(hash)) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
184 f.close() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
185 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
186 def _write(self): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
187 f = open(self.path, 'w') |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
188 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
|
189 f.flush() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
190 f.close() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
191 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
192 def __setitem__(self, key, hash): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
193 revnum, branch = key |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
194 f = open(self.path, 'a') |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
195 b = branch or '' |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
196 f.write(str(revnum) + ' ' + node.hex(hash) + ' ' + b + '\n') |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
197 f.flush() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
198 f.close() |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
199 self.seen = max(self.seen, revnum) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
200 dict.__setitem__(self, (revnum, branch), hash) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
201 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
202 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
203 class FileMap(object): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
204 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
205 def __init__(self, repo): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
206 self.ui = repo.ui |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
207 self.include = {} |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
208 self.exclude = {} |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
209 filemap = repo.ui.config('hgsubversion', 'filemap') |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
210 if filemap and os.path.exists(filemap): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
211 self.load(filemap) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
212 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
213 def _rpairs(self, name): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
214 yield '.', name |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
215 e = len(name) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
216 while e != -1: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
217 yield name[:e], name[e+1:] |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
218 e = name.rfind('/', 0, e) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
219 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
220 def check(self, map, path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
221 map = getattr(self, map) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
222 for pre, suf in self._rpairs(path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
223 if pre not in map: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
224 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
225 return map[pre] |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
226 return None |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
227 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
228 def __contains__(self, path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
229 if len(self.include) and len(path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
230 inc = self.check('include', path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
231 else: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
232 inc = path |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
233 if len(self.exclude) and len(path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
234 exc = self.check('exclude', path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
235 else: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
236 exc = None |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
237 if inc is None or exc is not None: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
238 return False |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
239 return True |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
240 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
241 def add(self, fn, map, path): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
242 mapping = getattr(self, map) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
243 if path in mapping: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
244 msg = 'duplicate %s entry in %s: "%d"\n' |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
245 self.ui.warn(msg % (map, fn, path)) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
246 return |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
247 bits = map.strip('e'), path |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
248 self.ui.debug('%sing %s\n' % bits) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
249 mapping[path] = path |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
250 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
251 def load(self, fn): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
252 self.ui.note('reading file map from %s\n' % fn) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
253 f = open(fn, 'r') |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
254 for line in f: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
255 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
|
256 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
257 try: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
258 cmd, path = line.split(' ', 1) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
259 cmd = cmd.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
260 path = path.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
261 if cmd in ('include', 'exclude'): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
262 self.add(fn, cmd, path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
263 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
264 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
|
265 except IndexError: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
266 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
|
267 self.ui.warn(msg % (fn, line.rstrip())) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
268 f.close() |