github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/pipeline/namerev.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package pipeline
     7  
     8  import (
     9  	"bytes"
    10  	"context"
    11  	"fmt"
    12  	"io"
    13  	"strings"
    14  	"sync"
    15  
    16  	"github.com/gitbundle/modules/git"
    17  )
    18  
    19  // NameRevStdin runs name-rev --stdin
    20  func NameRevStdin(ctx context.Context, shasToNameReader *io.PipeReader, nameRevStdinWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
    21  	defer wg.Done()
    22  	defer shasToNameReader.Close()
    23  	defer nameRevStdinWriter.Close()
    24  
    25  	stderr := new(bytes.Buffer)
    26  	var errbuf strings.Builder
    27  	if err := git.NewCommand(ctx, "name-rev", "--stdin", "--name-only", "--always").Run(&git.RunOpts{
    28  		Dir:    tmpBasePath,
    29  		Stdout: nameRevStdinWriter,
    30  		Stdin:  shasToNameReader,
    31  		Stderr: stderr,
    32  	}); err != nil {
    33  		_ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
    34  	}
    35  }