shithub: furgit

Download patch

ref: d2d3ce370816d178cc0beb4271123ee37d07657c
parent: 7ddaf1eb2fde11a9e07df0215646c1dca08ccc50
author: Runxi Yu <runxiyu@umich.edu>
date: Sun Mar 22 18:46:10 EDT 2026

packfile/ingest: Document lifecycle of pack ingest better

--- a/packfile/ingest/api.go
+++ b/packfile/ingest/api.go
@@ -68,6 +68,8 @@
 }
 
 // Pending is one started ingest operation awaiting Continue or Discard.
+//
+// Exactly one of Continue or Discard may be called.
 type Pending struct {
 	reader    *bufio.Reader
 	algo      objectid.Algorithm
@@ -110,11 +112,13 @@
 }
 
 // Continue ingests the pack stream into destination and writes pack artifacts.
+//
+// Continue is terminal. Further use of pending is undefined behavior.
+//
+// Artifacts are published under content-addressed final names derived from the
+// resulting pack hash. If those final names already exist, Continue treats that
+// as success and removes its temporary files.
 func (pending *Pending) Continue(destination *os.Root) (Result, error) {
-	if pending.finalized {
-		return Result{}, ErrAlreadyFinalized
-	}
-
 	pending.finalized = true
 
 	if pending.header.ObjectCount == 0 {
@@ -136,12 +140,11 @@
 	return ingest(state)
 }
 
-// Discard consumes and verifies one zero-object pack stream without writing files.
+// Discard consumes and verifies one zero-object pack stream without writing
+// files.
+//
+// Discard is terminal. Further use of pending is undefined behavior.
 func (pending *Pending) Discard() (DiscardResult, error) {
-	if pending.finalized {
-		return DiscardResult{}, ErrAlreadyFinalized
-	}
-
 	pending.finalized = true
 
 	if pending.header.ObjectCount != 0 {
--- a/packfile/ingest/errors.go
+++ b/packfile/ingest/errors.go
@@ -68,8 +68,6 @@
 var errExternalThinBase = errors.New("packfile/ingest: external thin base required")
 
 var (
-	// ErrAlreadyFinalized indicates Continue/Discard already called.
-	ErrAlreadyFinalized = errors.New("packfile/ingest: operation already finalized")
 	// ErrZeroObjectContinue indicates Continue was called for a zero-object pack.
 	ErrZeroObjectContinue = errors.New("packfile/ingest: cannot continue zero-object pack")
 	// ErrNonZeroDiscard indicates Discard was called for a non-zero-object pack.
--