| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,10 @@ void GitRevwalk::FileHistoryWalkWorker::Execute() | |||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | git_diff *diffs; | |
| 58 | + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; | ||
| 59 | + char *file_path = strdup(baton->file_path); | ||
| 60 | + opts.pathspec.strings = &file_path; | ||
| 61 | + opts.pathspec.count = 1; | ||
| 58 | 62 | git_commit *parent; | |
| 59 | 63 | unsigned int parents = git_commit_parentcount(nextCommit); | |
| 60 | 64 | if (parents > 1) { | |
@@ -67,19 +71,23 @@ void GitRevwalk::FileHistoryWalkWorker::Execute() | |||
| 67 | 71 | } | |
| 68 | 72 | if ( | |
| 69 | 73 | (baton->error_code = git_commit_tree(&parentTree, parent)) != GIT_OK || | |
| 70 | - (baton->error_code = git_diff_tree_to_tree(&diffs, repo, parentTree, thisTree, NULL)) != GIT_OK | ||
| 74 | + (baton->error_code = git_diff_tree_to_tree(&diffs, repo, parentTree, thisTree, &opts)) != GIT_OK | ||
| 71 | 75 | ) { | |
| 72 | 76 | git_commit_free(nextCommit); | |
| 73 | 77 | git_commit_free(parent); | |
| 74 | 78 | break; | |
| 75 | 79 | } | |
| 76 | 80 | } else { | |
| 77 | - if ((baton->error_code = git_diff_tree_to_tree(&diffs, repo, NULL, thisTree, NULL)) != GIT_OK) { | ||
| 81 | + if ((baton->error_code = git_diff_tree_to_tree(&diffs, repo, NULL, thisTree, &opts)) != GIT_OK) { | ||
| 78 | 82 | git_commit_free(nextCommit); | |
| 79 | 83 | break; | |
| 80 | 84 | } | |
| 81 | 85 | } | |
| 82 | 86 | ||
| 87 | + free(file_path); | ||
| 88 | + opts.pathspec.strings = NULL; | ||
| 89 | + opts.pathspec.count = 0; | ||
| 90 | + | ||
| 83 | 91 | bool flag = false; | |
| 84 | 92 | bool doRenamedPass = false; | |
| 85 | 93 | unsigned int numDeltas = git_diff_num_deltas(diffs); | |
@@ -127,10 +135,29 @@ void GitRevwalk::FileHistoryWalkWorker::Execute() | |||
| 127 | 135 | } | |
| 128 | 136 | } | |
| 129 | 137 | ||
| 130 | - if ( | ||
| 131 | - doRenamedPass && | ||
| 132 | - (baton->error_code = git_diff_find_similar(diffs, NULL)) == GIT_OK | ||
| 133 | - ) { | ||
| 138 | + if (doRenamedPass) { | ||
| 139 | + git_diff_free(diffs); | ||
| 140 | + | ||
| 141 | + if (parents == 1) { | ||
| 142 | + if ((baton->error_code = git_diff_tree_to_tree(&diffs, repo, parentTree, thisTree, NULL)) != GIT_OK) { | ||
| 143 | + git_commit_free(nextCommit); | ||
| 144 | + break; | ||
| 145 | + } | ||
| 146 | + if ((baton->error_code = git_diff_find_similar(diffs, NULL)) != GIT_OK) { | ||
| 147 | + git_commit_free(nextCommit); | ||
| 148 | + break; | ||
| 149 | + } | ||
| 150 | + } else { | ||
| 151 | + if ((baton->error_code = git_diff_tree_to_tree(&diffs, repo, NULL, thisTree, NULL)) != GIT_OK) { | ||
| 152 | + git_commit_free(nextCommit); | ||
| 153 | + break; | ||
| 154 | + } | ||
| 155 | + if((baton->error_code = git_diff_find_similar(diffs, NULL)) != GIT_OK) { | ||
| 156 | + git_commit_free(nextCommit); | ||
| 157 | + break; | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + | ||
| 134 | 161 | flag = false; | |
| 135 | 162 | numDeltas = git_diff_num_deltas(diffs); | |
| 136 | 163 | for (unsigned int j = 0; j < numDeltas; ++j) { | |
@@ -148,13 +175,20 @@ void GitRevwalk::FileHistoryWalkWorker::Execute() | |||
| 148 | 175 | const git_diff_delta *delta = git_patch_get_delta(nextPatch); | |
| 149 | 176 | bool isEqualOldFile = !strcmp(delta->old_file.path, baton->file_path); | |
| 150 | 177 | 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); | ||
| 151 | 185 | ||
| 152 | 186 | if (isEqualNewFile) { | |
| 153 | 187 | std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry; | |
| 154 | 188 | if (!isEqualOldFile) { | |
| 155 | 189 | historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >( | |
| 156 | 190 | nextCommit, | |
| 157 | - std::pair<char *, git_delta_t>(strdup(delta->old_file.path), delta->status) | ||
| 191 | + std::pair<char *, git_delta_t>(strdup(outPair), delta->status) | ||
| 158 | 192 | ); | |
| 159 | 193 | } else { | |
| 160 | 194 | historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >( | |
@@ -168,12 +202,14 @@ void GitRevwalk::FileHistoryWalkWorker::Execute() | |||
| 168 | 202 | std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry; | |
| 169 | 203 | historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >( | |
| 170 | 204 | nextCommit, | |
| 171 | - std::pair<char *, git_delta_t>(strdup(delta->new_file.path), delta->status) | ||
| 205 | + std::pair<char *, git_delta_t>(strdup(outPair), delta->status) | ||
| 172 | 206 | ); | |
| 173 | 207 | baton->out->push_back(historyEntry); | |
| 174 | 208 | flag = true; | |
| 175 | 209 | } | |
| 176 | 210 | ||
| 211 | + delete[] outPair; | ||
| 212 | + | ||
| 177 | 213 | git_patch_free(nextPatch); | |
| 178 | 214 | ||
| 179 | 215 | if (flag) { | |
@@ -228,7 +264,13 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback() | |||
| 228 | 264 | Nan::Set(historyEntry, Nan::New("commit").ToLocalChecked(), GitCommit::New(batonResult->first, true)); | |
| 229 | 265 | Nan::Set(historyEntry, Nan::New("status").ToLocalChecked(), Nan::New<Number>(batonResult->second.second)); | |
| 230 | 266 | if (batonResult->second.second == GIT_DELTA_RENAMED) { | |
| 231 | - 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()); | ||
| 232 | 274 | } | |
| 233 | 275 | Nan::Set(result, Nan::New<Number>(i), historyEntry); | |
| 234 | 276 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,7 +129,9 @@ Revwalk.prototype.getCommits = function(count) { | |||
| 129 | 129 | * @type {Object} | |
| 130 | 130 | * @property {Commit} commit the commit for this entry | |
| 131 | 131 | * @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 | ||
| 133 | 135 | * renamed | |
| 134 | 136 | */ | |
| 135 | 137 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -286,7 +286,8 @@ describe("Revwalk", function() { | |||
| 286 | 286 | }) | |
| 287 | 287 | .then(function(results) { | |
| 288 | 288 | 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); | ||
| 290 | 291 | }) | |
| 291 | 292 | .then(function() { | |
| 292 | 293 | var walker = repo.createRevWalk(); | |
@@ -296,7 +297,8 @@ describe("Revwalk", function() { | |||
| 296 | 297 | }) | |
| 297 | 298 | .then(function(results) { | |
| 298 | 299 | 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); | ||
| 300 | 302 | }) | |
| 301 | 303 | .then(function() { | |
| 302 | 304 | return fse.remove(repoPath); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments