Move some functions to gitrepo package to reduce RepoPath reference directly (#36126)

This commit is contained in:
Lunny Xiao
2025-12-11 16:15:40 -08:00
committed by GitHub
parent f25409fab8
commit d2a372fc59
18 changed files with 122 additions and 90 deletions

View File

@@ -4,8 +4,10 @@
package gitrepo
import (
"bytes"
"context"
"fmt"
"io"
"regexp"
"strconv"
@@ -60,3 +62,15 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
}
return numFiles, totalAdditions, totalDeletions, err
}
// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
func GetReverseRawDiff(ctx context.Context, repo Repository, commitID string, writer io.Writer) error {
stderr := new(bytes.Buffer)
if err := RunCmd(ctx, repo, gitcmd.NewCommand("show", "--pretty=format:revert %H%n", "-R").
AddDynamicArguments(commitID).
WithStdout(writer).
WithStderr(stderr)); err != nil {
return fmt.Errorf("GetReverseRawDiff: %w - %s", err, stderr)
}
return nil
}