Repository navigation
Read a commit timestamp whose offset is beyond 14 hours instead of failing Log() [patch] - #267
Merged
Merged
Conversation
…iling Log() [patch] git stores a commit's zone as an arbitrary +-hhmm, so imported history can carry +15:00, which DateTimeOffset cannot hold. ReadTimestamp threw GitParseException for that record, failing Log() for the whole history and making Commit() report failure after git had made the commit. The parser now reads such a timestamp by hand and returns the same instant in UTC. GitSignature.Timestamp documents the exception to its preserved-offset rule. Fixes #262 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PTQ7jCRWNMZJ4a5VEJRtt4
Addresses SonarCloud S3358 on this change; behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PTQ7jCRWNMZJ4a5VEJRtt4
|
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.



Fixes #262
What changed
GitLogParser.ReadTimestampused to throwGitParseExceptionwheneverDateTimeOffset.TryParsefailed.DateTimeOffsetonly holds offsets up to ±14:00, but git accepts any±hhmmzone, so one imported commit with+1500madeLog()fail for the entire history, and madeCommit()report failure after git had already made the commit.When the normal parse fails,
ReadTimestampnow reads%aI/%cIby hand:yyyy-MM-ddTHH:mm:ssplus a±hh:mmoffset. If the offset is beyond ±14:00, it returns the same instant in UTC. Any other malformed value still throws, and so does an in-range offset that failed to parse for some other reason.GitSignature.Timestampnow documents this as the one exception to its preserved-offset rule.Design note: the issue suggested adding
%at/%cttoLogFormat. I kept the format unchanged and read the offset from the existing ISO field instead. That gives the same instant without changing the field count, which every log fixture andFieldCountdepend on. If you'd rather have the Unix-seconds fields, that's a follow-up.Tests
GitLogParserTests:ReadsATimestampWithAnOffsetBeyondFourteenHours:+15:00and-15:00author and committer dates parse to Unix time1700000000, with an in-range row for comparison. The values are exactly what git 2.43 prints forGIT_AUTHOR_DATE="1700000000 +1500"/GIT_COMMITTER_DATE="1700000000 -1500", which I checked against a real repository.RejectsAMalformedTimestampWithAnOutOfRangeOffset: a malformed offset, an invalid month, and an offset with no date still throwGitParseException.Without the parser change, the
+15:00and-15:00rows fail. With it, the full suite passes: 923/923.Generated by Claude Code