diff options
author | Russell Belfer <rb@github.com> | 2012-10-08 15:19:00 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-10-08 15:22:40 -0700 |
commit | 5d1308f25ff36d03f0a22451642cc0f2a931daae (patch) | |
tree | 1d9c581f1a2b756a35c95f15077630a9fac34a2c /src/diff_output.c | |
parent | 71966e2f1bdfb75b7e57942d572ea089ce32e463 (diff) | |
download | libgit2-5d1308f25ff36d03f0a22451642cc0f2a931daae.tar.gz |
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.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r-- | src/diff_output.c | 34 |
1 files changed, 19 insertions, 15 deletions
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)) |