Skip to content

Overhaul Commit Amount Calculation Timing and Exposure#123

Merged
marstr merged 2 commits intomainfrom
overhaulAmountCheck
Apr 2, 2026
Merged

Overhaul Commit Amount Calculation Timing and Exposure#123
marstr merged 2 commits intomainfrom
overhaulAmountCheck

Conversation

@marstr
Copy link
Copy Markdown
Owner

@marstr marstr commented Apr 2, 2026

This will eventually help with getting rid of the amount calculation that slows down the help text and can timeout on slow storage.

Fixes #122

marstr added 2 commits April 1, 2026 20:25
This will eventually help with getting rid of the amount calculation
that slows down the help text and can timeout on slow storage.
This was wreaking havoc when storage access was slow. In tandem with a
new dry-run flag, people should have the same ability to demystify what
is happening with amount calculation but only doing it if you actually
need to, and not timing out unless to respect the global timeout flag.
@marstr marstr requested a review from Copilot April 2, 2026 03:48
@marstr marstr marked this pull request as ready for review April 2, 2026 03:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts commit command behavior so the transaction amount is calculated at execution time (respecting the global timeout) and adds a --dry-run mode to preview the resulting transaction without persisting it, addressing slow-storage timeouts described in #122.

Changes:

  • Moves automatic amount calculation out of the Cobra Args hook and into Run, removing the hardcoded 2s timeout.
  • Adds --dry-run/-d to print the would-be commit instead of writing it.
  • Switches imbalance prompt I/O to Cobra’s cmd.InOrStdin() / cmd.OutOrStdout().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/commit.go
Comment on lines +284 to +288
if parent.Equal(envelopes.ID{}) {
commitTransactionFromFlags.Parents = []envelopes.ID{}
} else {
commitTransactionFromFlags.Parents = append([]envelopes.ID{parent}, additionalParents...)
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

In the dry-run path, commitTransactionFromFlags.Parents is set to an empty slice when there is no current HEAD. format.PrettyPrintTransaction assumes subject.Parents[0] exists and will panic for empty Parents. Ensure Parents always has at least one entry (e.g., include a zero envelopes.ID{} placeholder as the first parent) before calling PrettyPrintTransaction.

Suggested change
if parent.Equal(envelopes.ID{}) {
commitTransactionFromFlags.Parents = []envelopes.ID{}
} else {
commitTransactionFromFlags.Parents = append([]envelopes.ID{parent}, additionalParents...)
}
var parents []envelopes.ID
if parent.Equal(envelopes.ID{}) {
// No current HEAD; include a zero ID placeholder as the first parent.
parents = append([]envelopes.ID{envelopes.ID{}}, additionalParents...)
} else {
parents = append([]envelopes.ID{parent}, additionalParents...)
}
commitTransactionFromFlags.Parents = parents

Copilot uses AI. Check for mistakes.
Comment thread cmd/commit.go
Comment on lines +146 to 154
if !cmd.Flags().Changed(amountFlag) {
var err error
commitTransactionFromFlags.Amount, err = calculateAmount(ctx, ".")
if err != nil {
logrus.Fatalf("Failed to calculate the amount from %q because of the following error: %s", amountDefault, err)
}
}

commitTransactionFromFlags.State, err = index.LoadState(ctx, targetDir)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

calculateAmount loads state from disk (index.LoadState) and opens/reads the repo, and then the Run path immediately loads state again (commitTransactionFromFlags.State = index.LoadState(...)) and later re-opens/reads the repo (especially in --dry-run). On slow storage this doubles the I/O cost the PR is trying to avoid. Consider refactoring so state is loaded once and reused for both amount calculation and the commit/dry-run logic (e.g., pass the already-loaded state into the amount calculation helper, and reuse the already-open repository).

Copilot uses AI. Check for mistakes.
@marstr marstr merged commit 9e851fe into main Apr 2, 2026
7 checks passed
@marstr marstr deleted the overhaulAmountCheck branch April 2, 2026 03:57
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.

On GVFS, amount calculation times out blocking commit operation

2 participants