3 class HeadTracker(object):
5 Keep track of the heads in a fastimport stream.
10 # map git ref name (e.g. "refs/heads/master") to id of last
11 # commit with that ref
14 # the set of heads seen so far in the stream, as a mapping
15 # from commit id of the head to set of ref names
18 def track_heads(self, cmd):
19 """Track the repository heads given a CommitCommand.
21 :param cmd: the CommitCommand
22 :return: the list of parents in terms of commit-ids
24 # Get the true set of parents
25 if cmd.from_ is not None:
28 last_id = self.last_ids.get(cmd.ref)
29 if last_id is not None:
33 parents.extend(cmd.merges)
36 self.track_heads_for_ref(cmd.ref, cmd.id, parents)
39 def track_heads_for_ref(self, cmd_ref, cmd_id, parents=None):
40 if parents is not None:
41 for parent in parents:
42 if parent in self.heads:
43 del self.heads[parent]
44 self.heads.setdefault(cmd_id, set()).add(cmd_ref)
45 self.last_ids[cmd_ref] = cmd_id
46 self.last_ref = cmd_ref