Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib: use specific git log range. Avoid --all. #36

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on GitHub.

## [0.0.x](https://github.com/vsoch/citelang/tree/main) (0.0.x)
- contrib does not count commits from other REFs, now uses git log without `--all` (0.0.30)
- Default contrib does a deep search, with option to add `--shallow` (0.0.29)
- Adding basic support for parsing CMakeLists.txt (0.0.28)
- JoSS paper and sort package names in listing (0.0.27)
Expand Down
39 changes: 17 additions & 22 deletions citelang/main/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def _to_list(self, original, detail):

class ContributionParser(GitParser):
def __init__(self, root=None, start=None, end=None, outdir=None, paths=None):
self.start = start
self.end = end
self.start = start or ""
self.end = end or ""
self.set_root(root)
self.set_paths(paths)
self.outdir = outdir or os.path.join(os.getcwd(), ".contrib")
Expand Down Expand Up @@ -518,12 +518,25 @@ 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 and self.start == self.end:
log_range = self.start +"~1.." + self.start
# Open or closed range with start
elif self.start:
log_range = self.start + ".." + self.end
# Open range with end (initial commit to end)
elif self.end:
log_range = 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 +548,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
2 changes: 1 addition & 1 deletion citelang/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2022, Vanessa Sochat"
__license__ = "MPL 2.0"

__version__ = "0.0.29"
__version__ = "0.0.30"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "citelang"
Expand Down