Skip to content

Commit d23ba87

Browse files
committed
Provide old and new name instead of just altname
1 parent c2f6d81 commit d23ba87

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

generate/templates/manual/revwalk/file_history_walk.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,20 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
175175
const git_diff_delta *delta = git_patch_get_delta(nextPatch);
176176
bool isEqualOldFile = !strcmp(delta->old_file.path, baton->file_path);
177177
bool isEqualNewFile = !strcmp(delta->new_file.path, baton->file_path);
178+
int oldLen = strlen(delta->old_file.path);
179+
int newLen = strlen(delta->new_file.path);
180+
char *outPair = new char[oldLen + newLen + 2];
181+
strcpy(outPair, delta->new_file.path);
182+
outPair[newLen] = '\n';
183+
outPair[newLen + 1] = '\0';
184+
strcat(outPair, delta->old_file.path);
178185

179186
if (isEqualNewFile) {
180187
std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry;
181188
if (!isEqualOldFile) {
182189
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
183190
nextCommit,
184-
std::pair<char *, git_delta_t>(strdup(delta->old_file.path), delta->status)
191+
std::pair<char *, git_delta_t>(strdup(outPair), delta->status)
185192
);
186193
} else {
187194
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
@@ -195,12 +202,14 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
195202
std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry;
196203
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
197204
nextCommit,
198-
std::pair<char *, git_delta_t>(strdup(delta->new_file.path), delta->status)
205+
std::pair<char *, git_delta_t>(strdup(outPair), delta->status)
199206
);
200207
baton->out->push_back(historyEntry);
201208
flag = true;
202209
}
203210

211+
delete[] outPair;
212+
204213
git_patch_free(nextPatch);
205214

206215
if (flag) {
@@ -255,7 +264,13 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
255264
Nan::Set(historyEntry, Nan::New("commit").ToLocalChecked(), GitCommit::New(batonResult->first, true));
256265
Nan::Set(historyEntry, Nan::New("status").ToLocalChecked(), Nan::New<Number>(batonResult->second.second));
257266
if (batonResult->second.second == GIT_DELTA_RENAMED) {
258-
Nan::Set(historyEntry, Nan::New("altname").ToLocalChecked(), Nan::New(batonResult->second.first).ToLocalChecked());
267+
char *namePair = batonResult->second.first;
268+
char *split = strchr(namePair, '\n');
269+
*split = '\0';
270+
char *oldName = split + 1;
271+
272+
Nan::Set(historyEntry, Nan::New("oldName").ToLocalChecked(), Nan::New(oldName).ToLocalChecked());
273+
Nan::Set(historyEntry, Nan::New("newName").ToLocalChecked(), Nan::New(namePair).ToLocalChecked());
259274
}
260275
Nan::Set(result, Nan::New<Number>(i), historyEntry);
261276

lib/revwalk.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ 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} altname the other name that is provided when status is
132+
* @property {String} newName the new name that is provided when status is
133+
* renamed
134+
* @property {String} oldName the old name that is provided when status is
133135
* renamed
134136
*/
135137

test/tests/revwalk.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ describe("Revwalk", function() {
286286
})
287287
.then(function(results) {
288288
assert.equal(results[0].status, NodeGit.Diff.DELTA.RENAMED);
289-
assert.equal(results[0].altname, fileNameA);
289+
assert.equal(results[0].newName, fileNameB);
290+
assert.equal(results[0].oldName, fileNameA);
290291
})
291292
.then(function() {
292293
var walker = repo.createRevWalk();
@@ -296,7 +297,8 @@ describe("Revwalk", function() {
296297
})
297298
.then(function(results) {
298299
assert.equal(results[0].status, NodeGit.Diff.DELTA.RENAMED);
299-
assert.equal(results[0].altname, fileNameB);
300+
assert.equal(results[0].newName, fileNameB);
301+
assert.equal(results[0].oldName, fileNameA);
300302
})
301303
.then(function() {
302304
return fse.remove(repoPath);

0 commit comments

Comments
 (0)