annotate hgsubversion/maps.py @ 846:7ca3d1b08d67

Save filemap into .hg/svn/filemap just like other maps
author Vitaliy Filippov <vitalif@yourcmc.ru>
date Fri, 20 Jan 2012 19:06:32 +0400
parents 5061640fe5bc
children 0de18c5c2e35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
7 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
8 import util
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
9
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
10 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
11 '''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
12 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
13
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
14 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
15 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
16 '''
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
17
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
18 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
19 '''Initialise a new AuthorMap.
322
05cd4a5138bf Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents: 310
diff changeset
20
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
21 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
22
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
23 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
24 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
25 '''
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.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
27 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
28 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
29 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
30 else:
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.defaulthost = ''
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
32 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
33 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
34 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
35
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
36 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
37 ''' 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
38
9aed3bfc92d6 authormap: expand environment variables when evaluating map path
maugustin <maugustin@gmx.net>
parents: 809
diff changeset
39 path = os.path.expandvars(path)
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
40 if not os.path.exists(path):
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
41 return
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
42
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
43 writing = False
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
44 if path != self.path:
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
45 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
46
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
47 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
48 f = open(path, 'r')
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
49 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
50
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
51 line = line_org.split('#')[0]
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
52 if not line.strip():
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
53 continue
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
54
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
55 try:
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
56 src, dst = line.split('=', 1)
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
57 except (IndexError, ValueError):
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
58 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
59 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
60 continue
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
61
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
62 src = src.strip()
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
63 dst = dst.strip()
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
64
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
65 if writing:
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
66 if not src in self:
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
67 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
68 elif dst != self[src]:
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
69 msg = 'overriding author: "%s" to "%s" (%s)\n'
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
70 self.ui.status(msg % (self[src], dst, src))
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
71 writing.write(line_org)
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
72
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
73 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
74
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
75 f.close()
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
76 if writing:
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
77 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
78
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
79 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
80 ''' 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
81 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
82 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
83 if author is None:
c2b9e08ecf10 maps: map a missing author to '(no author)'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 729
diff changeset
84 author = '(no author)'
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
85 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
86 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
87 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
88 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
89 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
90 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
91 else:
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
92 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
93 raise hgutil.Abort(msg % author)
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
94 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
95 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
96
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
97 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
98 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
99 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
100 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
101 else:
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
102 # 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
103 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
104
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
105
728
cfefeefad199 rename TagMap to Tags, to free up the TagMap name
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 725
diff changeset
106 class Tags(dict):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
107 """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
108
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
109 tag names are non-empty strings. Tags are saved in a file
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
110 called tagmap, for backwards compatibility reasons.
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
111 """
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
112 VERSION = 2
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
113
458
974102998578 rebuildmeta: remove any existing tagmap file.
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
114 @classmethod
974102998578 rebuildmeta: remove any existing tagmap file.
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
115 def filepath(cls, repo):
974102998578 rebuildmeta: remove any existing tagmap file.
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
116 return os.path.join(repo.path, 'svn', 'tagmap')
974102998578 rebuildmeta: remove any existing tagmap file.
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
117
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
118 def __init__(self, repo, endrev=None):
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
119 dict.__init__(self)
458
974102998578 rebuildmeta: remove any existing tagmap file.
Augie Fackler <durin42@gmail.com>
parents: 453
diff changeset
120 self.path = self.filepath(repo)
725
c787147fa3b7 fix some style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 647
diff changeset
121 self.endrev = endrev
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
122 if os.path.isfile(self.path):
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
123 self._load(repo)
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
124 else:
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
125 self._write()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
126
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
127 def _load(self, repo):
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
128 f = open(self.path)
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
129 ver = int(f.readline())
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
130 if ver < self.VERSION:
579
21a389e4d8b5 maps: if operation can continue, it should probably not use ui.warn()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 574
diff changeset
131 repo.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
132 f.close()
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
133 os.unlink(self.path)
573
00393e9abff8 svncommands: make repo optional (useful for things like listauthors)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 519
diff changeset
134 svncommands.rebuildmeta(repo.ui, repo, ())
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
135 return
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
136 elif ver != self.VERSION:
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
137 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
138 raise NotImplementedError
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
139 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
140 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
141 revision = int(revision)
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
142 tag = tag[:-1]
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
143 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
144 break
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
145 if not tag:
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
146 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
147 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
148 f.close()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
149
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
150 def _write(self):
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
151 assert self.endrev is None
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
152 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
153 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
154 f.close()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
155
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
156 def update(self, other):
725
c787147fa3b7 fix some style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 647
diff changeset
157 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
158 self[k] = v
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
159
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
160 def __contains__(self, tag):
593
eb16630bceb1 maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents: 579
diff changeset
161 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
162 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
163
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
164 def __getitem__(self, tag):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
165 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
166 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
167 raise KeyError()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
168
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
169 def __setitem__(self, tag, info):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
170 if not tag:
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
171 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
172 ha, revision = info
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
173 f = open(self.path, '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
174 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
175 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
176 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
177
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
178
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
179 class RevMap(dict):
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
180
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
181 VERSION = 1
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
182
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
183 def __init__(self, repo):
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
184 dict.__init__(self)
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
185 self.path = os.path.join(repo.path, 'svn', 'rev_map')
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
186 self.ypath = os.path.join(repo.path, 'svn', 'lastpulled')
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
187 # TODO(durin42): Consider moving management of the youngest
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
188 # file to svnmeta itself rather than leaving it here.
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
189 # must load youngest file first, or else self._load() can
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
190 # clobber the info
829
5061640fe5bc revmap: load/save _youngest using new load_string and save_string API
Yonggang Luo <luoyonggang@gmail.com>
parents: 826
diff changeset
191 _yonngest_str = util.load_string(self.ypath, '0')
5061640fe5bc revmap: load/save _youngest using new load_string and save_string API
Yonggang Luo <luoyonggang@gmail.com>
parents: 826
diff changeset
192 self._youngest = int(_yonngest_str.strip())
647
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
193 self.oldest = 0
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
194 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
195 self._load()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
196 else:
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
197 self._write()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
198
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
199 def _set_youngest(self, rev):
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
200 self._youngest = max(self._youngest, rev)
829
5061640fe5bc revmap: load/save _youngest using new load_string and save_string API
Yonggang Luo <luoyonggang@gmail.com>
parents: 826
diff changeset
201 util.save_string(self.ypath, str(self._youngest) + '\n')
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
202
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
203 def _get_youngest(self):
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
204 return self._youngest
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
205
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
206 youngest = property(_get_youngest, _set_youngest)
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 820
diff changeset
207
415
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
208 def hashes(self):
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
209 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
210
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
211 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
212 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
213 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
214
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
215 def _load(self):
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
216 f = open(self.path)
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
217 ver = int(f.readline())
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
218 if ver != self.VERSION:
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
219 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
220 raise NotImplementedError
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
221 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
222 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
223 if branch == '\n':
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
224 branch = None
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
225 else:
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
226 branch = branch[:-1]
415
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
227 revnum = int(revnum)
647
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
228 if revnum > self.youngest or not self.youngest:
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
229 self.youngest = revnum
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
230 if revnum < self.oldest or not self.oldest:
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
231 self.oldest = 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
232 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
233 f.close()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
234
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
235 def _write(self):
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
236 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
237 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
238 f.close()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
239
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
240 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
241 revnum, branch = key
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
242 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
243 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
244 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
245 f.close()
647
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
246 if revnum > self.youngest or not self.youngest:
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
247 self.youngest = revnum
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
248 if revnum < self.oldest or not self.oldest:
3ff8666b1479 maps: rename revmap.seen to revmap.youngest; add revmap.oldest.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 636
diff changeset
249 self.oldest = 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
250 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
251
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
252
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
253 class FileMap(object):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
254
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
255 VERSION = 1
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
256
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
257 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
258 '''Initialise a new FileMap.
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
259
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
260 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
261
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
262 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
263 typically .hg/svn/filemap.
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
264 '''
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
265 self.ui = ui
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
266 self.path = path
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
267 self.include = {}
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
268 self.exclude = {}
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
269 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
270 self._load()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
271 else:
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
272 self._write()
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
273
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
274 def _rpairs(self, name):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
275 yield '.', name
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
276 e = len(name)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
277 while e != -1:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
278 yield name[:e], name[e+1:]
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
279 e = name.rfind('/', 0, e)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
280
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
281 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
282 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
283 for pre, _suf in self._rpairs(path):
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
284 if pre not in m:
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
285 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
286 return m[pre]
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
287 return None
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
288
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
289 def __contains__(self, path):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
290 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
291 inc = self.check('include', path)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
292 else:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
293 inc = path
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
294 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
295 exc = self.check('exclude', path)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
296 else:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
297 exc = None
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
298 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
299 return False
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
300 return True
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
301
822
033b86e0f56d stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents: 821
diff changeset
302 # 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
303 def __len__(self):
033b86e0f56d stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents: 821
diff changeset
304 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
305
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
306 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
307 mapping = getattr(self, m)
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
308 if path in mapping:
593
eb16630bceb1 maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents: 579
diff changeset
309 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
310 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
311 return
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
312 bits = m.strip('e'), path
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
313 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
314 mapping[path] = path
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
315 if fn != self.path:
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
316 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
317 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
318 f.close()
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
319
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
320 def load(self, fn):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
321 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
322 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
323 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
324 f.close()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
325
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
326 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
327 for line in f:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
328 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
329 continue
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
330 try:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
331 cmd, path = line.split(' ', 1)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
332 cmd = cmd.strip()
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
333 path = path.strip()
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
334 if cmd in ('include', 'exclude'):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
335 self.add(fn, cmd, path)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
336 continue
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
337 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
338 except IndexError:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
339 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
340 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
341
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
342 def _load(self):
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
343 self.ui.note('reading in-repo file map from %s\n' % self.path)
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
344 f = open(self.path)
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
345 ver = int(f.readline())
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
346 if ver != self.VERSION:
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
347 print 'filemap too new -- please upgrade'
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
348 raise NotImplementedError
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
349 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
350 f.close()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
351
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
352 def _write(self):
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, 'w')
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
354 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
355 f.close()
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
356
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
357 class BranchMap(dict):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
358 '''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
359
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
360 oldname = newname
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
361 other = default
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
362
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
363 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
364 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
365 '''
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
366
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
367 def __init__(self, ui, path):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
368 self.ui = ui
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
369 self.path = path
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
370 self.super = super(BranchMap, self)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
371 self.super.__init__()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
372 self.load(path)
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 def load(self, path):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
375 '''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
376 if not os.path.exists(path):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
377 return
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
378
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
379 writing = False
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
380 if path != self.path:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
381 writing = open(self.path, 'a')
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
382
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
383 self.ui.note('reading branchmap from %s\n' % path)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
384 f = open(path, 'r')
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
385 for number, line in enumerate(f):
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 if writing:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
388 writing.write(line)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
389
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
390 line = line.split('#')[0]
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
391 if not line.strip():
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
392 continue
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
393
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
394 try:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
395 src, dst = line.split('=', 1)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
396 except (IndexError, ValueError):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
397 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
398 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
399 continue
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
400
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
401 src = src.strip()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
402 dst = dst.strip()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
403 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
404
d4f433ee709a branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 624
diff changeset
405 if not dst:
d4f433ee709a branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 624
diff changeset
406 # prevent people from assuming such lines are valid
d4f433ee709a branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 624
diff changeset
407 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
408 '(line %i in branch map %s)'
d4f433ee709a branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 624
diff changeset
409 % (number, path))
d4f433ee709a branchmap: reject empty mappings
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 624
diff changeset
410 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
411 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
412 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
413 self[src] = dst
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
414
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
415 f.close()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
416 if writing:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
417 writing.close()
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
418
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
419 class TagMap(dict):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
420 '''Facility for controlled renaming of tags. Example:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
421
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
422 oldname = newname
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
423 other =
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
424
809
ab372e38fb6c maps: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents: 742
diff changeset
425 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
426 the other tag will not be reflected in the hg repository.
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
427 '''
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
428
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
429 def __init__(self, ui, path):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
430 self.ui = ui
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
431 self.path = path
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
432 self.super = super(TagMap, self)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
433 self.super.__init__()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
434 self.load(path)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
435
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
436 def load(self, path):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
437 '''Load mappings from a file at the specified path.'''
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
438 if not os.path.exists(path):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
439 return
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
440
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
441 writing = False
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
442 if path != self.path:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
443 writing = open(self.path, 'a')
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
444
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
445 self.ui.note('reading tag renames from %s\n' % path)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
446 f = open(path, 'r')
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
447 for number, line in enumerate(f):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
448
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
449 if writing:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
450 writing.write(line)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
451
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
452 line = line.split('#')[0]
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
453 if not line.strip():
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
454 continue
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
455
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
456 try:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
457 src, dst = line.split('=', 1)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
458 except (IndexError, ValueError):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
459 msg = 'ignoring line %i in tag renames %s: %s\n'
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
460 self.ui.status(msg % (number, path, line.rstrip()))
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
461 continue
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
462
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
463 src = src.strip()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
464 dst = dst.strip()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
465 self.ui.debug('adding tag %s to tag renames\n' % src)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
466
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
467 if src in self and dst != self[src]:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
468 msg = 'overriding tag rename: "%s" to "%s" (%s)\n'
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
469 self.ui.status(msg % (self[src], dst, src))
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
470 self[src] = dst
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
471
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
472 f.close()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
473 if writing:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
474 writing.close()