summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compare.go28
-rw-r--r--deleteTags.go2
-rw-r--r--gitTag.common.go6
-rw-r--r--shell.go31
4 files changed, 43 insertions, 24 deletions
diff --git a/compare.go b/compare.go
index ed362f7..c0452eb 100644
--- a/compare.go
+++ b/compare.go
@@ -2,8 +2,6 @@ package gitpb
import (
"fmt"
-
- "go.wit.com/log"
)
type RepoTag struct {
@@ -32,25 +30,34 @@ func (r *Repo) NewCompareRef(t *GitTag) *RepoTag {
return rt
}
-func (t1 *RepoTag) DeleteBranch(t2 *RepoTag) ([]string, []string, error) {
- lines1, err1 := t1.r.CountDiffObjectsNew(t1.t.Refname, t2.t.Refname)
+func (rt *RepoTag) GetRefname() string {
+ return rt.t.Refname
+}
+
+func (rt *RepoTag) GetRef() *GitTag {
+ return rt.t
+}
+
+func (t1 *RepoTag) DeleteBranch(t2 *RepoTag) ([]string, []string, []string, []string, error) {
+ lines1, cmd1, err1 := t1.r.CountDiffObjectsNEWNEW(t1.t.Refname, t2.t.Refname)
// log.Info("lessthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath)
if err1 != nil {
// log.Info("lessthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath, err)
- return nil, nil, err1
+ return nil, nil, cmd1, nil, err1
}
- lines2, err2 := t1.r.CountDiffObjectsNew(t2.t.Refname, t1.t.Refname)
+ lines2, cmd2, err2 := t1.r.CountDiffObjectsNEWNEW(t2.t.Refname, t1.t.Refname)
// log.Info("lessthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath)
if err2 != nil {
// log.Info("lessthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath, err)
- return nil, nil, err2
+ return nil, nil, cmd1, cmd2, err2
}
if (len(lines1) != 0) || (len(lines2) != 0) {
- return lines1, lines2, fmt.Errorf("nope")
+ return lines1, lines2, cmd1, cmd2, fmt.Errorf("nope")
}
- return lines1, lines2, nil
+ return lines1, lines2, cmd1, cmd2, nil
}
+/*
func (t1 *RepoTag) LessThanVerbose(t2 *RepoTag) []string {
count, err := t1.r.CountDiffObjectsNew(t1.t.Refname, t2.t.Refname)
log.Info("lessthan", t1.t.Refname, t2.t.Refname, len(count), t1.r.FullPath)
@@ -67,10 +74,11 @@ func (t1 *RepoTag) LessThanVerbose(t2 *RepoTag) []string {
func (t1 *RepoTag) Equal(t2 *RepoTag) bool {
return false
}
+*/
// if t1 is user branch, and t2 is devel branch, true if 0
func (t1 *RepoTag) GreaterThan(t2 *RepoTag) []string {
- lines, err := t1.r.CountDiffObjectsNew(t2.t.Refname, t1.t.Refname)
+ lines, _, err := t1.r.CountDiffObjectsNEWNEW(t2.t.Refname, t1.t.Refname)
// log.Info("greaterthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath, err)
if err != nil {
return nil
diff --git a/deleteTags.go b/deleteTags.go
index 0b05238..d54c2dc 100644
--- a/deleteTags.go
+++ b/deleteTags.go
@@ -29,7 +29,7 @@ func (repo *Repo) DeleteLocalBranch(branch string) ([]string, error) {
return nil, fmt.Errorf("no remote branch")
}
- b1, err := repo.CountDiffObjectsNew(branch, remote) // should be zero
+ b1, _, err := repo.CountDiffObjectsNEWNEW(branch, remote) // should be zero
if err != nil {
return nil, err
}
diff --git a/gitTag.common.go b/gitTag.common.go
index ac0f09c..635ca7d 100644
--- a/gitTag.common.go
+++ b/gitTag.common.go
@@ -118,10 +118,10 @@ func (repo *Repo) IsBranchLocal(findname string) *GitTag {
if !strings.HasPrefix(t.Refname, "refs/heads") {
continue
}
- path, filename := filepath.Split(t.Refname)
- log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
+ _, filename := filepath.Split(t.Refname)
+ // log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
- log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
+ // log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return t
}
}
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)
}