-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.go
68 lines (53 loc) · 1.25 KB
/
diff.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
package main
import (
"fmt"
"os"
"path"
"github.com/go-enry/go-enry/v2"
)
type IntIntPair struct {
lines int
bytes int
}
type Diff struct {
File string
Added IntIntPair
Removed IntIntPair
}
func (diff Diff) should_skip(repo *Repo) bool {
if stored, ok := repo.FileSkipMap[diff.File]; ok {
return stored
}
ret := false
fpath := path.Join(repo.Path, diff.File)
fe := file_exists(fpath)
sy := fe && is_symlink(fpath)
di := fe && is_directory(fpath)
if !fe || sy || di {
log(Info, repo, fmt.Sprintf("Skipping path %s, exists: %t, symlink: %t, dir: %t", fpath, fe, sy, di))
// If the file doesn't exist, keep checking because sometimes it shows
// up later?? May have to do with renames...
return true
} else if repo.skip_file_name(diff.File) {
ret = true
} else {
data, err := os.ReadFile(fpath)
check(err)
if repo.skip_file_data(diff.File, data) {
ret = true
}
}
repo.FileSkipMap[diff.File] = ret
return ret
}
func (diff Diff) get_languages(repo *Repo) []string {
if stored, ok := repo.FileLangMap[diff.File]; ok {
return stored
}
fpath := path.Join(repo.Path, diff.File)
data, err := os.ReadFile(fpath)
check(err)
langs := enry.GetLanguages(diff.File, data)
repo.FileLangMap[diff.File] = langs
return langs
}