summaryrefslogtreecommitdiff
path: root/compare.go
blob: ed362f77d1b575297cfc585d2158400c3ab26fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package gitpb

import (
	"fmt"

	"go.wit.com/log"
)

type RepoTag struct {
	r *Repo
	t *GitTag
}

func (r *Repo) NewCompareTag(refname string) *RepoTag {
	t := r.IfRefExists(refname)
	if t == nil {
		return nil
	}
	rt := new(RepoTag)
	rt.r = r
	rt.t = t
	return rt
}

func (r *Repo) NewCompareRef(t *GitTag) *RepoTag {
	if t == nil {
		return nil
	}
	rt := new(RepoTag)
	rt.r = r
	rt.t = t
	return rt
}

func (t1 *RepoTag) DeleteBranch(t2 *RepoTag) ([]string, []string, error) {
	lines1, err1 := t1.r.CountDiffObjectsNew(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
	}
	lines2, err2 := t1.r.CountDiffObjectsNew(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
	}
	if (len(lines1) != 0) || (len(lines2) != 0) {
		return lines1, lines2, fmt.Errorf("nope")
	}
	return lines1, lines2, 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)
	if err != nil {
		log.Info("lessthan", t1.t.Refname, t2.t.Refname, len(count), t1.r.FullPath, err)
		return nil
	}
	if len(count) == 0 {
		return nil
	}
	return count
}

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)
	// log.Info("greaterthan", t1.t.Refname, t2.t.Refname, count, t1.r.FullPath, err)
	if err != nil {
		return nil
	}
	if len(lines) == 0 {
		return lines
	}
	return nil
}

func (r *Repo) GetLocalUserRef() *GitTag {
	return r.IsBranchLocal(r.GetUserBranchName())
}

func (r *Repo) GetLocalDevelRef() *GitTag {
	return r.IsBranchLocal(r.GetDevelBranchName())
}

func (r *Repo) GetLocalMasterRef() *GitTag {
	return r.IsBranchLocal(r.GetMasterBranchName())
}