-
-
Notifications
You must be signed in to change notification settings - Fork 479
/
rcs.go
67 lines (52 loc) · 1.68 KB
/
rcs.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
package backend
import (
"context"
"fmt"
"time"
"github.com/gopasspw/gopass/pkg/debug"
)
// rcs is a revision control backend.
type rcs interface {
Add(ctx context.Context, args ...string) error
Commit(ctx context.Context, msg string) error
Push(ctx context.Context, remote, location string) error
Pull(ctx context.Context, remote, location string) error
TryAdd(ctx context.Context, args ...string) error
TryCommit(ctx context.Context, msg string) error
TryPush(ctx context.Context, remote, location string) error
InitConfig(ctx context.Context, name, email string) error
AddRemote(ctx context.Context, remote, location string) error
RemoveRemote(ctx context.Context, remote string) error
Revisions(ctx context.Context, name string) ([]Revision, error)
GetRevision(ctx context.Context, name, revision string) ([]byte, error)
Status(ctx context.Context) ([]byte, error)
Compact(ctx context.Context) error
}
// Revision is a SCM revision.
type Revision struct {
Hash string
AuthorName string
AuthorEmail string
Date time.Time
Subject string
Body string
}
// Revisions implements the sort interface.
type Revisions []Revision
func (r Revisions) Len() int {
return len(r)
}
func (r Revisions) Less(i, j int) bool {
return r[i].Date.After(r[j].Date)
}
func (r Revisions) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}
// Clone clones an existing repository from a remote.
func Clone(ctx context.Context, id StorageBackend, repo, path string) (Storage, error) {
if be, err := StorageRegistry.Get(id); err == nil {
debug.Log("Cloning with %s", be.String())
return be.Clone(ctx, repo, path)
}
return nil, fmt.Errorf("unknown backend %d: %w", id, ErrNotFound)
}