Skip to content

Commit

Permalink
contrib: use specific git log range. Avoid --all.
Browse files Browse the repository at this point in the history
Because `git log --all` effectively adds REFS in `refs/` to the `git
log` call it will produce output listing commits from all the REFS in
our local repo.

Citelang was getting a list of `--all` commits, and then filtering between
start and end points. Because of this, it could pick up commits that
are not really in the section of history we are interested in - but come
from a fork, or usptream with shared history earlier on.

Call `git log` with a specific commit range so that it directly provides
the correct list of commits we need to consider.

As a bonus, you can now use other refs like branches or deltas as `--start`
and `--end` points.

Fixes #35
  • Loading branch information
dtrudg committed May 20, 2022
1 parent 5a69722 commit 3238697
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions citelang/main/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,22 @@ def get_commit_range(self, shallow=False):
"""
Given a start and end, parse and return the commits from git
"""
# Single commit, honor previous behavior
if self.start == self.end:
log_range = self.start +"~1.." + self.start
# Open or closed range
elif self.start or self.end:
log_range = self.start + ".." + self.end
# No start or end... all history for HEAD
else:
log_range = "HEAD"

if shallow:
res = self.git("git", "log", "--first-parent", "--all", "--format=%H")
res = self.git("git", "log", "--first-parent", "--format=%H", log_range)

# Possibly duplications but won't miss any commits
else:
res = self.git("git", "log", "--all", "--format=%H")
res = self.git("git", "log", "--format=%H", log_range)

# Get commits and timestamps
commits = [x for x in res.split("\n") if x]
Expand All @@ -535,23 +545,5 @@ def get_commit_range(self, shallow=False):
# Need to reverse - end (most recent) is at top!
commits.reverse()

# Do we have a start commit or tag?
start_commit = self.start
if start_commit:
if start_commit not in commits:
start_commit = self.get_tag_commit(start_commit)

end_commit = self.end
if end_commit:
if end_commit not in commits:
end_commit = self.get_tag_commit(end_commit)

if not end_commit:
end_commit = commits[-1]
if not start_commit:
start_commit = commits[0]

# +1 ensures we include the end commit in the range
commits = commits[commits.index(start_commit) : commits.index(end_commit) + 1]
logger.info("Found %s commits." % len(commits))
return commits

0 comments on commit 3238697

Please sign in to comment.