| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| 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; | ||
| 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); | ||
|
Comment thread
Copy link
Copy Markdown
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityJust 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
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYea, 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.
Sorry, something went wrong.
All reactions
|
||
| 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 |
There was a problem hiding this comment.
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 QualityI don't see these getting freed anywhere. Is this memory cleaned up?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 QualityI 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 QualityIf 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!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 QualityYes we do need to free it: https://github.com/libgit2/libgit2/blob/v0.23.4/include/git2/diff.h#L23-L28
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 Qualityoh cool! I guess since it's explained there they don't have to explain it in the function documentation for tree to tree.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.