FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement file history walk in revwalk by implausible · Pull Request #889 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .cc  (1) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Vanilla git log implementation
  • Loading branch information
implausible committed Feb 3, 2016
commit 4bfba56301daf3fbc3bd2f703889ad6f92e9e27f
2 changes: 1 addition & 1 deletion generate/input/libgit2-supplement.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
},
{
"name": "out",
"type": "std::vector< std::pair<git_commit *, char *> *> *"
"type": "std::vector< std::pair<git_commit *, std::pair<char *, git_delta_t> > *> *"
},
{
"name": "walk",
Expand Down
52 changes: 26 additions & 26 deletions generate/templates/manual/revwalk/file_history_walk.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NAN_METHOD(GitRevwalk::FileHistoryWalk)
String::Utf8Value from_js_file_path(info[0]->ToString());
baton->file_path = strdup(*from_js_file_path);
baton->max_count = (unsigned int)info[1]->ToNumber()->Value();
baton->out = new std::vector< std::pair<git_commit*, char *> *>;
baton->out = new std::vector< std::pair<git_commit *, std::pair<char *, git_delta_t> > *>;
baton->out->reserve(baton->max_count);
baton->walk = Nan::ObjectWrap::Unwrap<GitRevwalk>(info.This())->GetValue();

Expand All @@ -36,8 +36,6 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
git_repository *repo = git_revwalk_repository(baton->walk);
git_oid *nextOid = (git_oid *)malloc(sizeof(git_oid));
giterr_clear();
char * trackPath = strdup(baton->file_path);
bool addedFlag = false;
for (
unsigned int i = 0;
i < baton->max_count && (baton->error_code = git_revwalk_next(nextOid, baton->walk)) == GIT_OK;
Expand All @@ -59,8 +57,10 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
git_diff *diffs;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't see these getting freed anywhere. Is this memory cleaned up?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I can't find whether or not we're supposed to clean it up or not. It would be super helpful if the docs gave me some insight

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If you know explicitly that we're supposed to clean those up, I'll free the. I've been mulling it over myself, because the docs are not clear!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

oh cool! I guess since it's explained there they don't have to explain it in the function documentation for tree to tree.

git_commit *parent;
unsigned int parents = git_commit_parentcount(nextCommit);
if (
parents >= 1) {
if (parents > 1) {
git_commit_free(nextCommit);
continue;
} else if (parents == 1) {
if ((baton->error_code = git_commit_parent(&parent, nextCommit, 0)) != GIT_OK) {
git_commit_free(nextCommit);
break;
Expand Down Expand Up @@ -95,21 +95,23 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
}

const git_diff_delta *delta = git_patch_get_delta(nextPatch);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just a quick note that we do not need to free this https://libgit2.github.com/libgit2/#v0.23.4/group/patch/git_patch_get_delta

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yea, thanks for linking this in case anyone didn't know. the delta is attached to the patch object. When we free the patch it is freed, as well.

bool isEqualOldFile = !strcmp(delta->old_file.path, trackPath);
bool isEqualNewFile = !strcmp(delta->new_file.path, trackPath);
bool isEqualOldFile = !strcmp(delta->old_file.path, baton->file_path);
bool isEqualNewFile = !strcmp(delta->new_file.path, baton->file_path);

if (isEqualNewFile) {
baton->out->push_back(
new std::pair<git_commit *, char *>(
std::pair<git_commit *, std::pair<char *, git_delta_t> > *historyEntry;
if (!isEqualOldFile) {
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
nextCommit,
std::make_pair<char *, git_delta_t>(strdup(delta->old_file.path), delta->status)
);
} else {
historyEntry = new std::pair<git_commit *, std::pair<char *, git_delta_t> >(
nextCommit,
strdup(delta->new_file.path)
));
if (delta->status == GIT_DELTA_ADDED) {
addedFlag = true;
} else if (!isEqualOldFile) {
free(trackPath);
trackPath = strdup(delta->old_file.path);
std::make_pair<char *, git_delta_t>(strdup(delta->new_file.path), delta->status)
);
}
baton->out->push_back(historyEntry);
flag = true;
}

Expand All @@ -127,13 +129,8 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()
if (baton->error_code != GIT_OK) {
break;
}

if (addedFlag) {
break;
}
}

free(trackPath);
free(nextOid);

if (baton->error_code != GIT_OK) {
Expand All @@ -142,10 +139,10 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()

while(!baton->out->empty())
{
std::pair<git_commit *, char *> *pairToFree = baton->out->back();
std::pair<git_commit *, std::pair<char *, git_delta_t> > *pairToFree = baton->out->back();
baton->out->pop_back();
git_commit_free(pairToFree->first);
free(pairToFree->second);
free(pairToFree->second.first);
free(pairToFree);
}

Expand All @@ -165,12 +162,15 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
Local<Array> result = Nan::New<Array>(size);
for (unsigned int i = 0; i < size; i++) {
Local<v8::Object> historyEntry = Nan::New<Object>();
std::pair<git_commit *, char *> *batonResult = baton->out->at(i);
std::pair<git_commit *, std::pair<char *, git_delta_t> > *batonResult = baton->out->at(i);
Nan::Set(historyEntry, Nan::New("commit").ToLocalChecked(), GitCommit::New(batonResult->first, true));
Nan::Set(historyEntry, Nan::New("name").ToLocalChecked(), Nan::New(batonResult->second).ToLocalChecked());
Nan::Set(historyEntry, Nan::New("status").ToLocalChecked(), Nan::New<Number>(batonResult->second.second));
if (batonResult->second.second == GIT_DELTA_RENAMED) {
Nan::Set(historyEntry, Nan::New("oldName").ToLocalChecked(), Nan::New(batonResult->second.first).ToLocalChecked());
}
Nan::Set(result, Nan::New<Number>(i), historyEntry);

free(batonResult->second);
free(batonResult->second.first);
free(batonResult);
}

Expand Down

Back | FazBrowse Home | New Git URL