Commit 1dca8510a2e815c95293c1ebaacf2a286a9c6e1d

Sascha Cunz 2012-10-05T13:44:18

Diff: Do not try to calculate an oid for a GITLINK. We don't have anything useful that we could do with that oid anyway (We need to query the submodule for the HEAD commit instead). Without this, the following code creates the error "Failed to read descriptor: Is a directory" when run against the submod2 test-case: const char* oidstr = "873585b94bdeabccea991ea5e3ec1a277895b698"; git_tree* tree = resolve_commit_oid_to_tree(g_repo, oidstr); git_diff_list* diff = NULL; cl_assert(tree); cl_git_pass(git_diff_workdir_to_tree(g_repo, NULL, tree, &diff));

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/diff.c b/src/diff.c
index 375520e..7a0051a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -448,7 +448,11 @@ static int oid_for_workdir_item(
 		return -1;
 
 	/* calculate OID for file if possible*/
-	if (S_ISLNK(item->mode))
+	if (S_ISGITLINK(item->mode)) {
+		/* Don't bother to figure out an oid for a submodule. We won't use it anyway. */
+		memset(oid, 0, sizeof(*oid));
+		result = 0;
+	} else if (S_ISLNK(item->mode))
 		result = git_odb__hashlink(oid, full_path.ptr);
 	else if (!git__is_sizet(item->file_size)) {
 		giterr_set(GITERR_OS, "File size overflow for 32-bit systems");