comparison hg_delta_editor.py @ 167:3cd6a7354207

fetch: Add support for an authormap which can rename authors, intended for repository conversion.
author Graham Booker <gbooker@cod3r.com>
date Tue, 30 Dec 2008 20:13:32 -0600
parents 2a4b7a86af93
children 4f26fa049452
comparison
equal deleted inserted replaced
166:db88e528e8e6 167:3cd6a7354207
58 f.close() 58 f.close()
59 self.revmap[revnum, branch] = node_hash 59 self.revmap[revnum, branch] = node_hash
60 60
61 def __init__(self, path=None, repo=None, ui_=None, 61 def __init__(self, path=None, repo=None, ui_=None,
62 subdir='', author_host='', 62 subdir='', author_host='',
63 tag_locations=['tags']): 63 tag_locations=['tags'],
64 authors=None):
64 """path is the path to the target hg repo. 65 """path is the path to the target hg repo.
65 66
66 subdir is the subdirectory of the edits *on the svn server*. 67 subdir is the subdirectory of the edits *on the svn server*.
67 It is needed for stripping paths off in certain cases. 68 It is needed for stripping paths off in certain cases.
68 """ 69 """
103 pickle_atomic(self.tag_locations, self.tag_locations_file, 104 pickle_atomic(self.tag_locations, self.tag_locations_file,
104 self.meta_data_dir) 105 self.meta_data_dir)
105 106
106 self.clear_current_info() 107 self.clear_current_info()
107 self.author_host = author_host 108 self.author_host = author_host
109 self.authors = {}
110 if os.path.exists(self.authors_file):
111 self.readauthors(self.authors_file)
112 if authors and os.path.exists(authors):
113 self.readauthors(authors)
114 if self.authors:
115 self.writeauthors()
108 116
109 def __setup_repo(self, repo_path): 117 def __setup_repo(self, repo_path):
110 """Verify the repo is going to work out for us. 118 """Verify the repo is going to work out for us.
111 119
112 This method will fail an assertion if the repo exists but doesn't have 120 This method will fail an assertion if the repo exists but doesn't have
386 current_ctx = context.memctx(self.repo, 394 current_ctx = context.memctx(self.repo,
387 parents, 395 parents,
388 rev.message or ' ', 396 rev.message or ' ',
389 files, 397 files,
390 del_all_files, 398 del_all_files,
391 '%s%s' % (rev.author, 399 self.authorforsvnauthor(rev.author),
392 self.author_host),
393 date, 400 date,
394 {'branch': 'closed-branches'}) 401 {'branch': 'closed-branches'})
395 new_hash = self.repo.commitctx(current_ctx) 402 new_hash = self.repo.commitctx(current_ctx)
396 self.ui.status('Marked branch %s as closed.\n' % (branch or 403 self.ui.status('Marked branch %s as closed.\n' % (branch or
397 'default')) 404 'default'))
435 current_ctx = context.memctx(self.repo, 442 current_ctx = context.memctx(self.repo,
436 parents, 443 parents,
437 rev.message or '...', 444 rev.message or '...',
438 files.keys(), 445 files.keys(),
439 filectxfn, 446 filectxfn,
440 '%s%s' %(rev.author, self.author_host), 447 self.authorforsvnauthor(rev.author),
441 date, 448 date,
442 extra) 449 extra)
443 new_hash = self.repo.commitctx(current_ctx) 450 new_hash = self.repo.commitctx(current_ctx)
444 self.ui.status('committed as %s on branch %s\n' % 451 self.ui.status('committed as %s on branch %s\n' %
445 (node.hex(new_hash), (branch or 'default'))) 452 (node.hex(new_hash), (branch or 'default')))
462 current_ctx = context.memctx(self.repo, 469 current_ctx = context.memctx(self.repo,
463 (ha, node.nullid), 470 (ha, node.nullid),
464 rev.message or ' ', 471 rev.message or ' ',
465 [], 472 [],
466 del_all_files, 473 del_all_files,
467 '%s%s' % (rev.author, 474 self.authorforsvnauthor(rev.author),
468 self.author_host),
469 date, 475 date,
470 extra) 476 extra)
471 new_hash = self.repo.commitctx(current_ctx) 477 new_hash = self.repo.commitctx(current_ctx)
472 self.ui.status('committed as %s on branch %s\n' % 478 self.ui.status('committed as %s on branch %s\n' %
473 (node.hex(new_hash), (branch or 'default'))) 479 (node.hex(new_hash), (branch or 'default')))
474 if (rev.revnum, branch) not in self.revmap: 480 if (rev.revnum, branch) not in self.revmap:
475 self.add_to_revmap(rev.revnum, branch, new_hash) 481 self.add_to_revmap(rev.revnum, branch, new_hash)
476 self.clear_current_info() 482 self.clear_current_info()
477 483
484 def authorforsvnauthor(self, author):
485 if(author in self.authors):
486 return self.authors[author]
487 return '%s%s' %(author, self.author_host)
488
489 def readauthors(self, authorfile):
490 self.ui.status(
491 ('Reading authormap %s\n')
492 % authorfile)
493 f = open(authorfile, 'r')
494 for line in f:
495 if line.strip() == '':
496 continue
497 try:
498 srcauth, dstauth = line.split('=', 1)
499 srcauth = srcauth.strip()
500 dstauth = dstauth.strip()
501 if srcauth in self.authors and dstauth != self.authors[srcauth]:
502 self.ui.status(
503 ('Overriding mapping for author %s, was %s, now %s\n')
504 % (srcauth, self.authors[srcauth], dstauth))
505 else:
506 self.ui.debug(('Mapping author %s to %s\n')
507 % (srcauth, dstauth))
508 self.authors[srcauth] = dstauth
509 except IndexError:
510 self.ui.warn(
511 ('Ignoring bad line in author map file %s: %s\n')
512 % (authorfile, line.rstrip()))
513 f.close()
514
515 def writeauthors(self):
516 f = open(self.authors_file, 'w+')
517 self.ui.status(
518 ('Writing author map file %s\n')
519 % self.authors_file)
520 for author in self.authors:
521 f.write("%s=%s\n" % (author, self.authors[author]))
522 f.close()
523
478 @property 524 @property
479 def meta_data_dir(self): 525 def meta_data_dir(self):
480 return os.path.join(self.path, '.hg', 'svn') 526 return os.path.join(self.path, '.hg', 'svn')
481 527
482 def meta_file_named(self, name): 528 def meta_file_named(self, name):
512 558
513 @property 559 @property
514 def url(self): 560 def url(self):
515 return open(self.svn_url_file).read() 561 return open(self.svn_url_file).read()
516 562
563 @property
564 def authors_file(self):
565 return self.meta_file_named('authors')
566
517 @stash_exception_on_self 567 @stash_exception_on_self
518 def delete_entry(self, path, revision_bogus, parent_baton, pool=None): 568 def delete_entry(self, path, revision_bogus, parent_baton, pool=None):
519 br_path, branch = self._path_and_branch_for_path(path) 569 br_path, branch = self._path_and_branch_for_path(path)
520 if br_path == '': 570 if br_path == '':
521 self.branches_to_delete.add(branch) 571 self.branches_to_delete.add(branch)