diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2020-11-20 19:14:40 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2020-11-20 19:14:40 -0700 |
commit | 7aaf95e5c59533b09d2e5e58ca32aebac4139fcb (patch) | |
tree | 22395530d2dd97299d90cdf01d8d5e5605797472 /fi-sponge | |
parent | 04e08c2176065f22bf8b09967cb37f789a07a7db (diff) |
Update for forgetting how things work after almost 2 years
Diffstat (limited to 'fi-sponge')
-rw-r--r-- | fi-sponge/sponge.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/fi-sponge/sponge.go b/fi-sponge/sponge.go index 1d42143..92d9784 100644 --- a/fi-sponge/sponge.go +++ b/fi-sponge/sponge.go @@ -1,4 +1,4 @@ -// Copyright 2019 Luke Shumaker <lukeshu@parabola.nu> +// Copyright 2019-2020 Luke Shumaker <lukeshu@parabola.nu> // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -25,10 +25,18 @@ import ( "path/filepath" "strings" "syscall" + + "git.parabola.nu/~lukeshu/fastimport-go-utils/fiutil" ) func usage() { fmt.Printf("Usage: git fast-export | %s [FAST-IMPORT-FLAGS] -- [FAST-EXPORT-FLAGS] | git fast-import\n", os.Args[0]) + fmt.Printf("Soaks up a fast-import stream, and re-emits it, potentially with different flags\n") + fmt.Printf(` +As expected, stdin is a fast-import stream, but if stdin is socket (as +when set up by 'sockline') it is also used as the cat-blob-fd. +`) + os.Exit(0) } func main() { @@ -39,13 +47,10 @@ func main() { split = i case "-h", "--help": usage() - os.Exit(0) } } if split == 0 { - fmt.Fprintf(os.Stderr, "%s: must give a '--' argument\n", os.Args[0]) - fmt.Fprintf(os.Stderr, "Try '%s --help' for more information\n", os.Args[0]) - os.Exit(2) + fiutil.ErrUsage("must give a '--' argument") } inargs := os.Args[1:split] outargs := os.Args[split+1:] @@ -67,6 +72,8 @@ func main() { } func sponge(inargs, outargs []string) error { + // 1. Create the sponge + tmpdir, err := ioutil.TempDir("", filepath.Base(os.Args[0])+".") if err != nil { return err @@ -81,6 +88,8 @@ func sponge(inargs, outargs []string) error { return err } + // 2. Soak up the input + cmd = exec.Command("git", append([]string{"fast-import", "--cat-blob-fd=0"}, inargs...)...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stderr @@ -89,6 +98,8 @@ func sponge(inargs, outargs []string) error { return err } + // 3. Emit the output + cmd = exec.Command("git", "for-each-ref", "--format=%(refname)") cmd.Stderr = os.Stderr b, err := cmd.Output() |