From 5d1308f25ff36d03f0a22451642cc0f2a931daae Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 8 Oct 2012 15:19:00 -0700 Subject: Add test for diffs with submodules and bug fixes The adds a test for the submodule diff capabilities and then fixes a few bugs with how the output is generated. It improves the accuracy of OIDs in the diff delta object and makes the submodule output more closely mirror the OIDs that will be used by core git. --- src/diff_output.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/diff_output.c') diff --git a/src/diff_output.c b/src/diff_output.c index 9fee127c6..10fbd391c 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -275,30 +275,34 @@ static int get_workdir_sm_content( int error = 0; git_buf content = GIT_BUF_INIT; git_submodule* sm = NULL; - const git_oid* sm_head = NULL; unsigned int sm_status = 0; const char* sm_status_text = ""; char oidstr[GIT_OID_HEXSZ+1]; - if ((error = git_submodule_lookup(&sm, ctxt->repo, file->path)) < 0) { + if ((error = git_submodule_lookup(&sm, ctxt->repo, file->path)) < 0 || + (error = git_submodule_status(&sm_status, sm)) < 0) return error; - } - if ((sm_head = git_submodule_head_oid(sm)) == NULL) { - giterr_set(GITERR_SUBMODULE, "Cannot find head of submodule '%s'", file->path); - return -1; - } + /* update OID if we didn't have it previously */ + if ((file->flags & GIT_DIFF_FILE_VALID_OID) == 0) { + const git_oid* sm_head; - if ((error = git_submodule_status(&sm_status, sm)) < 0) { - return -1; + if ((sm_head = git_submodule_wd_oid(sm)) != NULL || + (sm_head = git_submodule_head_oid(sm)) != NULL) + { + git_oid_cpy(&file->oid, sm_head); + file->flags |= GIT_DIFF_FILE_VALID_OID; + } } - if (!GIT_SUBMODULE_STATUS_IS_UNMODIFIED(sm_status)) { + + git_oid_fmt(oidstr, &file->oid); + oidstr[GIT_OID_HEXSZ] = '\0'; + + if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status)) sm_status_text = "-dirty"; - } - git_oid_fmt(oidstr, sm_head); - oidstr[GIT_OID_HEXSZ] = 0; - git_buf_printf(&content, "Subproject commit %s%s\n", oidstr, sm_status_text ); + git_buf_printf(&content, "Subproject commit %s%s\n", + oidstr, sm_status_text); map->data = git_buf_detach(&content); map->len = strlen(map->data); @@ -318,7 +322,7 @@ static int get_workdir_content( git_buf path = GIT_BUF_INIT; const char *wd = git_repository_workdir(ctxt->repo); - if (file->mode == GIT_FILEMODE_COMMIT) + if (S_ISGITLINK(file->mode)) return get_workdir_sm_content(ctxt, file, map); if (S_ISDIR(file->mode)) -- cgit v1.2.1