Mercurial > hg-git-sync
comparison hggit_sync.py @ 1:e9f44d2deb94
Add some lame improvements to the map building.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 19 Feb 2016 16:01:24 -0800 |
parents | 6da45bb59fd0 |
children | 19156ccdc3e1 |
comparison
equal
deleted
inserted
replaced
0:6da45bb59fd0 | 1:e9f44d2deb94 |
---|---|
36 | 36 |
37 def build_commit_map(commits1, commits2): | 37 def build_commit_map(commits1, commits2): |
38 commits1 = sorted(commits1, key=lambda c: c.timestamp) | 38 commits1 = sorted(commits1, key=lambda c: c.timestamp) |
39 commits2 = sorted(commits2, key=lambda c: c.timestamp) | 39 commits2 = sorted(commits2, key=lambda c: c.timestamp) |
40 commit_map = dict(map(lambda c: (c.timestamp, (c, None)), commits1)) | 40 commit_map = dict(map(lambda c: (c.timestamp, (c, None)), commits1)) |
41 orphan_commits2 = [] | |
42 print("Building commit map...") | |
41 for c in commits2: | 43 for c in commits2: |
42 entry = commit_map.get(c.timestamp, (None, None)) | 44 entry = commit_map.get(c.timestamp, (None, None)) |
43 entry = (entry[0], c) | 45 entry = (entry[0], c) |
44 commit_map[c.timestamp] = entry | 46 commit_map[c.timestamp] = entry |
47 if entry[0] is None: | |
48 orphan_commits2.append(c) | |
49 | |
50 if orphan_commits2: | |
51 print("Fixing orphaned commits...") | |
52 did_fix = True | |
53 orphan_commits1 = [e[0] for e in commit_map.values() if e[1] is None] | |
54 while did_fix: | |
55 did_fix = False | |
56 for c2 in orphan_commits2: | |
57 for c1 in orphan_commits1: | |
58 if c1.description.strip() == c2.description.strip(): | |
59 print("Mapping '%s' to '%s'" % (c1.nodeid, c2.nodeid)) | |
60 print(" Similar description: %s" % c1.description) | |
61 print(" Timestamp difference: %d" % (c2.timestamp - c1.timestamp)) | |
62 commit_map[c1.timestamp] = (c1, c2) | |
63 orphan_commits1.remove(c1) | |
64 orphan_commits2.remove(c2) | |
65 did_fix = True | |
66 break | |
67 if did_fix: | |
68 break | |
69 | |
45 return commit_map | 70 return commit_map |
46 | 71 |
47 | 72 |
48 def main(): | 73 def main(): |
49 parser = argparse.ArgumentParser( | 74 parser = argparse.ArgumentParser( |
55 metavar='REMOTE', | 80 metavar='REMOTE', |
56 help="Rebuild the Git repo from the given remote URL.") | 81 help="Rebuild the Git repo from the given remote URL.") |
57 parser.add_argument( | 82 parser.add_argument( |
58 'mapfile', | 83 'mapfile', |
59 metavar='MAPFILE', | 84 metavar='MAPFILE', |
85 nargs='?', | |
60 help="The path to the mapfile to generate.") | 86 help="The path to the mapfile to generate.") |
61 res = parser.parse_args() | 87 res = parser.parse_args() |
62 | 88 |
63 hg_repo = os.getcwd() | 89 hg_repo = os.getcwd() |
64 if not os.path.exists(os.path.join(hg_repo, '.hg')): | 90 if not os.path.exists(os.path.join(hg_repo, '.hg')): |