Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
188 lines (171 loc) · 4.53 KB

File metadata and controls

188 lines (171 loc) · 4.53 KB
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
var git = require( '../' ),
events = require( 'events' );
/**
* Apply given details to the context.
*
* @param {Object} details
* @param {Object} context
* @return {Object} The modified context.
*/
function applyDetails(details, context) {
if (details) {
for (var detailKey in details) {
context[detailKey] = details[detailKey];
}
}
return context;
}
/**
* Convenience commit constructor.
*
* @param {RawCommit|Null} rawCommit
* @return {Commit}
*/
var _Commit = function(rawCommit) {
var self = {};
if(rawCommit && rawCommit instanceof git.raw.Commit) {
self.commit = rawCommit;
} else {
self.commit = new git.raw.Commit();
}
/**
* Fetch the commit's details asynchronously.
*
* @param {Function} callback
*/
self.fetchDetails = function(callback) {
var error = null;
self.commit.fetchDetails(function(error, details) {
if (error) {
error = git.error(error);
}
applyDetails(details, self);
callback(error);
});
};
/**
* Fetch the commit's details synchronously.
*/
self.fetchDetailsSync = function(callback) {
var details = self.commit.fetchDetailsSync();
return applyDetails(details, self);
};
/**
* Look up the commit referenced by oid, replace self.commit
* with the result.
*
* @param {Repo} repo
* @param {Oid|String} oid Raw OID object or SHA string
* @param {Function} callback
*/
self.lookup = function(repo, oid, callback) {
self.repo = repo;
self.commit.lookup(repo, oid, function(error, commit) {
if (error) {
callback(git.error(error), null);
return;
}
self.commit = commit;
self.fetchDetails(function(error) {
if (error) {
callback(git.error(error), null);
return;
}
callback(null, self);
});
});
};
self.tree = function() {
var tree = new git.raw.Tree(self.repo);
if(tree.error) {
return git.error(tree.error);
} else {
self.commit.tree(tree);
}
return git.tree(self.repo, tree);
};
self.file = function(path) {
return self.tree().entry(path);
};
/**
* Walk the history of this commit.
*
* @return {Event} Event emits 'commit', with error, commit and 'end', with
* error, commits[]
*/
self.history = function() {
var revwalk = git.revwalk(self.repo),
event = new events.EventEmitter(),
commits = [];
revwalk.walk(self.id, function(error, index, commit, noMoreCommits) {
if(error) {
event.emit('end', error, commits);
return false;
}
if (noMoreCommits) {
event.emit('end', null, commits);
return;
}
event.emit('commit', null, commit);
commits.push(commit);
});
return event;
};
/**
* Retrieve the commit's parent at the given position asynchronously.
*
* @param {Integer} position
*/
self.parent = function(position, callback) {
var parent = null;
self.commit.parent(position, function processParent(errorCode, parent) {
var error = null;
if (errorCode) {
error = git.error(errorCode);
return callback(error, null);
}
var parentCommit = new _Commit(parent);
parentCommit.fetchDetails(function returnParent(error) {
callback(error, parentCommit);
});
});
};
/**
* Retrieve the commit's parent at the given positino synchronously.
*
* @param {Integer} position
* @return {Commit}
*/
self.parentSync = function(position) {
var parent = new _Commit(self.commit.parentSync(position));
return parent.fetchDetailsSync();
};
/**
* Get a diff tree showing changes between this commit and its parent(s).
* Assumes commit has been populated with fetchDetails|fetchDetailsSync
*
* @param {Function} callback Called with error (null if no error) and the
* diff tree
*/
self.parentsDiffTrees = function(callback) {
if (!self.parentCount) {
callback(null, {});
return;
}
var parentDiffLists = [];
self.parentShas.forEach(function eachParentSha(parentSha) {
git.diffList(self.repo).treeToTree(parentSha, self.sha, function walkDiffList(error, diffList) {
if (error) {
callback(error, null);
return;
}
parentDiffLists.push(diffList);
if (parentDiffLists.length === self.parentShas.length) {
callback(null, parentDiffLists);
}
});
});
};
return self;
};
exports.commit = _Commit;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.