fix(git): correct field misalignment in date-filtered git_log#4524
Open
itguruhaseeb wants to merge 1 commit into
Open
fix(git): correct field misalignment in date-filtered git_log#4524itguruhaseeb wants to merge 1 commit into
itguruhaseeb wants to merge 1 commit into
Conversation
The date-filtered branch of git_log used the pretty-format
'%H%n%an%n%ad%n%s%n'. The trailing %n makes git emit a blank line after
every commit, so each record occupies 5 slots after split('\n') while the
parser advances in groups of 4. Only the first commit lands on a correct
boundary; every subsequent commit is shifted by one field (the hash is
labeled Author, the date labeled Message) and a commit can be dropped or a
spurious blank entry emitted.
Drop the trailing %n so each record is exactly 4 lines and the group-of-4
parser stays aligned. The unfiltered branch (iter_commits) was already
correct and is unchanged.
Adds a regression test that filters by start_timestamp and asserts every
commit's fields map correctly across multiple commits.
1 task
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.
Problem
git_log's date-filtered branch parsesgit logoutput into fixed groups of 4 lines (hash, author, date, subject), but the pretty-format string ends with a trailing%n:That trailing
%nmakes git emit a blank line after every commit, so each record occupies 5 slots after.split('\n')while the loop advances by 4. Only the first commit lands on a correct boundary. Every commit after it is shifted by one field, and a commit can be dropped or a spurious blank entry emitted.Concretely, for a repo with an "initial commit" plus a few filtered commits, the second entry comes back as:
The unfiltered branch (
iter_commits, used when nostart_timestamp/end_timestampis given) is correct and unaffected, which is why this went unnoticed.Fix
Drop the trailing
%nso each record is exactly 4 lines and the group-of-4 parser stays aligned:%sis the commit subject (first line only), so every field is guaranteed single-line and the 4-line grouping is safe.Test
Adds
test_git_log_with_timestamp_filter, which filters bystart_timestampand asserts every commit's fields map correctly across multiple commits. It fails on the old format (returns 5 entries with shifted fields) and passes with the fix. Full git-server suite: 44 passed.