This repository was archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit.go
54 lines (46 loc) · 1.51 KB
/
git.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
// Copyright 2018 IBM Corporation
// Licensed under the Apache License, Version 2.0. See LICENSE file.
package record
import (
"fmt"
"github.com/IBM/binprint/hash"
)
// GitRepoSource is a container representation of a git commit of a repository
type GitRepoSource struct {
Commit hash.GitShaDigest
Tag string `yaml:",omitempty"`
Branch string `yaml:",omitempty"`
URL string `yaml:",omitempty"`
Files []*File `yaml:",omitempty"`
embeddedCacheID `yaml:"-"`
}
// SerializedGitRepo is an alternative form of GitRepoSource that uses numeric IDs instead of pointers
type SerializedGitRepo struct {
ID uint64
Commit hash.GitShaDigest
Tag string `yaml:",omitempty"`
Branch string `yaml:",omitempty"`
URL string `yaml:",omitempty"`
Files []uint64 `yaml:",omitempty"`
}
// URN is a self-describing unique identifier for a specific commit of a
// specific repository.
func (r GitRepoSource) URN() string {
return fmt.Sprintf("urn:x-fp:git:%s:%s:%s", r.Commit.String(), r.Branch, r.Tag)
}
// Find returns a list of Files contained in the git repo that match the
// provided fingerprint.
func (r GitRepoSource) Find(i *Fingerprint) []*File {
hits := []*File{}
for _, f := range r.Files {
// log.Printf("Comparing %s to %s\n", f.Name(), i.Name())
if f.Is(i) {
hits = append(hits, f)
}
}
return hits
}
// RecordBlob records the given file as being part of this repo@commit
func (r *GitRepoSource) RecordBlob(f *File) {
r.Files = append(r.Files, f)
}