Skip to content

Commit f4cd577

Browse files
committed
Hot fix historywalk
was dropping deleted events due to rename detection.
1 parent 743c2a4 commit f4cd577

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

generate/templates/manual/revwalk/file_history_walk.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
164164
}
165165
baton->out->push_back(historyEntry);
166166
flag = true;
167+
} else if (isEqualOldFile) {
168+
std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry;
169+
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
170+
nextCommit,
171+
std::pair<char *, git_delta_t>(strdup(delta->new_file.path), delta->status)
172+
);
173+
baton->out->push_back(historyEntry);
174+
flag = true;
167175
}
168176

169177
git_patch_free(nextPatch);
@@ -220,7 +228,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
220228
Nan::Set(historyEntry, Nan::New("commit").ToLocalChecked(), GitCommit::New(batonResult->first, true));
221229
Nan::Set(historyEntry, Nan::New("status").ToLocalChecked(), Nan::New<Number>(batonResult->second.second));
222230
if (batonResult->second.second == GIT_DELTA_RENAMED) {
223-
Nan::Set(historyEntry, Nan::New("oldName").ToLocalChecked(), Nan::New(batonResult->second.first).ToLocalChecked());
231+
Nan::Set(historyEntry, Nan::New("altname").ToLocalChecked(), Nan::New(batonResult->second.first).ToLocalChecked());
224232
}
225233
Nan::Set(result, Nan::New<Number>(i), historyEntry);
226234

lib/revwalk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Revwalk.prototype.getCommits = function(count) {
129129
* @type {Object}
130130
* @property {Commit} commit the commit for this entry
131131
* @property {Number} status the status of the file in the commit
132-
* @property {String} oldName the old name that is provided when status is
132+
* @property {String} altname the other name that is provided when status is
133133
* renamed
134134
*/
135135

test/tests/revwalk.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ describe("Revwalk", function() {
235235
var repoPath = local("../repos/renamedFileRepo");
236236
var signature = NodeGit.Signature.create("Foo bar",
237237
"foo@bar.com", 123456789, 60);
238+
var headCommit;
239+
238240
return RepoUtils.createRepository(repoPath)
239241
.then(function(r) {
240242
repo = r;
@@ -276,14 +278,25 @@ describe("Revwalk", function() {
276278
return NodeGit.Reference.nameToId(repo, "HEAD");
277279
})
278280
.then(function(commitOid) {
281+
headCommit = commitOid.tostrS();
279282
var walker = repo.createRevWalk();
280283
walker.sorting(NodeGit.Revwalk.SORT.TIME);
281284
walker.push(commitOid.tostrS());
282285
return walker.fileHistoryWalk(fileNameB, 5);
283286
})
284287
.then(function(results) {
285288
assert.equal(results[0].status, NodeGit.Diff.DELTA.RENAMED);
286-
assert.equal(results[0].oldName, fileNameA);
289+
assert.equal(results[0].altname, fileNameA);
290+
})
291+
.then(function() {
292+
var walker = repo.createRevWalk();
293+
walker.sorting(NodeGit.Revwalk.SORT.TIME);
294+
walker.push(headCommit);
295+
return walker.fileHistoryWalk(fileNameA, 5);
296+
})
297+
.then(function(results) {
298+
assert.equal(results[0].status, NodeGit.Diff.DELTA.RENAMED);
299+
assert.equal(results[0].altname, fileNameB);
287300
})
288301
.then(function() {
289302
return fse.remove(repoPath);

0 commit comments

Comments
 (0)