comparison hggit/git2hg.py @ 794:1350e43e662f

git2hg.find_incoming: move graph traversal into a function This is preparation for upcoming changes to find_incoming that will allow it to import certain Git branches as Mercurial named branches.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 15 Oct 2014 14:21:09 -0700
parents 388944fca782
children c19835c3c60d
comparison
equal deleted inserted replaced
793:388944fca782 794:1350e43e662f
34 todo.append(sha) 34 todo.append(sha)
35 35
36 todo.sort(key=commitdate, reverse=True) 36 todo.sort(key=commitdate, reverse=True)
37 return todo 37 return todo
38 38
39 def get_unseen_commits(todo):
40 '''get all unseen commits reachable from todo in topological order
41
42 'unseen' means not reachable from the done set and not in the git map.
43 Mutates todo and the done set in the process.'''
44 commits = []
45 while todo:
46 sha = todo[-1]
47 if sha in done or sha in git_map:
48 todo.pop()
49 continue
50 assert isinstance(sha, str)
51 if sha in commit_cache:
52 obj = commit_cache[sha]
53 else:
54 obj = git_object_store[sha]
55 commit_cache[sha] = obj
56 assert isinstance(obj, Commit)
57 for p in obj.parents:
58 if p not in done and p not in git_map:
59 todo.append(p)
60 # process parents of a commit before processing the
61 # commit itself, and come back to this commit later
62 break
63 else:
64 commits.append(sha)
65 done.add(sha)
66 todo.pop()
67
68 return commits
69
39 todo = get_heads(refs) 70 todo = get_heads(refs)
40 71 commits = get_unseen_commits(todo)
41 # traverse the heads getting a list of all the unique commits in
42 # topological order
43 commits = []
44 while todo:
45 sha = todo[-1]
46 if sha in done or sha in git_map:
47 todo.pop()
48 continue
49 assert isinstance(sha, str)
50 if sha in commit_cache:
51 obj = commit_cache[sha]
52 else:
53 obj = git_object_store[sha]
54 commit_cache[sha] = obj
55 assert isinstance(obj, Commit)
56 for p in obj.parents:
57 if p not in done and p not in git_map:
58 todo.append(p)
59 # process parents of a commit before processing the
60 # commit itself, and come back to this commit later
61 break
62 else:
63 commits.append(sha)
64 done.add(sha)
65 todo.pop()
66 72
67 return GitIncomingResult(commits, commit_cache) 73 return GitIncomingResult(commits, commit_cache)
68 74
69 class GitIncomingResult(object): 75 class GitIncomingResult(object):
70 '''struct to store result from find_incoming''' 76 '''struct to store result from find_incoming'''