aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/packobjects.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-11 13:03:56 +0000
committerGravatar Runxi Yu2026-06-11 13:03:56 +0000
commit0fad4fe5e59a7d908ce62b80b7a14a7c74149ec5 (patch)
treeb4f7cf39d68cd0a7ab4ff45d85394c075762ec28 /internal/testgit/packobjects.go
parentinternal/format/packfile/delta: Add header parsing and serialization (diff)
internal/testgit: packobjects, verifypack
Diffstat (limited to 'internal/testgit/packobjects.go')
-rw-r--r--internal/testgit/packobjects.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/testgit/packobjects.go b/internal/testgit/packobjects.go
new file mode 100644
index 00000000..9f56eef0
--- /dev/null
+++ b/internal/testgit/packobjects.go
@@ -0,0 +1,47 @@
+package testgit
+
+import (
+ "bytes"
+ "iter"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "lindenii.org/go/furgit/object/id"
+)
+
+// PackObjectsOptions controls one pack-objects invocation.
+type PackObjectsOptions struct {
+ // RevIndex requests writing a .rev reverse index alongside the pack.
+ RevIndex bool
+}
+
+// PackObjects packs the supplied objects with git pack-objects
+// into a temporary directory,
+// and returns the artifact path prefix "<dir>/pack-<hash>",
+// to which ".pack", ".idx", and ".rev" suffixes apply.
+func (repo *Repo) PackObjects(tb testing.TB, oids iter.Seq[id.ObjectID], opts PackObjectsOptions) (string, error) {
+ tb.Helper()
+
+ dir := tb.TempDir()
+
+ var stdin bytes.Buffer
+ for oid := range oids {
+ stdin.WriteString(oid.String())
+ stdin.WriteByte('\n')
+ }
+
+ revIndex := "false"
+ if opts.RevIndex {
+ revIndex = "true"
+ }
+
+ out, err := repo.run(tb, &stdin,
+ "git", "-c", "pack.writeReverseIndex="+revIndex,
+ "pack-objects", "--end-of-options", filepath.Join(dir, "pack"))
+ if err != nil {
+ return "", err
+ }
+
+ return filepath.Join(dir, "pack-"+strings.TrimSpace(string(out))), nil
+}