From c7c54de39149e07c5cb03e8d8aa49793f32047de Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 6 Oct 2025 04:27:49 -0500 Subject: cleanup code further --- shell.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'shell.go') diff --git a/shell.go b/shell.go index ace3482..6230a2b 100644 --- a/shell.go +++ b/shell.go @@ -170,7 +170,9 @@ func (repo *Repo) ConstructGitDiffLog(branch1, branch2 string) []string { var cmd []string cmd = append(cmd, "git") cmd = append(cmd, "log") - cmd = append(cmd, "--format=\"%H%00%ae%00%as%00%s\"") + sfmt := strings.Join([]string{"%H", "%ae", "%as", "%s"}, "%00") + // cmd = append(cmd, "--format=%H%00%ae%00%as%00%s") // git log doesn't convert %00 to NULL + cmd = append(cmd, "--format="+sfmt) // git log doesn't convert %00 to NULL cmd = append(cmd, branch1) cmd = append(cmd, "--not") cmd = append(cmd, branch2) @@ -178,25 +180,34 @@ func (repo *Repo) ConstructGitDiffLog(branch1, branch2 string) []string { } // count all objects only in branch1 -func (repo *Repo) CountDiffObjects(branch1, branch2 string) (int, error) { +func (repo *Repo) CountDiffObjectsNEWNEW(branch1, branch2 string) ([]string, []string, error) { cmd := repo.ConstructGitDiffLog(branch1, branch2) - r, err := repo.RunVerboseOnError(cmd) - if err != nil { - return -1, err + os.Chdir(repo.FullPath) + result := shell.RunQuiet(cmd) + var err error + if result.Exit != 0 { + err = fmt.Errorf("probably os.Exit(-1)") + } + if result.Error != nil { + err = result.Error } + //for i, line := range result.Stdout { + // parts := strings.Split(line, "\x00") + // log.Infof("LINE: %d len(%d) %v\n", i, len(parts), parts) + //} // log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " ")) - return len(r.Stdout), err + return result.Stdout, cmd, err } // count all objects only in branch1 -func (repo *Repo) CountDiffObjectsNew(branch1, branch2 string) ([]string, error) { +func (repo *Repo) CountDiffObjects(branch1, branch2 string) (int, error) { cmd := repo.ConstructGitDiffLog(branch1, branch2) r, err := repo.RunVerboseOnError(cmd) if err != nil { - return nil, err + return -1, err } // log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " ")) - return r.Stdout, err + return len(r.Stdout), err } func (repo *Repo) CountDiffObjectsVerbose(branch1, branch2 string) ([]string, error) { @@ -205,7 +216,7 @@ func (repo *Repo) CountDiffObjectsVerbose(branch1, branch2 string) ([]string, er if err != nil { return nil, err } - log.Info("Run:", cmd) + log.Info("Ran:", cmd) for _, line := range r.Stdout { log.Info(line, branch1, branch2, repo.FullPath) } -- cgit v1.2.3