Only create diff options when necessary

This commit is contained in:
Kevin Sawicki 2012-12-27 10:53:13 -08:00
parent d3ed0fca27
commit a561d5efab

View File

@ -114,17 +114,6 @@ public:
return CefV8Value::CreateNull(); return CefV8Value::CreateNull();
} }
char *copiedPath = (char *)malloc(sizeof(char) * (strlen(path) + 1));
strcpy(copiedPath, path);
git_diff_options options;
memset(&options, 0, sizeof(options));
git_strarray paths;
paths.count = 1;
paths.strings = &copiedPath;
options.pathspec = paths;
options.context_lines = 1;
options.flags = GIT_DIFF_DISABLE_PATHSPEC_MATCH;
git_reference *head; git_reference *head;
if (git_repository_head(&head, repo) != GIT_OK) { if (git_repository_head(&head, repo) != GIT_OK) {
return CefV8Value::CreateNull(); return CefV8Value::CreateNull();
@ -145,6 +134,17 @@ public:
return CefV8Value::CreateNull(); return CefV8Value::CreateNull();
} }
char *copiedPath = (char *)malloc(sizeof(char) * (strlen(path) + 1));
strcpy(copiedPath, path);
git_diff_options options;
memset(&options, 0, sizeof(options));
git_strarray paths;
paths.count = 1;
paths.strings = &copiedPath;
options.pathspec = paths;
options.context_lines = 1;
options.flags = GIT_DIFF_DISABLE_PATHSPEC_MATCH;
git_diff_list *diffs; git_diff_list *diffs;
int diffStatus = git_diff_workdir_to_tree(repo, &options, tree, &diffs); int diffStatus = git_diff_workdir_to_tree(repo, &options, tree, &diffs);
if (diffStatus != GIT_OK) { if (diffStatus != GIT_OK) {