-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarcs.go
100 lines (82 loc) · 2.1 KB
/
darcs.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
package vcsinfo
import (
pth "path"
"path/filepath"
"strings"
)
// DarcsProbe is a probe for extracting information out of a DARCS repository.
type DarcsProbe struct{}
// Name returns the human-facing name of the probe.
func (probe DarcsProbe) Name() string {
return "darcs"
}
// DefaultFormat returns the default format string to use for DARCS
// repositories.
func (probe DarcsProbe) DefaultFormat() string {
return "%n[%b%m%u]"
}
// IsAvailable indicates whether or not this probe has the tools/environment
// necessary to operate.
func (probe DarcsProbe) IsAvailable() (bool, error) {
return commandExists("darcs"), nil
}
// IsRepositoryRoot identifies whether or not the specified path is the root
// of a DARCS repository.
func (probe DarcsProbe) IsRepositoryRoot(path string) (bool, error) {
return dirExists(filepath.Join(path, "_darcs"))
}
func (probe DarcsProbe) extractStatus(path string, info *VcsInfo) error {
out, err := runCommand(path, "darcs", "whatsnew", "--look-for-adds", "--summary")
if err != nil {
if len(out) > 0 {
if out[0] == "No changes!" {
return nil
}
}
return err
}
for _, line := range out {
flag := line[0:1]
if flag == "a" {
info.HasNew = true
} else {
info.HasModified = true
}
}
return nil
}
func (probe DarcsProbe) extractHash(path string, info *VcsInfo) error {
out, err := runCommand(path, "darcs", "log", "--last", "1")
if err != nil {
return err
}
for _, line := range out {
if strings.HasPrefix(line, "patch ") {
info.Hash = line[6:]
}
}
return nil
}
// GatherInfo extracts and returns VCS information for the DARCS repository at
// the specified path.
func (probe DarcsProbe) 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
info.Branch = pth.Base(root)
errors := waitGroup(
func() error {
return probe.extractStatus(path, &info)
},
func() error {
return probe.extractHash(path, &info)
},
)
return info, errors
}