summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Cunz <Sascha@BabbelBox.org>2012-10-05 13:03:22 +0200
committerSascha Cunz <Sascha@BabbelBox.org>2012-10-05 13:03:38 +0200
commit1686641f18f028940b760ef554e9219c2c9a27d8 (patch)
treeecce320f251b88a058286e228cfe26e9dcc97006
parent7e57d2506a4719dbe13115ba3bf7e4a012daa3e3 (diff)
downloadlibgit2-1686641f18f028940b760ef554e9219c2c9a27d8.tar.gz
Extract submodule logic out of diff_output.c:get_workdir_content
-rw-r--r--src/diff_output.c73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index f8a9f8e51..f5f6c381e 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -267,52 +267,59 @@ static int get_blob_content(
return diff_delta_is_binary_by_content(ctxt, delta, file, map);
}
-static int get_workdir_content(
+static int get_workdir_sm_content(
diff_context *ctxt,
- git_diff_delta *delta,
git_diff_file *file,
git_map *map)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
- const char *wd = git_repository_workdir(ctxt->repo);
+ 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 (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 ((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_lookup(&sm, ctxt->repo, file->path)) < 0) {
- return error;
- }
+ if ((error = git_submodule_status(&sm_status, sm)) < 0) {
+ return -1;
+ }
+ if (!GIT_SUBMODULE_STATUS_IS_UNMODIFIED(sm_status)) {
+ sm_status_text = "-dirty";
+ }
- if ((sm_head = git_submodule_head_oid(sm)) == NULL) {
- giterr_set(GITERR_SUBMODULE, "Cannot find head of submodule '%s'", file->path);
- return -1;
- }
+ git_oid_fmt(oidstr, sm_head);
+ oidstr[GIT_OID_HEXSZ] = 0;
+ git_buf_printf(&content, "Subproject commit %s%s\n", oidstr, sm_status_text );
- if ((error = git_submodule_status(&sm_status, sm)) < 0) {
- return -1;
- }
- if (!GIT_SUBMODULE_STATUS_IS_UNMODIFIED(sm_status)) {
- sm_status_text = "-dirty";
- }
+ map->data = git_buf_detach(&content);
+ map->len = strlen(map->data);
- git_oid_fmt(oidstr, sm_head);
- oidstr[GIT_OID_HEXSZ] = 0;
- git_buf_printf(&content, "Subproject commit %s%s\n", oidstr, sm_status_text );
+ file->flags |= GIT_DIFF_FILE_FREE_DATA;
- map->data = git_buf_detach(&content);
- map->len = strlen(map->data);
+ return 0;
+}
- file->flags |= GIT_DIFF_FILE_FREE_DATA;
+static int get_workdir_content(
+ diff_context *ctxt,
+ git_diff_delta *delta,
+ git_diff_file *file,
+ git_map *map)
+{
+ int error = 0;
+ git_buf path = GIT_BUF_INIT;
+ const char *wd = git_repository_workdir(ctxt->repo);
- return 0;
- }
+ if (file->mode == GIT_FILEMODE_COMMIT)
+ return get_workdir_sm_content(ctxt, file, map);
if (git_buf_joinpath(&path, wd, file->path) < 0)
return -1;