FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/lib/commit.js at master · mildsunrise/nodegit · GitHub
mildsunrise
nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
lib
/
commit.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
161 lines (141 loc) · 3.75 KB
Breadcrumbs
nodegit
/
lib
/
commit.js
Copy path
File metadata and controls
161 lines (141 loc) · 3.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var
git
=
require
(
'../'
)
,
Commit
=
git
.
Commit
,
events
=
require
(
'events'
)
;
/**
* Retrieve the SHA.
*
@return
{
String
}
*/
Commit
.
prototype
.
sha
=
function
(
)
{
return
this
.
oid
(
)
.
sha
(
)
;
}
;
/**
* Retrieve the commit time as a unix timestamp.
*
@return
{
Number
}
*/
Commit
.
prototype
.
timeMs
=
function
(
)
{
return
this
.
time
(
)
*
1000
;
}
;
/**
* Retrieve the commit time as a Date object.
*
@return
{
Date
}
*/
Commit
.
prototype
.
date
=
function
(
)
{
return
new
Date
(
this
.
timeMs
(
)
)
;
}
;
/**
* Get the tree associated with this commit.
*
@return
{
Tree
}
*/
Commit
.
prototype
.
getTree
=
function
(
callback
)
{
this
.
repo
.
getTree
(
this
.
treeId
(
)
,
callback
)
;
}
;
/**
* Retrieve the entry represented by path for this commit.
* Path must be relative to repository root.
*
*
@param
{
String
} path
*
@param
{
Function
} callback
*
@return
{
TreeEntry
}
*/
Commit
.
prototype
.
getEntry
=
function
(
path
,
callback
)
{
this
.
getTree
(
function
(
error
,
tree
)
{
if
(
error
)
return
callback
(
error
)
;
tree
.
getEntry
(
path
,
callback
)
;
}
)
;
}
;
/**
* Walk the history from this commit backwards.
* An EventEmitter is returned that will emit a 'commit' event for each
* commit in the history, and one 'end' event when the walk is completed.
* Don't forget to call `start()` on the returned event.
*
*
@fires
Commit#commit
*
@fires
Commit#end
*
*
@return
{
EventEmitter
}
*/
Commit
.
prototype
.
history
=
function
(
)
{
var
event
=
new
events
.
EventEmitter
(
)
;
var
oid
=
this
.
oid
(
)
;
var
revwalk
=
this
.
repo
.
createRevWalk
(
)
;
revwalk
.
sorting
.
apply
(
revwalk
,
arguments
)
;
var
commits
=
[
]
;
event
.
start
=
function
(
)
{
revwalk
.
walk
(
oid
,
function
commitRevWalk
(
error
,
commit
)
{
if
(
error
)
return
event
.
emit
(
'error'
,
error
)
;
if
(
!
commit
)
{
event
.
emit
(
'end'
,
commits
)
;
return
;
}
event
.
emit
(
'commit'
,
commit
)
;
commits
.
push
(
commit
)
;
}
)
;
}
;
return
event
;
}
;
/**
* Retrieve the commit's parents -- as commit objects.
*
*
@param
{
Function
} callback
*
@return
{
[Commit]
} array of commits
*/
Commit
.
prototype
.
getParents
=
function
(
callback
)
{
var
self
=
this
;
function
processParents
(
commit
,
n
,
acc
,
callback
)
{
if
(
n
<
0
)
return
callback
(
null
,
acc
)
;
self
.
repo
.
getCommit
(
self
.
parentId
(
n
)
,
function
nextParent
(
error
,
parent
)
{
if
(
error
)
return
callback
(
error
)
;
processParents
(
parent
,
n
-
1
,
acc
.
concat
(
[
parent
]
)
,
callback
)
;
}
)
;
}
processParents
(
this
,
this
.
parentCount
(
)
-
1
,
[
]
,
callback
)
;
}
;
/**
* Retrieve the commit's parent shas.
*
*
@param
{
Function
} callback
*
@return
{
[Oid]
} array of oids
*/
Commit
.
prototype
.
parents
=
function
(
)
{
var
result
=
[
]
;
for
(
var
i
=
0
;
i
<
this
.
parentCount
(
)
;
i
++
)
{
result
.
push
(
this
.
parentId
(
i
)
)
;
}
return
result
;
}
/**
* Generate an array of diff trees showing changes between this commit
* and its parent(s).
*
*
@param
{
Function
} callback
*
@return
{
[DiffList]
} an array of difflists
*/
Commit
.
prototype
.
getDiff
=
function
(
callback
)
{
var
self
=
this
;
self
.
getParents
(
function
commitParents
(
error
,
parents
)
{
if
(
error
)
return
callback
(
error
)
;
var
parentDiffLists
=
[
]
;
parents
.
forEach
(
function
commitEachParent
(
parent
)
{
parent
.
getTree
(
function
(
error
,
parentTree
)
{
if
(
error
)
return
callback
(
error
)
;
self
.
getTree
(
function
(
error
,
thisTree
)
{
if
(
error
)
return
callback
(
error
)
;
parentTree
.
diff
(
thisTree
,
function
walkDiffList
(
error
,
diffList
)
{
if
(
error
)
return
callback
(
error
)
;
parentDiffLists
.
push
(
diffList
)
;
if
(
parentDiffLists
.
length
===
parents
.
length
)
{
callback
(
null
,
parentDiffLists
)
;
}
}
)
;
}
)
;
}
)
;
}
)
;
}
)
;
}
;
/**
* The sha of this commit
*
@return
{
String
}
*/
Commit
.
prototype
.
toString
=
function
(
)
{
return
this
.
sha
(
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL