Skip to content

Commit 5fce0c9

Browse files
author
spacedragon
committed
support file history for dir
1 parent 3c74b8e commit 5fce0c9

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

generate/templates/manual/revwalk/file_history_walk.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
104104
}
105105

106106
const git_diff_delta *delta = git_patch_get_delta(nextPatch);
107-
bool isEqualOldFile = !strcmp(delta->old_file.path, baton->file_path);
108-
bool isEqualNewFile = !strcmp(delta->new_file.path, baton->file_path);
107+
bool isEqualOldFile = !strncmp(delta->old_file.path, baton->file_path, strlen(baton->file_path));
108+
bool isEqualNewFile = !strncmp(delta->new_file.path, baton->file_path, strlen(baton->file_path));
109109

110110
if (isEqualNewFile) {
111111
if (delta->status == GIT_DELTA_ADDED || delta->status == GIT_DELTA_DELETED) {
@@ -173,8 +173,8 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
173173
}
174174

175175
const git_diff_delta *delta = git_patch_get_delta(nextPatch);
176-
bool isEqualOldFile = !strcmp(delta->old_file.path, baton->file_path);
177-
bool isEqualNewFile = !strcmp(delta->new_file.path, baton->file_path);
176+
bool isEqualOldFile = !strncmp(delta->old_file.path, baton->file_path, strlen(baton->file_path));
177+
bool isEqualNewFile = !strncmp(delta->new_file.path, baton->file_path, strlen(baton->file_path));
178178
int oldLen = strlen(delta->old_file.path);
179179
int newLen = strlen(delta->new_file.path);
180180
char *outPair = new char[oldLen + newLen + 2];
@@ -185,7 +185,7 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
185185

186186
if (isEqualNewFile) {
187187
std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry;
188-
if (!isEqualOldFile) {
188+
if (!isEqualOldFile || delta ->status == GIT_DELTA_RENAMED) {
189189
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
190190
nextCommit,
191191
std::pair<char *, git_delta_t>(strdup(outPair), delta->status)

test/tests/revwalk.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,36 @@ describe("Revwalk", function() {
181181
});
182182
});
183183

184+
it("can get the history of a dir", function() {
185+
var test = this;
186+
var magicShas = [
187+
"6ed3027eda383d417457b99b38c73f88f601c368",
188+
"95cefff6aabd3c1f6138ec289f42fec0921ff610",
189+
"7ad92a7e4d26a1af93f3450aea8b9d9b8069ea8c",
190+
"96f077977eb1ffcb63f9ce766cdf110e9392fdf5",
191+
"694adc5369687c47e02642941906cfc5cb21e6c2",
192+
"eebd0ead15d62eaf0ba276da53af43bbc3ce43ab",
193+
"1273fff13b3c28cfdb13ba7f575d696d2a8902e1",
194+
"271c65ed16ab147cee715e1076e1d716156cc5a3",
195+
"94d532004323641fd169f375869c36a82b32fac7",
196+
"1c71929a905da9faab64472d53815d46ff4391dd",
197+
"3947245612ae27077517038704b7a679e742658e",
198+
"a44c81558d0f72ccf6c1facbe2ba0b9b711586a9",
199+
"01d469416b26340ee4922d5171ef8dbe46c879f4"
200+
];
201+
202+
return test.walker.fileHistoryWalk("include/functions", 1000)
203+
.then(function(results) {
204+
var shas = results.map(function(result) {
205+
return result.commit.sha();
206+
});
207+
assert.equal(magicShas.length, shas.length);
208+
magicShas.forEach(function(sha, i) {
209+
assert.equal(sha, shas[i]);
210+
});
211+
});
212+
});
213+
184214
it("can get the history of a file while ignoring parallel branches",
185215
function() {
186216
var test = this;

0 commit comments

Comments
 (0)