fix(git): correct git_log off-by-one in timestamp-filtered output#4399
Open
ly-wang19 wants to merge 1 commit into
Open
fix(git): correct git_log off-by-one in timestamp-filtered output#4399ly-wang19 wants to merge 1 commit into
ly-wang19 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
git_log's timestamp-filtered branch uses the pretty-format%H%n%an%n%ad%n%s%n— note the trailing%nafter the subject. With git's inter-commit newline,.split('\n')then yields 5 fields per commit (hash,author,date,subject,""), but the parser strides in groups of 4 (range(0, len(log_output), 4)).So only the first commit parses correctly; every subsequent commit is shifted by one —
Authorshows the next commit's hash,Dateshows its author, etc. — producing scrambledgit_logoutput wheneverstart_timestamp/end_timestampis used on a repo with 2+ matching commits.The sibling no-timestamp branch (which uses
iter_commits) parses cleanly, establishing the intended one-record-per-commit contract that this branch violates.Fix
Drop the trailing
%n(--format=%H%n%an%n%ad%n%s) so each commit is exactly four newline-delimited fields, matching the groups-of-4 parser.Testing
Added
test_git_log_with_timestamp_filter_parses_each_commit(three commits + astart_timestampfilter): before the fix it fails (messages/authors are shifted into each other); after the fix the three commits parse in order. Fullsrc/gitsuite: 44 passed.