aboutsummaryrefslogtreecommitdiff
path: root/cmd/show-object/run.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-29 13:31:16 +0000
committerGravatar Runxi Yu2026-03-29 13:31:16 +0000
commitad880cd26c9a6e4739d9ced8c5a076bccaceb999 (patch)
treef18d44acd1c2a414396c1d40c87af84cb815c65f /cmd/show-object/run.go
parentcmd/receivepack9418: Remove the silly runMain thingy (diff)
signatureNo signature
cmd/show-object: Split files
Diffstat (limited to 'cmd/show-object/run.go')
-rw-r--r--cmd/show-object/run.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/cmd/show-object/run.go b/cmd/show-object/run.go
new file mode 100644
index 00000000..f1a6fc6d
--- /dev/null
+++ b/cmd/show-object/run.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "codeberg.org/lindenii/furgit/repository"
+)
+
+func run(repoPath, name *string) error {
+ root, err := os.OpenRoot(*repoPath)
+ if err != nil {
+ return fmt.Errorf("open repo root: %w", err)
+ }
+
+ defer func() { _ = root.Close() }()
+
+ repo, err := repository.Open(root)
+ if err != nil {
+ return fmt.Errorf("open repository: %w", err)
+ }
+
+ id, err := resolveInput(repo, *name)
+ if err != nil {
+ _ = repo.Close()
+
+ return fmt.Errorf("resolve %q: %w", *name, err)
+ }
+
+ s, err := repo.Fetcher().ExactObject(id)
+ if err != nil {
+ _ = repo.Close()
+
+ return fmt.Errorf("read object %s: %w", id, err)
+ }
+
+ printStored(s)
+
+ err = repo.Close()
+ if err != nil {
+ return fmt.Errorf("close repository: %w", err)
+ }
+
+ return nil
+}