forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_get_commit.go
60 lines (56 loc) · 1.9 KB
/
cataloger_get_commit.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
package catalog
import (
"context"
"github.com/treeverse/lakefs/db"
)
func (c *cataloger) GetCommit(ctx context.Context, repository, reference string) (*CommitLog, error) {
if err := Validate(ValidateFields{
{Name: "repository", IsValid: ValidateRepositoryName(repository)},
{Name: "reference", IsValid: ValidateReference(reference)},
}); err != nil {
return nil, err
}
ref, err := ParseRef(reference)
if err != nil {
return nil, err
}
res, err := c.db.Transact(func(tx db.Tx) (interface{}, error) {
branchID, err := c.getBranchIDCache(tx, repository, ref.Branch)
if err != nil {
return nil, err
}
query := `SELECT b.name as branch_name,c.commit_id,c.previous_commit_id,c.committer,c.message,c.creation_date,c.metadata,
COALESCE(bb.name,'') as merge_source_branch_name,COALESCE(c.merge_source_commit,0) as merge_source_commit
FROM catalog_commits c JOIN catalog_branches b ON b.id = c.branch_id
LEFT JOIN catalog_branches bb ON bb.id = c.merge_source_branch
WHERE b.id=$1 AND c.commit_id=$2`
var rawCommit commitLogRaw
if err := tx.Get(&rawCommit, query, branchID, ref.CommitID); err != nil {
return nil, err
}
commit := convertRawCommit(&rawCommit)
return commit, nil
}, c.txOpts(ctx, db.ReadOnly())...)
if err != nil {
return nil, err
}
return res.(*CommitLog), err
}
func convertRawCommit(raw *commitLogRaw) *CommitLog {
c := &CommitLog{
Reference: MakeReference(raw.BranchName, raw.CommitID),
Committer: raw.Committer,
Message: raw.Message,
CreationDate: raw.CreationDate,
Metadata: raw.Metadata,
}
if raw.MergeSourceBranchName != "" && raw.MergeSourceCommit > 0 {
reference := MakeReference(raw.MergeSourceBranchName, raw.MergeSourceCommit)
c.Parents = append(c.Parents, reference)
}
if raw.PreviousCommitID > 0 {
reference := MakeReference(raw.BranchName, raw.PreviousCommitID)
c.Parents = append(c.Parents, reference)
}
return c
}