diff options
author | Sascha Cunz <Sascha@BabbelBox.org> | 2012-09-18 23:43:23 +0200 |
---|---|---|
committer | Sascha Cunz <Sascha@BabbelBox.org> | 2012-10-05 13:03:38 +0200 |
commit | 7e57d2506a4719dbe13115ba3bf7e4a012daa3e3 (patch) | |
tree | 06c3f7f3b800c949cf8f3b2bd808aac2bd087054 /src/diff_output.c | |
parent | 9ce44f1ae5a8b286585e60c88c6a143d80a226a6 (diff) | |
download | libgit2-7e57d2506a4719dbe13115ba3bf7e4a012daa3e3.tar.gz |
Diff: teach get_workdir_content to show a submodule as text
1. teach diff.c:maybe_modified to query git_submodule_status for the
modification state of a submodule. According to the
git_submodule_status docs, it will filter for to-ignore states
already.
2. teach diff_output.c:get_workdir_content to check the submodule status
again and create a line like:
Subproject commit <SHA-1>\n
or
Subproject comimt <SHA-1>-dirty\n
like git.git does.
Diffstat (limited to 'src/diff_output.c')
-rw-r--r-- | src/diff_output.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/diff_output.c b/src/diff_output.c index b8516cc24..f8a9f8e51 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -7,6 +7,7 @@ #include "common.h" #include "git2/attr.h" #include "git2/oid.h" +#include "git2/submodule.h" #include "diff_output.h" #include <ctype.h> #include "fileops.h" @@ -276,6 +277,43 @@ 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) + { + 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) { + 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; + } + + if ((error = git_submodule_status(&sm_status, sm)) < 0) { + return -1; + } + if (!GIT_SUBMODULE_STATUS_IS_UNMODIFIED(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 ); + + map->data = git_buf_detach(&content); + map->len = strlen(map->data); + + file->flags |= GIT_DIFF_FILE_FREE_DATA; + + return 0; + } + if (git_buf_joinpath(&path, wd, file->path) < 0) return -1; |