comparison hg_delta_editor.py @ 179:a336e3e82648

Fetch: add a filemap argument for use in converting old repositories to Mercurial.
author Graham Booker <gbooker@cod3r.com>
date Sat, 03 Jan 2009 20:15:03 -0600
parents c4115b3918e9
children e37f9d3fd5e7
comparison
equal deleted inserted replaced
178:33ebdcb75bcd 179:a336e3e82648
60 self.revmap[revnum, branch] = node_hash 60 self.revmap[revnum, branch] = node_hash
61 61
62 def __init__(self, path=None, repo=None, ui_=None, 62 def __init__(self, path=None, repo=None, ui_=None,
63 subdir='', author_host='', 63 subdir='', author_host='',
64 tag_locations=['tags'], 64 tag_locations=['tags'],
65 authors=None): 65 authors=None,
66 filemap=None):
66 """path is the path to the target hg repo. 67 """path is the path to the target hg repo.
67 68
68 subdir is the subdirectory of the edits *on the svn server*. 69 subdir is the subdirectory of the edits *on the svn server*.
69 It is needed for stripping paths off in certain cases. 70 It is needed for stripping paths off in certain cases.
70 """ 71 """
112 self.readauthors(self.authors_file) 113 self.readauthors(self.authors_file)
113 if authors and os.path.exists(authors): 114 if authors and os.path.exists(authors):
114 self.readauthors(authors) 115 self.readauthors(authors)
115 if self.authors: 116 if self.authors:
116 self.writeauthors() 117 self.writeauthors()
118 self.includepaths = {}
119 self.excludepaths = {}
120 if filemap and os.path.exists(filemap):
121 self.readfilemap(filemap)
117 122
118 def __setup_repo(self, repo_path): 123 def __setup_repo(self, repo_path):
119 """Verify the repo is going to work out for us. 124 """Verify the repo is going to work out for us.
120 125
121 This method will fail an assertion if the repo exists but doesn't have 126 This method will fail an assertion if the repo exists but doesn't have
227 if path and path.startswith(self.subdir): 232 if path and path.startswith(self.subdir):
228 path = path[len(self.subdir):] 233 path = path[len(self.subdir):]
229 if path and path[0] == '/': 234 if path and path[0] == '/':
230 path = path[1:] 235 path = path[1:]
231 return path 236 return path
237
238 def _is_file_included(self, subpath):
239 def checkpathinmap(path, mapping):
240 def rpairs(name):
241 yield '.', name
242 e = len(name)
243 while e != -1:
244 yield name[:e], name[e+1:]
245 e = name.rfind('/', 0, e)
246
247 for pre, suf in rpairs(path):
248 try:
249 return mapping[pre]
250 except KeyError, err:
251 pass
252 return None
253
254 if len(self.includepaths) and len(subpath):
255 inc = checkpathinmap(subpath, self.includepaths)
256 else:
257 inc = subpath
258 if len(self.excludepaths) and len(subpath):
259 exc = checkpathinmap(subpath, self.excludepaths)
260 else:
261 exc = None
262 if inc is None or exc is not None:
263 return False
264 return True
232 265
233 def _is_path_valid(self, path): 266 def _is_path_valid(self, path):
234 return self._split_branch_path(path)[0] is not None 267 subpath = self._split_branch_path(path)[0]
268 if subpath is None:
269 return False
270 return self._is_file_included(subpath)
271
235 272
236 def _is_path_tag(self, path): 273 def _is_path_tag(self, path):
237 """If path represents the path to a tag, returns the tag name. 274 """If path represents the path to a tag, returns the tag name.
238 275
239 Otherwise, returns False. 276 Otherwise, returns False.
559 % self.authors_file) 596 % self.authors_file)
560 for author in self.authors: 597 for author in self.authors:
561 f.write("%s=%s\n" % (author, self.authors[author])) 598 f.write("%s=%s\n" % (author, self.authors[author]))
562 f.close() 599 f.close()
563 600
601 def readfilemap(self, filemapfile):
602 self.ui.status(
603 ('Reading filemap %s\n')
604 % filemapfile)
605 def addpathtomap(path, mapping, mapname):
606 if path in mapping:
607 self.ui.warn(
608 ('%d alreading in %s list\n')
609 % (path, mapname))
610 else:
611 mapping[path] = path
612
613 f = open(filemapfile, 'r')
614 for line in f:
615 if line.strip() == '':
616 continue
617 try:
618 cmd, path = line.split(' ', 1)
619 cmd = cmd.strip()
620 path = path.strip()
621 if cmd == 'include':
622 addpathtomap(path, self.includepaths, 'include')
623 elif cmd == 'exclude':
624 addpathtomap(path, self.excludepaths, 'exclude')
625 else:
626 self.ui.warn(
627 ('Unknown filemap command %s\n')
628 % cmd)
629 except IndexError:
630 self.ui.warn(
631 ('Ignoring bad line in filemap %s: %s\n')
632 % (filemapfile, line.rstrip()))
633 f.close()
634
564 @property 635 @property
565 def meta_data_dir(self): 636 def meta_data_dir(self):
566 return os.path.join(self.path, '.hg', 'svn') 637 return os.path.join(self.path, '.hg', 'svn')
567 638
568 def meta_file_named(self, name): 639 def meta_file_named(self, name):