Skip to content

Fix external git diff-files being called repeatedly for the same file (Issue #530) - #599

Merged
hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-repeated-diff-on-stage
Sep 12, 2026
Merged

hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-repeated-diff-on-stage

Conversation

@goneng

@goneng goneng commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

The commit view re-renders on every index update, and each render asks git for
the diff of the file on screen.
Staging one file does that three times over an untouched file, which is
what #530 reports seeing in the log.

  • Answer from the last diff while the path, context, parent tree, working file
    and index are all unchanged
  • Stat the two files rather than trust the refresh output, which reports how a
    file is staged but not whether its content changed

Test plan:

  • Staging one file, same repo and steps, with a logging git wrapper:
    diff-files -U3 -- <path> ran 3 times before and runs 1 time after
  • An external edit to the selected file still re-reads its diff, checked in the
    running app
  • 6 new tests in PBGitIndexDiffCacheTests, make unit-test is 55 green

@goneng goneng changed the title Fix external git diff-files being called repeatedly for the same file Fix external git diff-files being called repeatedly for the same file (Issue #530) Sep 11, 2026
@goneng
goneng marked this pull request as ready for review September 11, 2026 16:06
@goneng
goneng force-pushed the fix-repeated-diff-on-stage branch from 67bb6fe to 744e037 Compare September 11, 2026 17:55
@goneng
goneng force-pushed the fix-repeated-diff-on-stage branch from 744e037 to 90c4e78 Compare September 12, 2026 08:42
… (issue gitx#530)

Answer the commit view from the diff it was last given while nothing it
was read from has changed, instead of starting another git for a file
that has not moved.

Staging one file re-renders the commit view three times:
- once as the selection moves on, and
- once for each of the two index refreshes that follow.
Each render asks for the diff of the file now on screen, so the same
`diff-files -U3 -- <path>` ran three times over an untouched file,
which is what issue gitx#530 reports seeing in the log.

The refresh output cannot tell whether a file's content changed,
only how it is staged, so the file and the index are stat'ed instead:
size and modification time to the nanosecond, alongside the path, the
tree being compared against and the requested context.

- Read a diff through a one entry cache keyed on all of that
- Fall back to reading it every time when the index cannot be located,
  since then there is nothing to notice a change against
- Cover both halves: a diff nothing could have changed is asked for
  once, and an edit, a rewritten index, a different context size or an
  amend are each asked for again
@goneng
goneng force-pushed the fix-repeated-diff-on-stage branch from 90c4e78 to 2eeff63 Compare September 12, 2026 09:36
@hannesa2
hannesa2 merged commit b621306 into gitx:master Sep 12, 2026
3 checks passed
@goneng
goneng deleted the fix-repeated-diff-on-stage branch September 12, 2026 15:19
@hannesa2 hannesa2 added the performance performance improvement label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants