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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package git
/*
#include <git2.h>
#include <git2/errors.h>
*/
import "C"
import (
"runtime"
)
type Status int
const (
StatusCurrent Status = C.GIT_STATUS_CURRENT
StatusIndexNew = C.GIT_STATUS_INDEX_NEW
StatusIndexModified = C.GIT_STATUS_INDEX_MODIFIED
StatusIndexDeleted = C.GIT_STATUS_INDEX_DELETED
StatusIndexRenamed = C.GIT_STATUS_INDEX_RENAMED
StatusIndexTypeChange = C.GIT_STATUS_INDEX_TYPECHANGE
StatusWtNew = C.GIT_STATUS_WT_NEW
StatusWtModified = C.GIT_STATUS_WT_NEW
StatusWtDeleted = C.GIT_STATUS_WT_DELETED
StatusWtTypeChange = C.GIT_STATUS_WT_TYPECHANGE
StatusWtRenamed = C.GIT_STATUS_WT_RENAMED
StatusIgnored = C.GIT_STATUS_IGNORED
)
type StatusEntry struct {
Status Status
HeadToIndex DiffDelta
IndexToWorkdir DiffDelta
}
func statusEntryFromC(statusEntry *C.git_status_entry) StatusEntry {
return StatusEntry {
Status: Status(statusEntry.status),
HeadToIndex: diffDeltaFromC(statusEntry.head_to_index),
IndexToWorkdir: diffDeltaFromC(statusEntry.index_to_workdir),
}
}
type StatusList struct {
ptr *C.git_status_list
}
func newStatusListFromC(ptr *C.git_status_list) *StatusList {
if ptr == nil {
return nil
}
statusList := &StatusList{
ptr: ptr,
}
runtime.SetFinalizer(statusList, (*StatusList).Free)
return statusList
}
func (statusList *StatusList) Free() error {
if statusList.ptr == nil {
return ErrInvalid
}
runtime.SetFinalizer(statusList, nil)
C.git_status_list_free(statusList.ptr)
statusList.ptr = nil
return nil
}
func (statusList *StatusList) ByIndex(index int) (StatusEntry, error) {
if statusList.ptr == nil {
return StatusEntry{}, ErrInvalid
}
ptr := C.git_status_byindex(statusList.ptr, C.size_t(index))
return statusEntryFromC(ptr), nil
}
func (statusList *StatusList) EntryCount() (int, error) {
if statusList.ptr == nil {
return -1, ErrInvalid
}
return int(C.git_status_list_entrycount(statusList.ptr)), nil
}
|