Skip to content

fix(git): correct git_log off-by-one in timestamp-filtered output#4399

Open
ly-wang19 wants to merge 1 commit into
modelcontextprotocol:mainfrom
ly-wang19:fix/git-log-timestamp-format-offby-one
Open

fix(git): correct git_log off-by-one in timestamp-filtered output#4399
ly-wang19 wants to merge 1 commit into
modelcontextprotocol:mainfrom
ly-wang19:fix/git-log-timestamp-format-offby-one

Conversation

@ly-wang19

Copy link
Copy Markdown

Description

git_log's timestamp-filtered branch uses the pretty-format %H%n%an%n%ad%n%s%n — note the trailing %n after 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 — Author shows the next commit's hash, Date shows its author, etc. — producing scrambled git_log output whenever start_timestamp / end_timestamp is 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 + a start_timestamp filter): before the fix it fails (messages/authors are shifted into each other); after the fix the three commits parse in order. Full src/git suite: 44 passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant