Update diff to new internal submodule status API Submodules now expose an internal status API that allows diff to get back the OID values from the submodule very easily and also to avoiding caching issues and to override the ignore setting for the submodule.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/diff.c b/src/diff.c
index cc7be45..2b01818 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -13,6 +13,7 @@
#include "pathspec.h"
#include "index.h"
#include "odb.h"
+#include "submodule.h"
#define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0)
#define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0)
@@ -595,7 +596,6 @@ static int maybe_modified_submodule(
int error = 0;
git_submodule *sub;
unsigned int sm_status = 0;
- const git_oid *sm_oid;
*status = GIT_DELTA_UNMODIFIED;
@@ -603,7 +603,9 @@ static int maybe_modified_submodule(
!(error = git_submodule_lookup(
&sub, diff->repo, info->nitem->path)) &&
git_submodule_ignore(sub) != GIT_SUBMODULE_IGNORE_ALL &&
- !(error = git_submodule_status(&sm_status, sub)))
+ !(error = git_submodule__status(
+ &sm_status, NULL, NULL, found_oid, sub,
+ GIT_SUBMODULE_IGNORE_DEFAULT)))
{
/* check IS_WD_UNMODIFIED because this case is only used
* when the new side of the diff is the working directory
@@ -611,10 +613,10 @@ static int maybe_modified_submodule(
if (!GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(sm_status))
*status = GIT_DELTA_MODIFIED;
- /* grab OID while we are here */
- if (git_oid_iszero(&info->nitem->oid) &&
- (sm_oid = git_submodule_wd_id(sub)) != NULL)
- git_oid_cpy(found_oid, sm_oid);
+ /* now that we have a HEAD OID, check if HEAD moved */
+ if ((sm_status & GIT_SUBMODULE_STATUS_IN_WD) != 0 &&
+ !git_oid_equal(&info->oitem->oid, found_oid))
+ *status = GIT_DELTA_MODIFIED;
}
/* GIT_EEXISTS means a dir with .git in it was found - ignore it */
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c
index c94fd57..4a40aff 100644
--- a/tests-clar/diff/submodules.c
+++ b/tests-clar/diff/submodules.c
@@ -333,8 +333,6 @@ void test_diff_submodules__invalid_cache(void)
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
- sleep(2);
-
/* commit changed index of submodule */
{
git_object *parent;
@@ -357,11 +355,6 @@ void test_diff_submodules__invalid_cache(void)
git_signature_free(sig);
}
- /* THIS RELOAD SHOULD NOT BE REQUIRED
- cl_git_pass(git_submodule_reload_all(g_repo));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
- */
-
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));