annotate hgsubversion/maps.py @ 1385:9139d9295a36

maps: make author map inherit from base map
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:59 -0500
parents 2d1d05e6e46c
children 8bd40916106f
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
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
3 import errno
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
4 import os
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
5 from mercurial import util as hgutil
1253
c54214bb6c4e maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents: 1252
diff changeset
6 from mercurial.node import bin, hex, nullid
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
7
1374
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
8 import subprocess
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
9 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
10 import util
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
11
1383
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
12 class BaseMap(dict):
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
13 '''A base class for the different type of mappings: author, branch, and
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
14 tags.'''
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
15 def __init__(self, meta):
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
16 self.meta = meta
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
17 super(BaseMap, self).__init__()
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
18
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
19 # trickery: all subclasses have the same name as their file and config
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
20 # names, e.g. AuthorMap is meta.authormap_file for the filename and
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
21 # 'authormap' for the config option
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
22 self.mapname = self.__class__.__name__.lower()
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
23 self.mapfilename = self.mapname + '_file'
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
24 self.load(self.meta.__getattribute__(self.mapfilename))
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
25
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
26 # append mappings specified from the commandline
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
27 clmap = util.configpath(self.meta.ui, self.mapname)
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
28 if clmap:
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
29 self.load(clmap)
73c76f99ca08 maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents: 1382
diff changeset
30
1384
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
31 def load(self, path):
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
32 '''Load mappings from a file at the specified path.'''
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
33 path = os.path.expandvars(path)
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
34 if not os.path.exists(path):
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
35 return
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
36
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
37 writing = False
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
38 mapfile = self.meta.__getattribute__(self.mapfilename)
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
39 if path != mapfile:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
40 writing = open(mapfile, 'a')
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
41
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
42 self.meta.ui.debug('reading %s from %s\n' % (self.mapname , path))
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
43 f = open(path, 'r')
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
44 for number, line in enumerate(f):
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
45
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
46 if writing:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
47 writing.write(line)
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
48
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
49 line = line.split('#')[0]
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
50 if not line.strip():
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
51 continue
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
52
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
53 try:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
54 src, dst = line.split('=', 1)
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
55 except (IndexError, ValueError):
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
56 msg = 'ignoring line %i in %s %s: %s\n'
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
57 self.meta.ui.status(msg % (number, self.mapname, path,
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
58 line.rstrip()))
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
59 continue
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
60
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
61 src = src.strip()
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
62 dst = dst.strip()
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
63
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
64 if src not in self:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
65 self.meta.ui.debug('adding %s to %s\n' % (src, self.mapname))
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
66 elif dst != self[src]:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
67 msg = 'overriding %s: "%s" to "%s" (%s)\n'
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
68 self.meta.ui.status(msg % (self.mapname, self[src], dst, src))
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
69 self[src] = dst
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
70
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
71 f.close()
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
72 if writing:
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
73 writing.close()
2d1d05e6e46c maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1383
diff changeset
74
1385
9139d9295a36 maps: make author map inherit from base map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1384
diff changeset
75 class AuthorMap(BaseMap):
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
76 '''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
77 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
78
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
79 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
80 attempting to obtain an unknown author will fail with an Abort.
1188
38dd8721fb0d maps: remove trailing whitespace
Sean Farley <sean.michael.farley@gmail.com>
parents: 1187
diff changeset
81
1097
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
82 If the 'hgsubversion.caseignoreauthors' configuration option is set to true,
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
83 the userid from Subversion is always compared lowercase.
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
84 '''
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
85
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
86 def __init__(self, meta):
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 '''Initialise a new AuthorMap.
322
05cd4a5138bf Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents: 310
diff changeset
88
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
89 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
90
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 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
92 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
93 '''
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
94 self.meta = meta
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
95 self.defaulthost = ''
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
96 if meta.defaulthost:
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
97 self.defaulthost = '@%s' % meta.defaulthost.lstrip('@')
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
98
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
99 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
100 self.super.__init__()
1332
ecce8aef4b21 svnmeta: rename authors_file to authormap_file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1294
diff changeset
101 self.load(self.meta.authormap_file)
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
102
1193
a55339d35066 maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1188
diff changeset
103 # append authors specified from the commandline
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
104 clmap = util.configpath(self.meta.ui, 'authormap')
1193
a55339d35066 maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1188
diff changeset
105 if clmap:
a55339d35066 maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1188
diff changeset
106 self.load(clmap)
a55339d35066 maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1188
diff changeset
107
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
108 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
109 ''' 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
110
9aed3bfc92d6 authormap: expand environment variables when evaluating map path
maugustin <maugustin@gmx.net>
parents: 809
diff changeset
111 path = os.path.expandvars(path)
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
112 if not os.path.exists(path):
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
113 return
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
114
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
115 writing = False
1332
ecce8aef4b21 svnmeta: rename authors_file to authormap_file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1294
diff changeset
116 if path != self.meta.authormap_file:
ecce8aef4b21 svnmeta: rename authors_file to authormap_file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1294
diff changeset
117 writing = open(self.meta.authormap_file, 'a')
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
118
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
119 self.meta.ui.debug('reading authormap from %s\n' % path)
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
120 f = open(path, 'r')
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
121 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
122
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
123 line = line_org.split('#')[0]
359
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
124 if not line.strip():
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
125 continue
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
126
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
127 try:
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
128 src, dst = line.split('=', 1)
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
129 except (IndexError, ValueError):
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
130 msg = 'ignoring line %i in author map %s: %s\n'
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
131 self.meta.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
132 continue
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
133
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
134 src = src.strip()
e74321f6f8a1 Author maps: code/message style (prevent line continuations).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 358
diff changeset
135 dst = dst.strip()
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
136
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
137 if writing:
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
138 if not src in self:
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
139 self.meta.ui.debug('adding author %s to author map\n' % src)
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
140 elif dst != self[src]:
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
141 msg = 'overriding author: "%s" to "%s" (%s)\n'
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
142 self.meta.ui.status(msg % (self[src], dst, src))
820
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
143 writing.write(line_org)
09f7c1c09207 authormap: only append new or changed authors
maugustin <maugustin@gmx.net>
parents: 818
diff changeset
144
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
145 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
146
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
147 f.close()
430
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
148 if writing:
2851b81c65ce maps: make sure AuthorMaps don't overwrite themselves, fix overriding
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 415
diff changeset
149 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
150
1379
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
151 def __setitem__(self, key, value):
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
152 '''Similar to dict.__setitem__, except we check caseignoreauthors to
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
153 use lowercase string or not
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
154 '''
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
155 if self.meta.caseignoreauthors:
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
156 key = key.lower()
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
157 super(AuthorMap, self).__setitem__(key, value)
367e65989b41 maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1375
diff changeset
158
1380
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
159 def __contains__(self, key):
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
160 '''Similar to dict.__contains__, except we check caseignoreauthors to
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
161 use lowercase string or not
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
162 '''
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
163 if self.meta.caseignoreauthors:
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
164 key = key.lower()
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
165 return super(AuthorMap, self).__contains__(key)
332ad9ea579b maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents: 1379
diff changeset
166
307
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
167 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
168 ''' 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
169 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
170 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
171 if author is None:
c2b9e08ecf10 maps: map a missing author to '(no author)'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 729
diff changeset
172 author = '(no author)'
1097
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
173
1196
878372849175 maps: use meta.caseignoreauthors intead of accessing ui directly
Sean Farley <sean.michael.farley@gmail.com>
parents: 1195
diff changeset
174 search_author = author
878372849175 maps: use meta.caseignoreauthors intead of accessing ui directly
Sean Farley <sean.michael.farley@gmail.com>
parents: 1195
diff changeset
175 if self.meta.caseignoreauthors:
1097
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
176 search_author = author.lower()
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
177
1374
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
178 result = None
1097
e015cd34168d authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents: 976
diff changeset
179 if search_author in self:
1382
d996850ac4e8 maps: call super directly instead of self.super
Sean Farley <sean.michael.farley@gmail.com>
parents: 1381
diff changeset
180 result = super(AuthorMap, self).__getitem__(search_author)
1374
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
181 elif self.meta.mapauthorscmd:
1375
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
182 cmd = self.meta.mapauthorscmd % author
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
183 process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
184 output, err = process.communicate()
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
185 retcode = process.poll()
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
186 if retcode:
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
187 msg = 'map author command "%s" exited with error'
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
188 raise hgutil.Abort(msg % cmd)
abc87a62ff51 maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents: 1374
diff changeset
189 self[author] = result = output.strip()
1374
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
190 if not result:
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
191 if self.meta.defaultauthors:
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
192 self[author] = result = '%s%s' % (author, self.defaulthost)
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
193 msg = 'substituting author "%s" for default "%s"\n'
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
194 self.meta.ui.debug(msg % (author, result))
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
195 else:
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
196 msg = 'author %s has no entry in the author map!'
a17d8874a099 Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents: 1356
diff changeset
197 raise hgutil.Abort(msg % author)
1194
49791c40a8a5 maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1193
diff changeset
198 self.meta.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
199 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
200
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
201 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
202 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
203 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
204 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
205 else:
1d48d9a34c19 Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff changeset
206 # 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
207 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
208
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
209
728
cfefeefad199 rename TagMap to Tags, to free up the TagMap name
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 725
diff changeset
210 class Tags(dict):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
211 """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
212
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
213 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
214 called tagmap, for backwards compatibility reasons.
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
215 """
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
216 VERSION = 2
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
217
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
218 def __init__(self, meta, endrev=None):
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
219 dict.__init__(self)
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
220 self.meta = meta
725
c787147fa3b7 fix some style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 647
diff changeset
221 self.endrev = endrev
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
222 if os.path.isfile(self.meta.tagfile):
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
223 self._load()
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
224 else:
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
225 self._write()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
226
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
227 def _load(self):
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
228 f = open(self.meta.tagfile)
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
229 ver = int(f.readline())
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
230 if ver < self.VERSION:
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
231 self.meta.ui.status('tag map outdated, running rebuildmeta...\n')
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
232 f.close()
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
233 os.unlink(self.meta.tagfile)
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
234 svncommands.rebuildmeta(self.meta.ui, self.meta.repo, ())
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
235 return
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
236 elif ver != self.VERSION:
891
83cc6e9e8425 kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 889
diff changeset
237 raise hgutil.Abort('tagmap too new -- please upgrade')
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
238 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
239 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
240 revision = int(revision)
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
241 tag = tag[:-1]
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
242 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
243 break
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
244 if not tag:
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
245 continue
1253
c54214bb6c4e maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents: 1252
diff changeset
246 dict.__setitem__(self, tag, bin(ha))
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
247 f.close()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
248
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
249 def _write(self):
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
250 assert self.endrev is None
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
251 f = open(self.meta.tagfile, 'w')
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
252 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
253 f.close()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
254
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
255 def update(self, other):
725
c787147fa3b7 fix some style nits
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 647
diff changeset
256 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
257 self[k] = v
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
258
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
259 def __contains__(self, tag):
593
eb16630bceb1 maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents: 579
diff changeset
260 return (tag and dict.__contains__(self, tag)
1253
c54214bb6c4e maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents: 1252
diff changeset
261 and dict.__getitem__(self, tag) != nullid)
448
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
262
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
263 def __getitem__(self, tag):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
264 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
265 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
266 raise KeyError()
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
267
453
bb612e625be6 tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents: 448
diff changeset
268 def __setitem__(self, tag, info):
519
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
269 if not tag:
247110c633f7 maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents: 460
diff changeset
270 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
271 ha, revision = info
1187
30b2139c3931 maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1186
diff changeset
272 f = open(self.meta.tagfile, 'a')
1253
c54214bb6c4e maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents: 1252
diff changeset
273 f.write('%s %s %s\n' % (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
274 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
275 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
276
fbc7cf4fd701 tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents: 430
diff changeset
277
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
278 class RevMap(dict):
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
279
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
280 VERSION = 1
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
281
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
282 def __init__(self, meta):
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
283 dict.__init__(self)
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
284 self.meta = meta
1294
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
285 self._hashes = None
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
286
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
287 if os.path.isfile(self.meta.revmap_file):
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
288 self._load()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
289 else:
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
290 self._write()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
291
415
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
292 def hashes(self):
1294
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
293 if self._hashes is None:
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
294 self._hashes = dict((v, k) for (k, v) in self.iteritems())
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
295 return self._hashes
415
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
296
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
297 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
298 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
299 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
300
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
301 @classmethod
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1144
diff changeset
302 def readmapfile(cls, path, missingok=True):
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
303 try:
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1144
diff changeset
304 f = open(path)
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
305 except IOError, err:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
306 if not missingok or err.errno != errno.ENOENT:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
307 raise
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
308 return iter([])
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
309 ver = int(f.readline())
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
310 if ver != cls.VERSION:
891
83cc6e9e8425 kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 889
diff changeset
311 raise hgutil.Abort('revmap too new -- please upgrade')
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
312 return f
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
313
1251
46cec117dda2 maps.RevMap: disable GC while loading the revmap
Siddharth Agarwal <sid0@fb.com>
parents: 1217
diff changeset
314 @util.gcdisable
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 847
diff changeset
315 def _load(self):
1252
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
316 lastpulled = self.meta.lastpulled
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
317 firstpulled = self.meta.firstpulled
1254
d07ccad28b1a maps.RevMap: avoid O(revs) property lookups on dict
Siddharth Agarwal <sid0@fb.com>
parents: 1253
diff changeset
318 setitem = dict.__setitem__
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
319 for l in self.readmapfile(self.meta.revmap_file):
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
320 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
321 if branch == '\n':
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
322 branch = None
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
323 else:
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
324 branch = branch[:-1]
415
b17b2969861c svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 409
diff changeset
325 revnum = int(revnum)
1252
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
326 if revnum > lastpulled or not lastpulled:
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
327 lastpulled = revnum
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
328 if revnum < firstpulled or not firstpulled:
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
329 firstpulled = revnum
1254
d07ccad28b1a maps.RevMap: avoid O(revs) property lookups on dict
Siddharth Agarwal <sid0@fb.com>
parents: 1253
diff changeset
330 setitem(self, (revnum, branch), bin(ha))
1252
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
331 self.meta.lastpulled = lastpulled
a321afbc3479 maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents: 1251
diff changeset
332 self.meta.firstpulled = firstpulled
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
333
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
334 def _write(self):
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
335 f = open(self.meta.revmap_file, 'w')
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
336 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
337 f.close()
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
338
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
339 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
340 revnum, branch = key
1183
09b20039192c maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1182
diff changeset
341 f = open(self.meta.revmap_file, 'a')
408
f137231f9d30 extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 360
diff changeset
342 b = branch or ''
1253
c54214bb6c4e maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents: 1252
diff changeset
343 f.write(str(revnum) + ' ' + 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
344 f.close()
1184
43384d2782dc svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents: 1183
diff changeset
345 if revnum > self.meta.lastpulled or not self.meta.lastpulled:
43384d2782dc svnmeta: move revmap.youngest to meta.lastpulled
Sean Farley <sean.michael.farley@gmail.com>
parents: 1183
diff changeset
346 self.meta.lastpulled = revnum
1186
f9650d24464a svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents: 1184
diff changeset
347 if revnum < self.meta.firstpulled or not self.meta.firstpulled:
f9650d24464a svnmeta: move revmap.oldest to meta.firstpulled
Sean Farley <sean.michael.farley@gmail.com>
parents: 1184
diff changeset
348 self.meta.firstpulled = revnum
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
349 dict.__setitem__(self, (revnum, branch), ha)
1294
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
350 if self._hashes is not None:
9a722b5246df maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents: 1254
diff changeset
351 self._hashes[ha] = (revnum, branch)
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
352
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
353
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
354 class FileMap(object):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
355
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
356 VERSION = 1
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
357
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
358 def __init__(self, meta):
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
359 '''Initialise a new FileMap.
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
360
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
361 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
362
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
363 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
364 typically .hg/svn/filemap.
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
365 '''
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
366 self.meta = meta
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
367 self.include = {}
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
368 self.exclude = {}
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
369 if os.path.isfile(self.meta.filemap_file):
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
370 self._load()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
371 else:
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
372 self._write()
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
373
1214
2c793092862b maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1213
diff changeset
374 # append file mapping specified from the commandline
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
375 clmap = util.configpath(self.meta.ui, 'filemap')
1214
2c793092862b maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1213
diff changeset
376 if clmap:
2c793092862b maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1213
diff changeset
377 self.load(clmap)
2c793092862b maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1213
diff changeset
378
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
379 def _rpairs(self, name):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
380 e = len(name)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
381 while e != -1:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
382 yield name[:e], name[e+1:]
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
383 e = name.rfind('/', 0, e)
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
384 yield '.', name
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
385
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
386 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
387 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
388 for pre, _suf in self._rpairs(path):
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
389 if pre in m:
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
390 return m[pre]
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
391 return -1
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
392
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
393 def __contains__(self, path):
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
394 if not len(path):
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
395 return True
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
396 if len(self.include):
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
397 inc = self.check('include', path)
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
398 elif not len(self.exclude):
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
399 return True
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
400 else:
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
401 inc = 0
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
402 if len(self.exclude):
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
403 exc = self.check('exclude', path)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
404 else:
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
405 exc = -1
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
406 # respect rule order: newer rules override older
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
407 return inc > exc
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
408
822
033b86e0f56d stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents: 821
diff changeset
409 # 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
410 def __len__(self):
033b86e0f56d stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents: 821
diff changeset
411 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
412
826
8794302f3614 maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents: 822
diff changeset
413 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
414 mapping = getattr(self, m)
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
415 if path in mapping:
593
eb16630bceb1 maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents: 579
diff changeset
416 msg = 'duplicate %s entry in %s: "%s"\n'
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
417 self.meta.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
418 return
956
24fbba02cb8f maps: fix filemap loading --verbose message
Patrick Mezard <patrick@mezard.eu>
parents: 891
diff changeset
419 bits = m.rstrip('e'), path
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
420 self.meta.ui.debug('%sing %s\n' % bits)
847
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
421 # respect rule order
0de18c5c2e35 Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 846
diff changeset
422 mapping[path] = len(self)
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
423 if fn != self.meta.filemap_file:
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
424 f = open(self.meta.filemap_file, 'a')
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
425 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
426 f.close()
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
427
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
428 def load(self, fn):
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
429 self.meta.ui.debug('reading file map from %s\n' % fn)
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
430 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
431 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
432 f.close()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
433
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
434 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
435 for line in f:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
436 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
437 continue
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
438 try:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
439 cmd, path = line.split(' ', 1)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
440 cmd = cmd.strip()
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
441 path = path.strip()
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
442 if cmd in ('include', 'exclude'):
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
443 self.add(fn, cmd, path)
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
444 continue
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
445 self.meta.ui.warn('unknown filemap command %s\n' % cmd)
409
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
446 except IndexError:
d4615986e1db extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
447 msg = 'ignoring bad line in filemap %s: %s\n'
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
448 self.meta.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
449
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
450 def _load(self):
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
451 self.meta.ui.debug('reading in-repo file map from %s\n' % self.meta.filemap_file)
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
452 f = open(self.meta.filemap_file)
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
453 ver = int(f.readline())
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
454 if ver != self.VERSION:
891
83cc6e9e8425 kill all 'print' statements in the extension proper
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 889
diff changeset
455 raise hgutil.Abort('filemap too new -- please upgrade')
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
456 self.load_fd(f, self.meta.filemap_file)
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
457 f.close()
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
458
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
459 def _write(self):
1217
a10a4fc69364 maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1216
diff changeset
460 f = open(self.meta.filemap_file, 'w')
846
7ca3d1b08d67 Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents: 829
diff changeset
461 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
462 f.close()
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
463
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
464 class BranchMap(dict):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
465 '''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
466
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
467 oldname = newname
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
468 other = default
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
469
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
470 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
471 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
472 '''
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
473
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
474 def __init__(self, meta):
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
475 self.meta = meta
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
476 self.super = super(BranchMap, self)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
477 self.super.__init__()
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
478 self.load(self.meta.branchmap_file)
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
479
1211
56d6e0273733 maps: load commandline branchmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1210
diff changeset
480 # append branch mapping specified from the commandline
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
481 clmap = util.configpath(self.meta.ui, 'branchmap')
1211
56d6e0273733 maps: load commandline branchmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1210
diff changeset
482 if clmap:
56d6e0273733 maps: load commandline branchmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1210
diff changeset
483 self.load(clmap)
56d6e0273733 maps: load commandline branchmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1210
diff changeset
484
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
485 def load(self, path):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
486 '''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
487 if not os.path.exists(path):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
488 return
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
489
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
490 writing = False
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
491 if path != self.meta.branchmap_file:
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
492 writing = open(self.meta.branchmap_file, 'a')
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
493
1216
572417ad0313 svnmeta: turn filemap into a lazy property
Sean Farley <sean.michael.farley@gmail.com>
parents: 1214
diff changeset
494 self.meta.ui.debug('reading branchmap from %s\n' % path)
574
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
495 f = open(path, 'r')
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
496 for number, line in enumerate(f):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
497
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
498 if writing:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
499 writing.write(line)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
500
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
501 line = line.split('#')[0]
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
502 if not line.strip():
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
503 continue
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
504
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
505 try:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
506 src, dst = line.split('=', 1)
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
507 except (IndexError, ValueError):
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
508 msg = 'ignoring line %i in branch map %s: %s\n'
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
509 self.meta.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
510 continue
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
511
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
512 src = src.strip()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
513 dst = dst.strip()
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
514 self.meta.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
515
1356
57d65269d30c maps: allow an empty map to not convert specific branches
Sean Farley <sean@farley.io>
parents: 1332
diff changeset
516 if dst and 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
517 msg = 'overriding branch: "%s" to "%s" (%s)\n'
1213
295d2f0cc275 maps: change branchmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1211
diff changeset
518 self.meta.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
519 self[src] = dst
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
520
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
521 f.close()
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
522 if writing:
8e025a6f0db4 add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 573
diff changeset
523 writing.close()
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
524
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
525 class TagMap(dict):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
526 '''Facility for controlled renaming of tags. Example:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
527
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
528 oldname = newname
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
529 other =
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
530
809
ab372e38fb6c maps: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents: 742
diff changeset
531 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
532 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
533 '''
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
534
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
535 def __init__(self, meta):
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
536 self.meta = meta
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
537 self.super = super(TagMap, self)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
538 self.super.__init__()
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
539 self.load(self.meta.tagmap_file)
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
540
1208
54d42e59b29c maps: load commandline tagmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1196
diff changeset
541 # append tag mapping specified from the commandline
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
542 clmap = util.configpath(self.meta.ui, 'tagmap')
1208
54d42e59b29c maps: load commandline tagmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1196
diff changeset
543 if clmap:
54d42e59b29c maps: load commandline tagmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1196
diff changeset
544 self.load(clmap)
54d42e59b29c maps: load commandline tagmap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents: 1196
diff changeset
545
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
546 def load(self, path):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
547 '''Load mappings from a file at the specified path.'''
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
548 if not os.path.exists(path):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
549 return
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
550
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
551 writing = False
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
552 if path != self.meta.tagmap_file:
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
553 writing = open(self.meta.tagmap_file, 'a')
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
554
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
555 self.meta.ui.debug('reading tag renames from %s\n' % path)
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
556 f = open(path, 'r')
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
557 for number, line in enumerate(f):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
558
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
559 if writing:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
560 writing.write(line)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
561
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
562 line = line.split('#')[0]
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
563 if not line.strip():
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
564 continue
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
565
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
566 try:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
567 src, dst = line.split('=', 1)
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
568 except (IndexError, ValueError):
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
569 msg = 'ignoring line %i in tag renames %s: %s\n'
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
570 self.meta.ui.status(msg % (number, path, line.rstrip()))
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
571 continue
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
572
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
573 src = src.strip()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
574 dst = dst.strip()
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
575 self.meta.ui.debug('adding tag %s to tag renames\n' % src)
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
576
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
577 if src in self and dst != self[src]:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
578 msg = 'overriding tag rename: "%s" to "%s" (%s)\n'
1210
a0c6dbd9afbb maps: change tagmap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1208
diff changeset
579 self.meta.ui.status(msg % (self[src], dst, src))
729
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
580 self[src] = dst
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
581
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
582 f.close()
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
583 if writing:
467b95348e6a implement tag renames
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 728
diff changeset
584 writing.close()