diff options
author | Russell Belfer <rb@github.com> | 2014-03-25 09:14:48 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-03-25 09:14:48 -0700 |
commit | a15c7802c86cf995fa658ef0624c46d352ce9a81 (patch) | |
tree | 25bebc086059abc13e74a3a8b4e461c0cf06dc64 /src/checkout.c | |
parent | f210cb5b1442f82e2f930909d8430f7cc6661c5f (diff) | |
download | libgit2-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/checkout.c')
-rw-r--r-- | src/checkout.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/checkout.c b/src/checkout.c index f882f3593..da9e5a12d 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -147,19 +147,23 @@ static bool checkout_is_workdir_modified( git_submodule *sm; unsigned int sm_status = 0; const git_oid *sm_oid = NULL; + bool rval = false; - if (git_submodule_lookup(&sm, data->repo, wditem->path) < 0 || - git_submodule_status(&sm_status, sm) < 0) - return true; - - if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status)) + if (git_submodule_lookup(&sm, data->repo, wditem->path) < 0) { + giterr_clear(); return true; + } - sm_oid = git_submodule_wd_id(sm); - if (!sm_oid) - return false; + if (git_submodule_status(&sm_status, sm) < 0 || + GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status)) + rval = true; + else if ((sm_oid = git_submodule_wd_id(sm)) == NULL) + rval = false; + else + rval = (git_oid__cmp(&baseitem->id, sm_oid) != 0); - return (git_oid__cmp(&baseitem->id, sm_oid) != 0); + git_submodule_free(sm); + return rval; } /* Look at the cache to decide if the workdir is modified. If not, @@ -1510,7 +1514,7 @@ static int checkout_create_submodules( /* initial reload of submodules if .gitmodules was changed */ if (data->reload_submodules && - (error = git_submodule_reload_all(data->repo)) < 0) + (error = git_submodule_reload_all(data->repo, 1)) < 0) return error; git_vector_foreach(&data->diff->deltas, i, delta) { @@ -1534,7 +1538,7 @@ static int checkout_create_submodules( } /* final reload once submodules have been updated */ - return git_submodule_reload_all(data->repo); + return git_submodule_reload_all(data->repo, 1); } static int checkout_lookup_head_tree(git_tree **out, git_repository *repo) |