FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/lib/tree.js at master · webjay/nodegit · GitHub
webjay
nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
lib
/
tree.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
189 lines (160 loc) · 4.16 KB
Breadcrumbs
nodegit
/
lib
/
tree.js
Copy path
File metadata and controls
189 lines (160 loc) · 4.16 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
var
path
=
require
(
"path"
)
;
var
events
=
require
(
"events"
)
;
var
NodeGit
=
require
(
"../"
)
;
var
Diff
=
NodeGit
.
Diff
;
var
LookupWrapper
=
NodeGit
.
Utils
.
lookupWrapper
;
var
Tree
=
NodeGit
.
Tree
;
var
Treebuilder
=
NodeGit
.
Treebuilder
;
/**
* Retrieves the tree pointed to by the oid
*
@async
*
@param
{
Repository
} repo The repo that the tree lives in
*
@param
{
String|Oid|Tree
} id The tree to lookup
*
@param
{
Function
} callback
*
@return
{
Tree
}
*/
Tree
.
lookup
=
LookupWrapper
(
Tree
)
;
/**
* Diff two trees
*
@async
*
@param
{
Tree
} tree to diff against
*
@param
{
Function
} callback
*
@return
{
DiffList
}
*/
Tree
.
prototype
.
diff
=
function
(
tree
,
callback
)
{
return
this
.
diffWithOptions
(
tree
,
null
,
callback
)
;
}
;
/**
* Diff two trees with options
*
@async
*
@param
{
Tree
} tree to diff against
*
@param
{
Object
} options
*
@param
{
Function
} callback
*
@return
{
DiffList
}
*/
Tree
.
prototype
.
diffWithOptions
=
function
(
tree
,
options
,
callback
)
{
return
Diff
.
treeToTree
(
this
.
repo
,
tree
,
this
,
options
)
.
then
(
function
(
diff
)
{
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
diff
)
;
}
return
diff
;
}
,
callback
)
;
}
;
/**
* Get an entry at the ith position.
*
*
@param
{
Number
} i
*
@return
{
TreeEntry
}
*/
Tree
.
prototype
.
entryByIndex
=
function
(
i
)
{
var
entry
=
this
.
_entryByIndex
(
i
)
;
entry
.
parent
=
this
;
return
entry
;
}
;
/**
* Get an entry by name; if the tree is a directory, the name is the filename.
*
*
@param
{
String
} name
*
@return
{
TreeEntry
}
*/
Tree
.
prototype
.
entryByName
=
function
(
name
)
{
var
entry
=
this
.
entryByName
(
name
)
;
entry
.
parent
=
this
;
return
entry
;
}
;
/**
* Get an entry at a path. Unlike by name, this takes a fully
* qualified path, like `/foo/bar/baz.javascript`
*
*
@param
{
String
} filePath
*
@return
{
TreeEntry
}
*/
Tree
.
prototype
.
getEntry
=
function
(
filePath
,
callback
)
{
var
tree
=
this
;
return
this
.
entryByPath
(
filePath
)
.
then
(
function
(
entry
)
{
entry
.
parent
=
tree
;
entry
.
dirtoparent
=
path
.
dirname
(
filePath
)
;
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
entry
)
;
}
return
entry
;
}
)
;
}
;
/**
* Return an array of the entries in this tree (excluding its children).
*
@return
{
Array<TreeEntry>
} an array of TreeEntrys
*/
Tree
.
prototype
.
entries
=
function
(
)
{
var
size
=
this
.
entryCount
(
)
;
var
result
=
[
]
;
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
result
.
push
(
this
.
entryByIndex
(
i
)
)
;
}
return
result
;
}
;
/**
* Recursively walk the tree in breadth-first order. Fires an event for each
* entry.
*
*
@fires
EventEmitter#entry Tree
*
@fires
EventEmitter#end Array<Tree>
*
@fires
EventEmitter#error Error
*
*
@param
{
Boolean
} [blobsOnly = true] True to emit only blob & blob executable
* entries.
*
*
@return
{
EventEmitter
}
*/
Tree
.
prototype
.
walk
=
function
(
blobsOnly
)
{
blobsOnly
=
typeof
blobsOnly
===
"boolean"
?
blobsOnly
:
true
;
var
self
=
this
;
var
event
=
new
events
.
EventEmitter
(
)
;
var
total
=
1
;
var
entries
=
new
Set
(
)
;
var
finalEntires
=
[
]
;
// This looks like a DFS, but it is a BFS because of implicit queueing in
// the recursive call to `entry.getTree(bfs)`
function
bfs
(
error
,
tree
)
{
total
--
;
if
(
error
)
{
return
event
.
emit
(
"error"
,
error
)
;
}
tree
.
entries
(
)
.
forEach
(
function
(
entry
,
entryIndex
)
{
if
(
!
blobsOnly
||
entry
.
isFile
(
)
&&
!
entries
.
has
(
entry
)
)
{
event
.
emit
(
"entry"
,
entry
)
;
entries
.
add
(
entry
)
;
// Node 0.12 doesn't support either [v for (v of entries)] nor
// Array.from so we'll just maintain our own list.
finalEntires
.
push
(
entry
)
;
}
if
(
entry
.
isTree
(
)
)
{
total
++
;
entry
.
getTree
(
bfs
)
;
}
}
)
;
if
(
total
===
0
)
{
event
.
emit
(
"end"
,
finalEntires
)
;
}
}
event
.
start
=
function
(
)
{
bfs
(
null
,
self
)
;
}
;
return
event
;
}
;
/**
* Return the path of this tree, like `/lib/foo/bar`
*
@return
{
String
}
*/
Tree
.
prototype
.
path
=
function
(
blobsOnly
)
{
return
this
.
entry
?
this
.
entry
.
path
(
)
:
""
;
}
;
/**
* Make builder. This is helpful for modifying trees.
*
@return
{
Treebuilder
}
*/
Tree
.
prototype
.
builder
=
function
(
)
{
var
builder
=
Treebuilder
.
create
(
this
)
;
builder
.
root
=
builder
;
builder
.
repo
=
this
.
repo
;
return
builder
;
}
;
Back
|
FazBrowse Home
|
New Git URL