GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(repo): preserve trailing whitespace in blamed line content by Keerthana-64 · Pull Request #2339 · gitpython-developers/GitPython

Conversation

@Keerthana-64

@Keerthana-64 Keerthana-64 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

repo.blame mein line_bytes.rstrip().decode() use hone ki wajah se line ke end ke spaces aur tabs remove ho rahe the. Whitespace-only lines empty ho jaati thi aur CRLF line ka carriage return bhi remove ho raha tha.

Is wajah se repo.blame() original file ka exact content return nahi kar raha tha, jisse exact line matching aur commit identify karne mein problem aa sakti thi.

Fix: Ab sirf starting tab aur ending line feed remove hoti hai. Baaki original content preserve rehta hai.

Testing: blame-content.sh aur test_blame_preserves_line_content dono backends par successfully pass ho rahe hain.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Keerthana-64
fix(repo): preserve trailing whitespace in blamed line content
35027d1
`Repo.blame` built each blamed line with `line_bytes.rstrip().decode(defenc)`
and then stripped the leading tab, but a `git blame -p` content line is a
leading tab, the blamed line's exact bytes, and git's own terminating line
feed. `rstrip` therefore dropped a line's trailing spaces and tabs, emptied a
whitespace-only line, and removed the carriage return of a CRLF line, so the
content returned by `repo.blame()` differed from both the file and
`git blame`. A caller that reconstructs or compares file content from blame,
for example to find the commit that introduced an exact line, was handed
altered text.

Recover the exact bytes instead: drop the leading tab and only git's trailing
line feed, then decode. Binary lines and the hexsha/header parsing are
unchanged, so the only behavior change is that blamed lines keep their
original trailing whitespace and carriage returns.

Adds `tests/fixtures/blame-content.sh` and `test_blame_preserves_line_content`
in `test/test_repo.py`, which fail before the change
(`['alpha', 'beta', '', 'crlf', 'gamma']`) and pass after
(`['alpha   ', 'beta', '\t', 'crlf\r', 'gamma']`) on both the `cli` and `gix`
backends. `ruff check`, `ruff format --check` and `mypy` pass on the touched
files. The repository's pre-existing shallow-clone failures occur identically
with and without this change.

Agent-Model: claude-opus-4-8
@Byron
Byron requested a balanced review from Copilot November 4, 2026 09:37
Copilot started reviewing on behalf of Byron November 4, 2026 09:37
View session
Copilot AI reviewed Nov 4, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change to preserve trailing whitespace and carriage returns in blame output.

No open issues 🎉

What changed in this PR

This PR fixes Repo.blame() text-line parsing so returned content preserves trailing whitespace and carriage returns from CRLF lines.

Changes:

  • Remove only the porcelain content prefix and terminating line feed before decoding.
  • Add a byte-preserving fixture and regression test covering trailing spaces, a tab-only line, and CRLF content.
File Description
tests/​fixtures/​blame-content.sh Creates committed content with exact whitespace bytes.
test/​test_repo.py Verifies blame preserves the expected line content.
git/​repo/​base.py Decodes content without stripping its trailing whitespace.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Byron
Byron approved these changes Nov 4, 2026
View reviewed changes
@codex @Byron
test(refs): keep PathLike reference names portable on Windows
ff48765
`test_revision_arguments_preserve_pathlike_paths` fails in the Windows
`Python package` jobs because `Path("refs/heads/main")` emits
`refs\heads\main`. Git rejects backslashes in reference names, so the
test raises `ValueError: Invalid reference` before exercising revision
argument handling. All four combinations of SHA-1/SHA-256 and
files/reftable fail. The same failures are present in the final Windows
Python 3.14t job for the introducing PR gitpython-developers#2336, so this is inherited by
PR gitpython-developers#2339 rather than caused by its blame-content change.

Use `PurePosixPath` for the reference-name test parameter. Reference
names use forward slashes on every platform; filesystem paths elsewhere
in the tests continue to use `Path`. Keep `PathLikeMock` coverage and
the existing reference validation unchanged.

Validation: 28 focused reference/revision tests pass on each of the
`cli` and `gix` backends, including all eight PathLike cases, nested
merge-base operands, reflog walks, fork-point lookup, and remote archives.
Both blame-content regressions also pass on each backend. Ruff 0.17.2
lint and formatting checks pass for `test/test_refs.py`; `git diff --check`
passes. Windows validation is left to the PR's CI matrix.

Agent-Model: unknown
@Byron

Byron commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Codex on behalf of Byron: pushed ff48765 (test(refs): keep PathLike reference names portable on Windows) to fix the inherited Windows failures.

Path("refs/heads/main") produces refs\heads\main on Windows, which Git correctly rejects. The test now uses PurePosixPath so reference names retain Git's forward-slash syntax on every platform. Library behavior and reference validation are unchanged.

The earlier revision of #2336, d03d3d7, passed CI. Its follow-up 6de90f1 added this test and failed with the same four Windows cases. This explains why the introducing PR appeared to have passed previously.

Locally, 28 focused reference tests and both blame-content regressions pass on each of the CLI and Gix backends. Ruff lint and formatting checks also pass. All 64 CI checks passed for ff48765, including every Windows CLI and Gix job. There are no unresolved review threads. The PR workflow is complete.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Byron
Byron merged commit 2ad7960 into gitpython-developers:main Nov 5, 2026
64 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Keerthana-64

Keerthana-64 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, and for tracking down the Windows ref-name failure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@Byron Byron Byron approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Keerthana-64 @Byron @codex
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.