-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvs.go
114 lines (95 loc) · 2.59 KB
/
cvs.go
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package vcsinfo
import (
"path/filepath"
"strings"
)
// CvsProbe is a probe for extracting information out of a CVS repository.
type CvsProbe struct{}
// Name returns the human-facing name of the probe.
func (probe CvsProbe) Name() string {
return "cvs"
}
// DefaultFormat returns the default format string to use for CVS repositories.
func (probe CvsProbe) DefaultFormat() string {
return "%n[%e%m%u]"
}
// IsAvailable indicates whether or not this probe has the tools/environment
// necessary to operate.
func (probe CvsProbe) IsAvailable() (bool, error) {
return commandExists("cvs"), nil
}
// IsRepositoryRoot identifies whether or not the specified path is the root
// of a CVS repository.
func (probe CvsProbe) IsRepositoryRoot(path string) (bool, error) {
exists, err := dirExists(filepath.Join(path, "CVS"))
if !exists || err != nil {
return false, err
}
parentExists, parentErr := dirExists(filepath.Join(path, "..", "CVS"))
if parentExists || parentErr != nil {
return false, parentErr
}
return true, nil
}
func (probe CvsProbe) extractStatus(path string, info *VcsInfo) error {
out, err := runCommand(path, "cvs", "status")
if err != nil {
if len(out) > 0 {
// We're likely in a new directory that hasn't been added yet
if strings.HasPrefix(out[0], "cvs status: No CVSROOT specified!") {
return nil
}
}
return err
}
for _, line := range out {
if strings.HasSuffix(line, "Locally Added") ||
strings.HasSuffix(line, "Locally Modified") ||
strings.HasSuffix(line, "Locally Removed") ||
strings.HasSuffix(line, "Needs Checkout") {
info.HasModified = true
}
}
return nil
}
func (probe CvsProbe) extractNew(path string, info *VcsInfo) error {
out, err := runCommand(path, "cvs", "-qn", "update")
if err != nil {
if len(out) > 0 {
// We're likely in a new directory that hasn't been added yet
if strings.HasPrefix(out[0], "cvs update: No CVSROOT specified!") {
return nil
}
}
return err
}
for _, line := range out {
if strings.HasPrefix(line, "?") {
info.HasNew = true
return nil
}
}
return nil
}
// GatherInfo extracts and returns VCS information for the CVS repository at
// the specified path.
func (probe CvsProbe) GatherInfo(path string) (VcsInfo, []error) {
info := VcsInfo{
VcsName: probe.Name(),
Path: path,
}
root, err := findAcceptablePath(path, probe.IsRepositoryRoot)
if err != nil {
return info, []error{err}
}
info.RepositoryRoot = root
errors := waitGroup(
func() error {
return probe.extractStatus(path, &info)
},
func() error {
return probe.extractNew(path, &info)
},
)
return info, errors
}