summaryrefslogtreecommitdiff
path: root/src/diff_file.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-03-25 09:14:48 -0700
committerRussell Belfer <rb@github.com>2014-03-25 09:14:48 -0700
commita15c7802c86cf995fa658ef0624c46d352ce9a81 (patch)
tree25bebc086059abc13e74a3a8b4e461c0cf06dc64 /src/diff_file.c
parentf210cb5b1442f82e2f930909d8430f7cc6661c5f (diff)
downloadlibgit2-a15c7802c86cf995fa658ef0624c46d352ce9a81.tar.gz
Make submodules externally refcounted
`git_submodule` objects were already refcounted internally in case the submodule name was different from the path at which it was stored. This makes that refcounting externally used as well, so `git_submodule_lookup` and `git_submodule_add_setup` return an object that requires a `git_submodule_free` when done.
Diffstat (limited to 'src/diff_file.c')
-rw-r--r--src/diff_file.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/diff_file.c b/src/diff_file.c
index 7dabf8d6f..2f3f797c5 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -177,11 +177,17 @@ static int diff_file_content_commit_to_str(
unsigned int sm_status = 0;
const git_oid *sm_head;
- if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0 ||
- (error = git_submodule_status(&sm_status, sm)) < 0) {
+ if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) {
/* GIT_EEXISTS means a "submodule" that has not been git added */
- if (error == GIT_EEXISTS)
+ if (error == GIT_EEXISTS) {
+ giterr_clear();
error = 0;
+ }
+ return error;
+ }
+
+ if ((error = git_submodule_status(&sm_status, sm)) < 0) {
+ git_submodule_free(sm);
return error;
}
@@ -196,6 +202,8 @@ static int diff_file_content_commit_to_str(
if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
status = "-dirty";
+
+ git_submodule_free(sm);
}
git_oid_tostr(oid, sizeof(oid), &fc->file->id);