Mercurial > hgsubversion
annotate hgsubversion/maps.py @ 1440:4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
I'm not really sure I like this magic anymore, but we can at least
contain it to make the next patch cleaner.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 06 Jun 2016 00:42:07 -0400 |
parents | ab15749252b0 |
children | e79ff1a85938 |
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 |
1394
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
5 import re |
1439
ab15749252b0
TagMap: stop automagically running 'hg svn rebuildmeta'
Augie Fackler <raf@durin42.com>
parents:
1438
diff
changeset
|
6 from mercurial import error |
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 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
|
8 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
|
9 |
1374
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
10 import subprocess |
829
5061640fe5bc
revmap: load/save _youngest using new load_string and save_string API
Yonggang Luo <luoyonggang@gmail.com>
parents:
826
diff
changeset
|
11 import util |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
12 |
1383
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
13 class BaseMap(dict): |
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
14 '''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
|
15 tags.''' |
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
16 def __init__(self, meta): |
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
17 super(BaseMap, self).__init__() |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
18 self._ui = meta.ui |
1383
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
19 |
1394
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
20 self._commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*') |
1401
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
21 self.syntaxes = ('re', 'glob') |
1394
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
22 |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
23 self._filepath = meta.__getattribute__(self.defaultfilenameattr()) |
1431
066c08918060
BaseMap: record filename on self._filename
Augie Fackler <raf@durin42.com>
parents:
1430
diff
changeset
|
24 self.load(self._filepath) |
1383
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
25 |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
26 # Append mappings specified from the commandline. A little |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
27 # magic here: our name in the config mapping is the same as |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
28 # the class name lowercased. |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
29 clmap = util.configpath(self._ui, self.mapname()) |
1383
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
30 if clmap: |
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
31 self.load(clmap) |
73c76f99ca08
maps: add a basemap class
Sean Farley <sean.michael.farley@gmail.com>
parents:
1382
diff
changeset
|
32 |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
33 @classmethod |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
34 def mapname(cls): |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
35 return cls.__name__.lower() |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
36 |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
37 @classmethod |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
38 def defaultfilenameattr(cls): |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
39 # trickery: all subclasses have the same name as their file and config |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
40 # names, e.g. AuthorMap is meta.authormap_file for the filename and |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
41 # 'authormap' for the config option |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
42 return cls.mapname() + '_file' |
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
43 |
1395
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
44 def _findkey(self, key): |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
45 '''Takes a string and finds the first corresponding key that matches |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
46 via regex''' |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
47 if not key: |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
48 return None |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
49 |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
50 # compile a new regex key if we're given a string; can't use |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
51 # hgutil.compilere since we need regex.sub |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
52 k = key |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
53 if isinstance(key, str): |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
54 k = re.compile(re.escape(key)) |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
55 |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
56 # preference goes to matching the exact pattern, i.e. 'foo' should |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
57 # first match 'foo' before trying regexes |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
58 for regex in self: |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
59 if regex.pattern == k.pattern: |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
60 return regex |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
61 |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
62 # if key isn't a string, then we are done; nothing matches |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
63 if not isinstance(key, str): |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
64 return None |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
65 |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
66 # now we test the regex; the above loop will be faster and is |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
67 # equivalent to not having regexes (i.e. just doing string compares) |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
68 for regex in self: |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
69 if regex.search(key): |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
70 return regex |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
71 return None |
53184be1b1fd
maps: add _findkey method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1394
diff
changeset
|
72 |
1396
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
73 def get(self, key, default=None): |
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
74 '''Similar to dict.get, except we use our own matcher, _findkey.''' |
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
75 if self._findkey(key): |
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
76 return self[key] |
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
77 return default |
77594c88d91f
maps: add custom get method
Sean Farley <sean.michael.farley@gmail.com>
parents:
1395
diff
changeset
|
78 |
1397
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
79 def __getitem__(self, key): |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
80 '''Similar to dict.get, except we use our own matcher, _findkey. If the key is |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
81 a string, then we can use our regex matching to map its value. |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
82 ''' |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
83 k = self._findkey(key) |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
84 val = super(BaseMap, self).__getitem__(k) |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
85 |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
86 # if key is a string then we can transform it using our regex, else we |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
87 # don't have enough information, so we just return the val |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
88 if isinstance(key, str): |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
89 val = k.sub(val, key) |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
90 |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
91 return val |
304fdb9810a6
maps: add custom __getitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1396
diff
changeset
|
92 |
1398
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
93 def __setitem__(self, key, value): |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
94 '''Similar to dict.__setitem__, except we compile the string into a regex, if |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
95 need be. |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
96 ''' |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
97 # try to find the regex already in the map |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
98 k = self._findkey(key) |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
99 # if we found one, then use it |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
100 if k: |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
101 key = k |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
102 # else make a new regex |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
103 if isinstance(key, str): |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
104 key = re.compile(re.escape(key)) |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
105 super(BaseMap, self).__setitem__(key, value) |
75745298d99d
maps: add custom __setitem__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1397
diff
changeset
|
106 |
1399
3b96075bffa7
maps: add custom __contains__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1398
diff
changeset
|
107 def __contains__(self, key): |
3b96075bffa7
maps: add custom __contains__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1398
diff
changeset
|
108 '''Similar to dict.get, except we use our own matcher, _findkey.''' |
3b96075bffa7
maps: add custom __contains__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1398
diff
changeset
|
109 return self._findkey(key) is not None |
3b96075bffa7
maps: add custom __contains__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1398
diff
changeset
|
110 |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
111 def load(self, path): |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
112 '''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
|
113 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
|
114 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
|
115 return |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
116 |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
117 writing = False |
1431
066c08918060
BaseMap: record filename on self._filename
Augie Fackler <raf@durin42.com>
parents:
1430
diff
changeset
|
118 mapfile = self._filepath |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
119 if path != mapfile: |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
120 writing = open(mapfile, 'a') |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
121 |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
122 self._ui.debug('reading %s from %s\n' % (self.mapname() , path)) |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
123 f = open(path, 'r') |
1401
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
124 syntax = '' |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
125 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
|
126 |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
127 if writing: |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
128 writing.write(line) |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
129 |
1394
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
130 # strip out comments |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
131 if "#" in line: |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
132 # remove comments prefixed by an even number of escapes |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
133 line = self._commentre.sub(r'\1', line) |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
134 # fixup properly escaped comments that survived the above |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
135 line = line.replace("\\#", "#") |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
136 line = line.rstrip() |
c4055968f030
maps: use regex for better comment handling
Sean Farley <sean.michael.farley@gmail.com>
parents:
1393
diff
changeset
|
137 if not line: |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
138 continue |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
139 |
1401
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
140 if line.startswith('syntax:'): |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
141 s = line[7:].strip() |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
142 syntax = '' |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
143 if s in self.syntaxes: |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
144 syntax = s |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
145 continue |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
146 pat = syntax |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
147 for s in self.syntaxes: |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
148 if line.startswith(s + ':'): |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
149 pat = s |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
150 line = line[len(s) + 1:] |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
151 break |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
152 |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
153 # split on the first '=' |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
154 try: |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
155 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
|
156 except (IndexError, ValueError): |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
157 msg = 'ignoring line %i in %s %s: %s\n' |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
158 self._ui.status(msg % (number, self.mapname(), path, |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
159 line.rstrip())) |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
160 continue |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
161 |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
162 src = src.strip() |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
163 dst = dst.strip() |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
164 |
1401
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
165 if pat != 're': |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
166 src = re.escape(src) |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
167 if pat == 'glob': |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
168 src = src.replace('\\*', '.*') |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
169 src = re.compile(src) |
70cb6ba038fa
maps: add ability to parse a regex or glob
Sean Farley <sean.michael.farley@gmail.com>
parents:
1400
diff
changeset
|
170 |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
171 if src not in self: |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
172 self._ui.debug('adding %s to %s\n' % (src, self.mapname())) |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
173 elif dst != self[src]: |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
174 msg = 'overriding %s: "%s" to "%s" (%s)\n' |
1440
4d3a51e82147
BaseMap: extract filename attribute magic into a classmethod
Augie Fackler <raf@durin42.com>
parents:
1439
diff
changeset
|
175 self._ui.status(msg % (self.mapname(), self[src], dst, src)) |
1384
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
176 self[src] = dst |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
177 |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
178 f.close() |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
179 if writing: |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
180 writing.close() |
2d1d05e6e46c
maps: add a load method to base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1383
diff
changeset
|
181 |
1385
9139d9295a36
maps: make author map inherit from base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1384
diff
changeset
|
182 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
|
183 '''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
|
184 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
|
185 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
186 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
|
187 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
|
188 |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
189 If the 'hgsubversion.caseignoreauthors' configuration option is set to true, |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
190 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
|
191 ''' |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
192 |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
193 def __init__(self, meta, defaulthost, caseignoreauthors, |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
194 mapauthorscmd, defaultauthors): |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
195 '''Initialise a new AuthorMap. |
322
05cd4a5138bf
Move some .warn() calls to noisy levels instead.
Augie Fackler <durin42@gmail.com>
parents:
310
diff
changeset
|
196 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
197 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
|
198 |
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 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
|
200 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
|
201 ''' |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
202 if defaulthost: |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
203 self.defaulthost = '@%s' % defaulthost.lstrip('@') |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
204 else: |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
205 self.defaulthost = '' |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
206 self._caseignoreauthors = caseignoreauthors |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
207 self._mapauthorscmd = mapauthorscmd |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
208 self._defaulthost = defaulthost |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
209 self._defaultauthors = defaultauthors |
1194
49791c40a8a5
maps: change authormap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents:
1193
diff
changeset
|
210 |
1386
8bd40916106f
maps: remove unneeded __init__ code from author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1385
diff
changeset
|
211 super(AuthorMap, self).__init__(meta) |
1193
a55339d35066
maps: load commandline authormap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1188
diff
changeset
|
212 |
1400
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
213 def _lowercase(self, key): |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
214 '''Determine whether or not to lowercase a str or regex using the |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
215 meta.caseignoreauthors.''' |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
216 k = key |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
217 if self._caseignoreauthors: |
1400
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
218 if isinstance(key, str): |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
219 k = key.lower() |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
220 else: |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
221 k = re.compile(key.pattern.lower()) |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
222 return k |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
223 |
1379
367e65989b41
maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1375
diff
changeset
|
224 def __setitem__(self, key, value): |
367e65989b41
maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1375
diff
changeset
|
225 '''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
|
226 use lowercase string or not |
367e65989b41
maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1375
diff
changeset
|
227 ''' |
1400
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
228 super(AuthorMap, self).__setitem__(self._lowercase(key), value) |
1379
367e65989b41
maps: add custom __setitem__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1375
diff
changeset
|
229 |
1380
332ad9ea579b
maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1379
diff
changeset
|
230 def __contains__(self, key): |
332ad9ea579b
maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1379
diff
changeset
|
231 '''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
|
232 use lowercase string or not |
332ad9ea579b
maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1379
diff
changeset
|
233 ''' |
1400
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
234 return super(AuthorMap, self).__contains__(self._lowercase(key)) |
1380
332ad9ea579b
maps: add custom __contains__ to author map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1379
diff
changeset
|
235 |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
236 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
|
237 ''' 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
|
238 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
|
239 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
|
240 if author is None: |
c2b9e08ecf10
maps: map a missing author to '(no author)'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
729
diff
changeset
|
241 author = '(no author)' |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
242 |
1400
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
243 if not isinstance(author, str): |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
244 return super(AuthorMap, self).__getitem__(author) |
3e264851f879
maps: protect author map functions from regexes
Sean Farley <sean.michael.farley@gmail.com>
parents:
1399
diff
changeset
|
245 |
1196
878372849175
maps: use meta.caseignoreauthors intead of accessing ui directly
Sean Farley <sean.michael.farley@gmail.com>
parents:
1195
diff
changeset
|
246 search_author = author |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
247 if self._caseignoreauthors: |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
248 search_author = author.lower() |
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
249 |
1374
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
250 result = None |
1097
e015cd34168d
authormap: allow case-insensitive authormaps for easier conversions
maugustin
parents:
976
diff
changeset
|
251 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
|
252 result = super(AuthorMap, self).__getitem__(search_author) |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
253 elif self._mapauthorscmd: |
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
254 cmd = self._mapauthorscmd % author |
1375
abc87a62ff51
maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents:
1374
diff
changeset
|
255 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
|
256 output, err = process.communicate() |
abc87a62ff51
maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents:
1374
diff
changeset
|
257 retcode = process.poll() |
abc87a62ff51
maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents:
1374
diff
changeset
|
258 if retcode: |
abc87a62ff51
maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents:
1374
diff
changeset
|
259 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
|
260 raise hgutil.Abort(msg % cmd) |
abc87a62ff51
maps: remove python2.7ism from dynamic author mapping
Mateusz Kwapich <mitrandir@fb.com>
parents:
1374
diff
changeset
|
261 self[author] = result = output.strip() |
1374
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
262 if not result: |
1429
3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
Augie Fackler <raf@durin42.com>
parents:
1428
diff
changeset
|
263 if self._defaultauthors: |
1374
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
264 self[author] = result = '%s%s' % (author, self.defaulthost) |
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
265 msg = 'substituting author "%s" for default "%s"\n' |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
266 self._ui.debug(msg % (author, result)) |
1374
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
267 else: |
a17d8874a099
Added dynamic author mapping.
Jerome M. BERGER <jeberger@free.fr>
parents:
1356
diff
changeset
|
268 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
|
269 raise hgutil.Abort(msg % author) |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
270 self._ui.debug('mapping author "%s" to "%s"\n' % (author, result)) |
307
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
271 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
|
272 |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 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
|
277 else: |
1d48d9a34c19
Put authormap into a separate file, and make it much better too.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
diff
changeset
|
278 # 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
|
279 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
|
280 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
281 |
728
cfefeefad199
rename TagMap to Tags, to free up the TagMap name
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
725
diff
changeset
|
282 class Tags(dict): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
283 """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
|
284 |
729 | 285 tag names are non-empty strings. Tags are saved in a file |
286 called tagmap, for backwards compatibility reasons. | |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
287 """ |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
288 VERSION = 2 |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
289 |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
290 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
|
291 dict.__init__(self) |
1432
a2ef2c1e3644
TagMap: record filepath explicitly
Augie Fackler <raf@durin42.com>
parents:
1431
diff
changeset
|
292 self._filepath = meta.tagfile |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
293 self._ui = meta.ui |
725 | 294 self.endrev = endrev |
1432
a2ef2c1e3644
TagMap: record filepath explicitly
Augie Fackler <raf@durin42.com>
parents:
1431
diff
changeset
|
295 if os.path.isfile(self._filepath): |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
296 self._load() |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
297 else: |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
298 self._write() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
299 |
1187
30b2139c3931
maps: change tags init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1186
diff
changeset
|
300 def _load(self): |
1432
a2ef2c1e3644
TagMap: record filepath explicitly
Augie Fackler <raf@durin42.com>
parents:
1431
diff
changeset
|
301 f = open(self._filepath) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
302 ver = int(f.readline()) |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
303 if ver < self.VERSION: |
1439
ab15749252b0
TagMap: stop automagically running 'hg svn rebuildmeta'
Augie Fackler <raf@durin42.com>
parents:
1438
diff
changeset
|
304 raise error.Abort( |
ab15749252b0
TagMap: stop automagically running 'hg svn rebuildmeta'
Augie Fackler <raf@durin42.com>
parents:
1438
diff
changeset
|
305 'tag map outdated, please run `hg svn rebuildmeta`') |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
310 revision = int(revision) |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
311 tag = tag[:-1] |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
312 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
|
313 break |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
314 if not tag: |
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
315 continue |
1253
c54214bb6c4e
maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents:
1252
diff
changeset
|
316 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
|
317 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
318 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
319 def _write(self): |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
320 assert self.endrev is None |
1432
a2ef2c1e3644
TagMap: record filepath explicitly
Augie Fackler <raf@durin42.com>
parents:
1431
diff
changeset
|
321 f = open(self._filepath, 'w') |
448
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
322 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
|
323 f.close() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
324 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
325 def update(self, other): |
725 | 326 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
|
327 self[k] = v |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
328 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
329 def __contains__(self, tag): |
593
eb16630bceb1
maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents:
579
diff
changeset
|
330 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
|
331 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
|
332 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
333 def __getitem__(self, tag): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
334 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
|
335 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
|
336 raise KeyError() |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
337 |
453
bb612e625be6
tags: handle copyfrom old versions of tags more correctly
Augie Fackler <durin42@gmail.com>
parents:
448
diff
changeset
|
338 def __setitem__(self, tag, info): |
519
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
339 if not tag: |
247110c633f7
maps: TagMap tags are non-empty strings
Patrick Mezard <pmezard@gmail.com>
parents:
460
diff
changeset
|
340 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
|
341 ha, revision = info |
1432
a2ef2c1e3644
TagMap: record filepath explicitly
Augie Fackler <raf@durin42.com>
parents:
1431
diff
changeset
|
342 f = open(self._filepath, 'a') |
1253
c54214bb6c4e
maps: avoid O(n) property lookups on the node module
Siddharth Agarwal <sid0@fb.com>
parents:
1252
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 |
fbc7cf4fd701
tags: reinstate a tag map file in a better way
Augie Fackler <durin42@gmail.com>
parents:
430
diff
changeset
|
347 |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
348 class RevMap(dict): |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
349 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
350 VERSION = 1 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
351 |
1183
09b20039192c
maps: change revmap init to accept svnmeta not a repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1182
diff
changeset
|
352 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
|
353 dict.__init__(self) |
1430
48beb467b2e5
RevMap: use self._filepath instead of using meta
Augie Fackler <raf@durin42.com>
parents:
1429
diff
changeset
|
354 self._filepath = meta.revmap_file |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
355 self._lastpulled_file = os.path.join(meta.metapath, 'lastpulled') |
1294
9a722b5246df
maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents:
1254
diff
changeset
|
356 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
|
357 |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
358 self.firstpulled = 0 |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
359 if os.path.exists(self._lastpulled_file): |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
360 with open(self._lastpulled_file) as f: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
361 self._lastpulled = int(f.read()) |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
362 else: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
363 self._lastpulled = 0 |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
364 |
1430
48beb467b2e5
RevMap: use self._filepath instead of using meta
Augie Fackler <raf@durin42.com>
parents:
1429
diff
changeset
|
365 if os.path.isfile(self._filepath): |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
366 self._load() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
367 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
368 self._write() |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
369 |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
370 def _writelastpulled(self): |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
371 with open(self._lastpulled_file, 'w') as f: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
372 f.write('%d\n' % self.lastpulled) |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
373 |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
374 @property |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
375 def lastpulled(self): |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
376 return self._lastpulled |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
377 |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
378 @lastpulled.setter |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
379 def lastpulled(self, value): |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
380 self._lastpulled = value |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
381 self._writelastpulled() |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
382 |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
383 def hashes(self): |
1294
9a722b5246df
maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents:
1254
diff
changeset
|
384 if self._hashes is None: |
9a722b5246df
maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents:
1254
diff
changeset
|
385 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
|
386 return self._hashes |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
387 |
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 |
1422
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
392 def branchmaxrevnum(self, branch, maxrevnum): |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
393 result = 0 |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
394 for num, br in self.iterkeys(): |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
395 if br == branch and num <= maxrevnum and num > result: |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
396 result = num |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
397 return result |
372afb75f465
maps: add the "branchmaxrevnum" method to RevMap
Jun Wu <quark@fb.com>
parents:
1421
diff
changeset
|
398 |
1419
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
399 @property |
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
400 def lasthash(self): |
1421
0094f222c5dc
maps: make readmapfile of RevMap a private instance method
Jun Wu <quark@fb.com>
parents:
1419
diff
changeset
|
401 lines = list(self._readmapfile()) |
1419
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
402 if not lines: |
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
403 return None |
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
404 return bin(lines[-1].split(' ', 2)[1]) |
2e4145e452cd
maps: add "lasthash" property to RevMap
Jun Wu <quark@fb.com>
parents:
1414
diff
changeset
|
405 |
1413
951a87f2f2bd
maps: add the "revhashes" method to RevMap
Jun Wu <quark@fb.com>
parents:
1412
diff
changeset
|
406 def revhashes(self, revnum): |
951a87f2f2bd
maps: add the "revhashes" method to RevMap
Jun Wu <quark@fb.com>
parents:
1412
diff
changeset
|
407 for key, value in self.iteritems(): |
951a87f2f2bd
maps: add the "revhashes" method to RevMap
Jun Wu <quark@fb.com>
parents:
1412
diff
changeset
|
408 if key[0] == revnum: |
951a87f2f2bd
maps: add the "revhashes" method to RevMap
Jun Wu <quark@fb.com>
parents:
1412
diff
changeset
|
409 yield value |
951a87f2f2bd
maps: add the "revhashes" method to RevMap
Jun Wu <quark@fb.com>
parents:
1412
diff
changeset
|
410 |
1411
025e849d22f0
maps: add the "clear" method to RevMap
Jun Wu <quark@fb.com>
parents:
1401
diff
changeset
|
411 def clear(self): |
025e849d22f0
maps: add the "clear" method to RevMap
Jun Wu <quark@fb.com>
parents:
1401
diff
changeset
|
412 self._write() |
025e849d22f0
maps: add the "clear" method to RevMap
Jun Wu <quark@fb.com>
parents:
1401
diff
changeset
|
413 dict.clear(self) |
025e849d22f0
maps: add the "clear" method to RevMap
Jun Wu <quark@fb.com>
parents:
1401
diff
changeset
|
414 self._hashes = None |
025e849d22f0
maps: add the "clear" method to RevMap
Jun Wu <quark@fb.com>
parents:
1401
diff
changeset
|
415 |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
416 def batchset(self, items, lastpulled): |
1412
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
417 '''Set items in batches |
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
418 |
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
419 items is an array of (rev num, branch, binary hash) |
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
420 |
1424
a794cbc174a9
maps: document RevMap.batchset will not update internal state
Jun Wu <quark@fb.com>
parents:
1422
diff
changeset
|
421 For performance reason, internal in-memory state is not updated. |
a794cbc174a9
maps: document RevMap.batchset will not update internal state
Jun Wu <quark@fb.com>
parents:
1422
diff
changeset
|
422 To get an up-to-date RevMap, reconstruct the object. |
1412
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
423 ''' |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
424 with open(self._filepath, 'a') as f: |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
425 f.write(''.join('%s %s %s\n' % (revnum, hex(binhash), br or '') |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
426 for revnum, br, binhash in items)) |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
427 with open(self._lastpulled_file, 'w') as f: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
428 f.write('%s\n' % lastpulled) |
1412
7e98352a37db
maps: add the "batchset" method to RevMap
Jun Wu <quark@fb.com>
parents:
1411
diff
changeset
|
429 |
1421
0094f222c5dc
maps: make readmapfile of RevMap a private instance method
Jun Wu <quark@fb.com>
parents:
1419
diff
changeset
|
430 def _readmapfile(self): |
1430
48beb467b2e5
RevMap: use self._filepath instead of using meta
Augie Fackler <raf@durin42.com>
parents:
1429
diff
changeset
|
431 path = self._filepath |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
432 try: |
1182
8f9619a67565
maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents:
1144
diff
changeset
|
433 f = open(path) |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
434 except IOError, err: |
1421
0094f222c5dc
maps: make readmapfile of RevMap a private instance method
Jun Wu <quark@fb.com>
parents:
1419
diff
changeset
|
435 if err.errno != errno.ENOENT: |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
436 raise |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
437 return iter([]) |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
438 ver = int(f.readline()) |
1421
0094f222c5dc
maps: make readmapfile of RevMap a private instance method
Jun Wu <quark@fb.com>
parents:
1419
diff
changeset
|
439 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
|
440 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
|
441 return f |
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
442 |
1414
99bc6003ac56
maps: add the "exists" method to RevMap
Jun Wu <quark@fb.com>
parents:
1413
diff
changeset
|
443 @classmethod |
99bc6003ac56
maps: add the "exists" method to RevMap
Jun Wu <quark@fb.com>
parents:
1413
diff
changeset
|
444 def exists(cls, meta): |
99bc6003ac56
maps: add the "exists" method to RevMap
Jun Wu <quark@fb.com>
parents:
1413
diff
changeset
|
445 return os.path.exists(meta.revmap_file) |
99bc6003ac56
maps: add the "exists" method to RevMap
Jun Wu <quark@fb.com>
parents:
1413
diff
changeset
|
446 |
1251
46cec117dda2
maps.RevMap: disable GC while loading the revmap
Siddharth Agarwal <sid0@fb.com>
parents:
1217
diff
changeset
|
447 @util.gcdisable |
889
7a98fbadcae9
revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents:
847
diff
changeset
|
448 def _load(self): |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
449 lastpulled = self.lastpulled |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
450 firstpulled = self.firstpulled |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
451 if os.path.exists(self._lastpulled_file): |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
452 with open(self._lastpulled_file) as f: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
453 lastpulled = int(f.read()) |
1254
d07ccad28b1a
maps.RevMap: avoid O(revs) property lookups on dict
Siddharth Agarwal <sid0@fb.com>
parents:
1253
diff
changeset
|
454 setitem = dict.__setitem__ |
1421
0094f222c5dc
maps: make readmapfile of RevMap a private instance method
Jun Wu <quark@fb.com>
parents:
1419
diff
changeset
|
455 for l in self._readmapfile(): |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
456 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
|
457 if branch == '\n': |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
458 branch = None |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
459 else: |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
460 branch = branch[:-1] |
415
b17b2969861c
svnmeta: move revmap methods, make last_known_revision() more efficient
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
409
diff
changeset
|
461 revnum = int(revnum) |
1252
a321afbc3479
maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents:
1251
diff
changeset
|
462 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
|
463 lastpulled = revnum |
a321afbc3479
maps.RevMap: while loading, read lastpulled and firstpulled once
Siddharth Agarwal <sid0@fb.com>
parents:
1251
diff
changeset
|
464 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
|
465 firstpulled = revnum |
1254
d07ccad28b1a
maps.RevMap: avoid O(revs) property lookups on dict
Siddharth Agarwal <sid0@fb.com>
parents:
1253
diff
changeset
|
466 setitem(self, (revnum, branch), bin(ha)) |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
467 if self.lastpulled != lastpulled: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
468 self.lastpulled = lastpulled |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
469 self.firstpulled = firstpulled |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
470 |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
471 def _write(self): |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
472 with open(self._filepath, 'w') as f: |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
473 f.write('%s\n' % self.VERSION) |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
474 self._writelastpulled() |
408
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
475 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
476 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
|
477 revnum, branch = key |
f137231f9d30
extract the revmap support into a separate dict-like class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
360
diff
changeset
|
478 b = branch or '' |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
479 with open(self._filepath, 'a') as f: |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
480 f.write(str(revnum) + ' ' + hex(ha) + ' ' + b + '\n') |
1434
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
481 if revnum > self.lastpulled or not self.lastpulled: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
482 self.lastpulled = revnum |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
483 if revnum < self.firstpulled or not self.firstpulled: |
0a6b3da6d34c
RevMap: move lastpulled from SVNMeta down into RevMap
Augie Fackler <raf@durin42.com>
parents:
1432
diff
changeset
|
484 self.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
|
485 dict.__setitem__(self, (revnum, branch), ha) |
1294
9a722b5246df
maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents:
1254
diff
changeset
|
486 if self._hashes is not None: |
9a722b5246df
maps: cache hashes() for the revmap
Mateusz Kwapich <mitrandir@fb.com>
parents:
1254
diff
changeset
|
487 self._hashes[ha] = (revnum, branch) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
488 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
489 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
490 class FileMap(object): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
491 |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
492 VERSION = 1 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
493 |
1217
a10a4fc69364
maps: change filemap to initialize with an svnmeta object
Sean Farley <sean.michael.farley@gmail.com>
parents:
1216
diff
changeset
|
494 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
|
495 '''Initialise a new FileMap. |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
496 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
497 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
|
498 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
499 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
|
500 typically .hg/svn/filemap. |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
501 ''' |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
502 self._filename = meta.filemap_file |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
503 self._ui = meta.ui |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
504 self.include = {} |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
505 self.exclude = {} |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
506 if os.path.isfile(self._filename): |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
507 self._load() |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
508 else: |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
509 self._write() |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
510 |
1214
2c793092862b
maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1213
diff
changeset
|
511 # append file mapping specified from the commandline |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
512 clmap = util.configpath(self._ui, 'filemap') |
1214
2c793092862b
maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1213
diff
changeset
|
513 if clmap: |
2c793092862b
maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1213
diff
changeset
|
514 self.load(clmap) |
2c793092862b
maps: load commandline filemap in __init__
Sean Farley <sean.michael.farley@gmail.com>
parents:
1213
diff
changeset
|
515 |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
516 def _rpairs(self, name): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
517 e = len(name) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
518 while e != -1: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
519 yield name[:e], name[e+1:] |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
520 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
|
521 yield '.', name |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
522 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 return -1 |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
529 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 if len(self.include): |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
534 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
|
535 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
|
536 return True |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
537 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
|
538 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
|
539 if len(self.exclude): |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
540 exc = self.check('exclude', path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
541 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
|
542 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
|
543 # 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
|
544 return inc > exc |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
545 |
822
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
546 # 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
|
547 def __len__(self): |
033b86e0f56d
stupid/filemap: disable this since it doesn't currently work
Augie Fackler <durin42@gmail.com>
parents:
821
diff
changeset
|
548 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
|
549 |
826
8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Yonggang Luo <luoyonggang@gmail.com>
parents:
822
diff
changeset
|
550 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
|
551 mapping = getattr(self, m) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
552 if path in mapping: |
593
eb16630bceb1
maps: fix a % formatting bug
Augie Fackler <durin42@gmail.com>
parents:
579
diff
changeset
|
553 msg = 'duplicate %s entry in %s: "%s"\n' |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
554 self._ui.status(msg % (m, fn, path)) |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
555 return |
956
24fbba02cb8f
maps: fix filemap loading --verbose message
Patrick Mezard <patrick@mezard.eu>
parents:
891
diff
changeset
|
556 bits = m.rstrip('e'), path |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
557 self._ui.debug('%sing %s\n' % bits) |
847
0de18c5c2e35
Respect filemap rule order (rules that come first are overridden by rules that come later)
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
846
diff
changeset
|
558 # 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
|
559 mapping[path] = len(self) |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
560 if fn != self._filename: |
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
561 with open(self._filename, 'a') as f: |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
562 f.write(m + ' ' + path + '\n') |
409
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
563 |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
564 def load(self, fn): |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
565 self._ui.debug('reading file map from %s\n' % fn) |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
566 with open(fn, 'r') as f: |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
567 self.load_fd(f, fn) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
568 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
569 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
|
570 for line in f: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
571 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
|
572 continue |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
573 try: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
574 cmd, path = line.split(' ', 1) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
575 cmd = cmd.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
576 path = path.strip() |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
577 if cmd in ('include', 'exclude'): |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
578 self.add(fn, cmd, path) |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
579 continue |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
580 self._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
|
581 except IndexError: |
d4615986e1db
extract the filemap support into a separate class
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
408
diff
changeset
|
582 msg = 'ignoring bad line in filemap %s: %s\n' |
1428
da272633997f
maps: store a direct reference to ui
Augie Fackler <raf@durin42.com>
parents:
1427
diff
changeset
|
583 self._ui.warn(msg % (fn, line.rstrip())) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
584 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
585 def _load(self): |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
586 self._ui.debug('reading in-repo file map from %s\n' % self._filename) |
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
587 with open(self._filename) as f: |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
588 ver = int(f.readline()) |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
589 if ver != self.VERSION: |
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
590 raise hgutil.Abort('filemap too new -- please upgrade') |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
591 self.load_fd(f, self._filename) |
846
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
592 |
7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
Vitaliy Filippov <vitalif@yourcmc.ru>
parents:
829
diff
changeset
|
593 def _write(self): |
1437
43df01d36f22
FileMap: store filename locally
Augie Fackler <raf@durin42.com>
parents:
1435
diff
changeset
|
594 with open(self._filename, 'w') as f: |
1435
18a961672a72
maps: switch many file opens to using the with statement
Augie Fackler <raf@durin42.com>
parents:
1434
diff
changeset
|
595 f.write('%s\n' % self.VERSION) |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
596 |
1388
130ced9e371d
maps: make branch map inherit from base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1387
diff
changeset
|
597 class BranchMap(BaseMap): |
574
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
598 '''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
|
599 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
600 oldname = newname |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
601 other = default |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
602 |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
603 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
|
604 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
|
605 ''' |
8e025a6f0db4
add basic branchmap functionality, to rename branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
573
diff
changeset
|
606 |
1391
7a866bca15de
maps: make tag map inherit from base map
Sean Farley <sean.michael.farley@gmail.com>
parents:
1390
diff
changeset
|
607 class TagMap(BaseMap): |
729 | 608 '''Facility for controlled renaming of tags. Example: |
609 | |
610 oldname = newname | |
611 other = | |
612 | |
809
ab372e38fb6c
maps: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents:
742
diff
changeset
|
613 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
|
614 the other tag will not be reflected in the hg repository. |
729 | 615 ''' |