Skip to contentSkip to conversation

Remove unused var

PATCH Superseded David Turner 2 participants 5 messages Aug 2, 2021 – Aug 31, 2021

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 Remove unused var

---
 t/t4060-diff-submodule-option-diff-format.sh | 1 -
 1 file changed, 1 deletion(-)
t/t4060-diff-submodule-option-diff-format.sh +0 -1
index dc7b242697..69b9946931 100755
@@ -361,7 +361,6 @@ test_expect_success 'typechanged submodule(submodule->blob)' '
 rm -f sm1 &&
 test_create_repo sm1 &&
 head6=$(add_file sm1 foo6 foo7)
-fullhead6=$(cd sm1; git rev-parse --verify HEAD)
 test_expect_success 'nonexistent commit' '
 	git diff-index -p --submodule=diff HEAD >actual &&
 	cat >expected <<-EOF &&
Signature · 1 line
2.11.GIT
#1 lore raw

PATCH v2 2/3 diff --submodule=diff: do not fail on ever-initialied deleted submodules

If you have ever initialized a submodule, open_submodule will open it. If you then delete the submodule's worktree directory (but don't remove it from .gitmodules), git diff --submodule=diff would error out as it attempted to chdir into the now-deleted working tree directory.

Instead, we chdir into the submodule's git directory and run the diff from there.

---
 submodule.c                                  |  10 ++
 t/t4060-diff-submodule-option-diff-format.sh | 157 +++++++++++++++++++++++++--
 2 files changed, 160 insertions(+), 7 deletions(-)
submodule.c +10 -0
index 0b1d9c1dde..d13d103975 100644
@@ -710,6 +710,16 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
 		strvec_push(&cp.args, oid_to_hex(new_oid));
 
 	prepare_submodule_repo_env(&cp.env_array);
+
+	if (!is_directory(path)) {
+		// fall back to absorbed git dir, if any
+		if (!sub)
+			goto done;
+		cp.dir = sub->gitdir;
+		strvec_push(&cp.env_array, GIT_DIR_ENVIRONMENT "=.");
+		strvec_push(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT "=.");
+	}
+
 	if (start_command(&cp))
 		diff_emit_submodule_error(o, "(diff failed)\n");
 
t/t4060-diff-submodule-option-diff-format.sh +150 -7

194 lines not on this page · raw message

Signature · 1 line
2.11.GIT
#2 lore raw

Re: [PATCH v2 2/3] diff --submodule=diff: do not fail on ever-initialied deleted submodules

Quoted 19 lines · David Turner

If you have ever initialized a submodule, open_submodule will open it. If you then delete the submodule's worktree directory (but don't remove it from .gitmodules), git diff --submodule=diff would error out as it attempted to chdir into the now-deleted working tree directory.

Instead, we chdir into the submodule's git directory and run the diff from there.

---
 submodule.c                                  |  10 ++
 t/t4060-diff-submodule-option-diff-format.sh | 157 +++++++++++++++++++++++++--
 2 files changed, 160 insertions(+), 7 deletions(-)
submodule.c +0 -0
index 0b1d9c1dde..d13d103975 100644

submodule.c void show_submodule_inline_diff(struct diff_options *o, const char *path, · line 715

Quoted 6 lines
submodule.c +3 -0
@@ -710,6 +710,16 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
 		strvec_push(&cp.args, oid_to_hex(new_oid));
 
 	prepare_submodule_repo_env(&cp.env_array);
+
+	if (!is_directory(path)) {
+		// fall back to absorbed git dir, if any

I'll locally amend this comment style. If there is no other comments, that would be sufficient.

Quoted 9 lines
submodule.c +7 -0
+		if (!sub)
+			goto done;
+		cp.dir = sub->gitdir;
+		strvec_push(&cp.env_array, GIT_DIR_ENVIRONMENT "=.");
+		strvec_push(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT "=.");
+	}
+
 	if (start_command(&cp))
 		diff_emit_submodule_error(o, "(diff failed)\n");
#3 lore raw

PATCH v2 3/3 diff --submodule=diff: Don't print failure message twice

In reply to David Turner

When we fail to start a diff command inside a submodule, immediately exit the routine rather than trying to finish the command and printing a second message.

---
 submodule.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
submodule.c +3 -1
index d13d103975..2e98e840af 100644
@@ -720,8 +720,10 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
 		strvec_push(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT "=.");
 	}
 
-	if (start_command(&cp))
+	if (start_command(&cp)) {
 		diff_emit_submodule_error(o, "(diff failed)\n");
+		goto done;
+	}
 
 	while (strbuf_getwholeline_fd(&sb, cp.out, '\n') != EOF)
 		diff_emit_submodule_pipethrough(o, sb.buf, sb.len);
Signature · 1 line
2.11.GIT
#4 lore raw

Re: [PATCH v2 3/3] diff --submodule=diff: Don't print failure message twice

Quoted 15 lines · David Turner

When we fail to start a diff command inside a submodule, immediately exit the routine rather than trying to finish the command and printing a second message.

---
 submodule.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
submodule.c +0 -0
index d13d103975..2e98e840af 100644
@@ -720,8 +720,10 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
 		strvec_push(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT "=.");

submodule.c void show_submodule_inline_diff(struct diff_options *o, const char *path, · line 729

Quoted 10 lines
submodule.c +3 -1
 	}
 
-	if (start_command(&cp))
+	if (start_command(&cp)) {
 		diff_emit_submodule_error(o, "(diff failed)\n");
+		goto done;
+	}
 
 	while (strbuf_getwholeline_fd(&sb, cp.out, '\n') != EOF)
 		diff_emit_submodule_pipethrough(o, sb.buf, sb.len);

Makes sense.