File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,35 @@ type Commit struct {
24
24
// submodules map[string]*SubModule
25
25
}
26
26
27
+ // ParentID returns oid of n-th parent (0-based index).
28
+ // It returns nil if no such parent exists.
29
+ func (c * Commit ) ParentID (n int ) (sha1 , error ) {
30
+ if n >= len (c .parents ) {
31
+ return sha1 {}, ErrNotExist {"" , "" }
32
+ }
33
+ return c .parents [n ], nil
34
+ }
35
+
36
+ // Parent returns n-th parent (0-based index) of the commit.
37
+ func (c * Commit ) Parent (n int ) (* Commit , error ) {
38
+ id , err := c .ParentID (n )
39
+ if err != nil {
40
+ return nil , err
41
+ }
42
+ parent , err := c .repo .getCommit (id )
43
+ if err != nil {
44
+ return nil , err
45
+ }
46
+ return parent , nil
47
+ }
48
+
49
+ // ParentCount returns number of parents of the commit.
50
+ // 0 if this is the root commit, otherwise 1,2, etc.
51
+ func (c * Commit ) ParentCount () int {
52
+ return len (c .parents )
53
+ }
54
+
55
+ // GetCommitOfRelPath return the commit of relative path object.
27
56
func (c * Commit ) GetCommitOfRelPath (relpath string ) (* Commit , error ) {
28
57
return c .repo .getCommitOfRelPath (c .ID , relpath )
29
58
}
You can’t perform that action at this time.
0 commit comments