/
missing.go
63 lines (51 loc) · 1.52 KB
/
missing.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
package main
import (
"bytes"
"flag"
"fmt"
"os"
commit "github.com/mildred/doc/commit"
)
const usageMissing string = `doc missing [OPTIONS...] [SRC] DEST
doc missing [OPTIONS...] -from SRC [DEST]
doc missing [OPTIONS...] -to DEST [SRC]
Show files in SRC that are different from the same files in DEST (only committed
changes). Lines start with a symbol, followed by the file hash and the file
name.
- Represents the file in SRC
+ Represents the file in DEST
Conflicts are represented by two lines (one for each version).
Options:
`
func mainMissing(args []string) int {
f := flag.NewFlagSet("status", flag.ExitOnError)
opt_from := f.String("from", "", "Specify the source directory")
opt_to := f.String("to", "", "Specify the destination directory")
f.Usage = func() {
fmt.Print(usageMissing)
f.PrintDefaults()
}
f.Parse(args)
src, dst := findSourceDest(*opt_from, *opt_to, f.Args())
srcfiles, err := commit.ReadCommit(src)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s", src, err.Error())
}
dstfiles, err := commit.ReadCommit(dst)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s", dst, err.Error())
}
for _, s := range srcfiles.Entries {
did, hasd := dstfiles.ByPath[s.Path]
if !hasd {
fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(s.Path))
} else {
d := dstfiles.Entries[did]
if !bytes.Equal(s.Hash, d.Hash) {
fmt.Printf("- %s\t%s\n", s.HashText(), commit.EncodePath(s.Path))
fmt.Printf("+ %s\t%s\n", d.HashText(), commit.EncodePath(d.Path))
}
}
}
return 0
}