git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] disable complete ignorance of submodules for index <-> HEAD diff

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Nov 23, 2013, 01:11 UTC
Message-ID
<20131123011145.GB4952@sandbox-ub>
In-Reply-To
<20131122215454.GA4952@sandbox-ub>

If the value of ignore for submodules is set to "all" we would not show whats actually committed during status or diff. This can result in the user committing unexpected submodule references. Lets be nicer and always show whats in the index.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
This probably needs splitting up into two patches one for the
refactoring and one for the actual fix. It is also missing tests, but I
would first like to know what you think about this approach.
 builtin/diff.c | 43 +++++++++++++++++++++++++++----------------
 diff.h         |  2 +-
 submodule.c    |  6 ++++--
 wt-status.c    |  3 +++
 4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/builtin/diff.c b/builtin/diff.c
index adb93a9..e9a356c 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -249,6 +249,21 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
 	return run_diff_files(revs, options);
 }
 
+static int have_cached_option(int argc, const char **argv)
+{
+	int i;
+	for (i = 1; i < argc; i++) {
+		const char *arg = argv[i];
+		if (!strcmp(arg, "--"))
+			return 0;
+		else if (!strcmp(arg, "--cached") ||
+			 !strcmp(arg, "--staged")) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
 int cmd_diff(int argc, const char **argv, const char *prefix)
 {
 	int i;
@@ -259,6 +274,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	struct blobinfo blob[2];
 	int nongit;
 	int result = 0;
+	int have_cached;
 
 	/*
 	 * We could get N tree-ish in the rev.pending_objects list.
@@ -305,6 +321,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 
 	if (nongit)
 		die(_("Not a git repository"));
+
+	have_cached = have_cached_option(argc, argv);
+	if (have_cached)
+		DIFF_OPT_SET(&rev.diffopt, NO_IGNORE_SUBMODULE);
+
 	argc = setup_revisions(argc, argv, &rev, NULL);
 	if (!rev.diffopt.output_format) {
 		rev.diffopt.output_format = DIFF_FORMAT_PATCH;
@@ -319,22 +340,12 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	 * Do we have --cached and not have a pending object, then
 	 * default to HEAD by hand.  Eek.
 	 */
-	if (!rev.pending.nr) {
-		int i;
-		for (i = 1; i < argc; i++) {
-			const char *arg = argv[i];
-			if (!strcmp(arg, "--"))
-				break;
-			else if (!strcmp(arg, "--cached") ||
-				 !strcmp(arg, "--staged")) {
-				add_head_to_pending(&rev);
-				if (!rev.pending.nr) {
-					struct tree *tree;
-					tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
-					add_pending_object(&rev, &tree->object, "HEAD");
-				}
-				break;
-			}
+	if (!rev.pending.nr && have_cached) {
+		add_head_to_pending(&rev);
+		if (!rev.pending.nr) {
+			struct tree *tree;
+			tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+			add_pending_object(&rev, &tree->object, "HEAD");
 		}
 	}
 
diff --git a/diff.h b/diff.h
index e342325..81561b3 100644
--- a/diff.h
+++ b/diff.h
@@ -64,7 +64,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_FIND_COPIES_HARDER  (1 <<  6)
 #define DIFF_OPT_FOLLOW_RENAMES      (1 <<  7)
 #define DIFF_OPT_RENAME_EMPTY        (1 <<  8)
-/* (1 <<  9) unused */
+#define DIFF_OPT_NO_IGNORE_SUBMODULE (1 <<  9)
 #define DIFF_OPT_HAS_CHANGES         (1 << 10)
 #define DIFF_OPT_QUICK               (1 << 11)
 #define DIFF_OPT_NO_INDEX            (1 << 12)
diff --git a/submodule.c b/submodule.c
index 1905d75..9d81712 100644
--- a/submodule.c
+++ b/submodule.c
@@ -301,9 +301,11 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,
 	DIFF_OPT_CLR(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
 	DIFF_OPT_CLR(diffopt, IGNORE_DIRTY_SUBMODULES);
 
-	if (!strcmp(arg, "all"))
+	if (!strcmp(arg, "all")) {
+		if (DIFF_OPT_TST(diffopt, NO_IGNORE_SUBMODULE))
+			return;
 		DIFF_OPT_SET(diffopt, IGNORE_SUBMODULES);
-	else if (!strcmp(arg, "untracked"))
+	} else if (!strcmp(arg, "untracked"))
 		DIFF_OPT_SET(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
 	else if (!strcmp(arg, "dirty"))
 		DIFF_OPT_SET(diffopt, IGNORE_DIRTY_SUBMODULES);
diff --git a/wt-status.c b/wt-status.c
index b4e44ba..34be1cc 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -462,6 +462,9 @@ static void wt_status_collect_changes_index(struct wt_status *s)
 		handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
 	}
 
+	/* for the index we need to disable complete ignorance of submodules */
+	DIFF_OPT_SET(&rev.diffopt, NO_IGNORE_SUBMODULE);
+
 	rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
 	rev.diffopt.format_callback = wt_status_collect_updated_cb;
 	rev.diffopt.format_callback_data = s;
-- 
1.8.5.rc3.1.gcd6363f
Previous: Junio C HamanoNext: Sergey Sharybin
Message 40 of 51 in “Git issues with submodules”
  1. Sergey SharybinNov 22, 2013
  2. Ramkumar RamachandraNov 22, 2013
  3. Sergey SharybinNov 22, 2013
  4. Ramkumar RamachandraNov 22, 2013
  5. Jeff KingNov 22, 2013
  6. Sergey SharybinNov 22, 2013
  7. Ramkumar RamachandraNov 22, 2013
  8. Sergey SharybinNov 22, 2013
  9. Sergey SharybinNov 22, 2013
  10. Ramkumar RamachandraNov 22, 2013
  11. Jens LehmannNov 22, 2013
  12. Sergey SharybinNov 22, 2013
  13. Heiko VoigtNov 22, 2013
  14. Jonathan NiederNov 22, 2013
  15. Jens LehmannNov 23, 2013
  16. Heiko VoigtNov 24, 2013
  17. Jens LehmannNov 24, 2013
  18. Sergey SharybinNov 25, 2013
  19. Heiko VoigtNov 25, 2013
  20. Sergey SharybinNov 25, 2013
  21. Heiko VoigtNov 25, 2013
  22. 0/4 less ignorance of submodules for ignore=allHeiko Voigt, Dec 4, 2013
  23. 1/4 disable complete ignorance of submodules for index <-> HEAD diffHeiko Voigt, Dec 4, 2013
  24. 2/4 fix 'git add' to skip submodules configured as ignoredHeiko Voigt, Dec 4, 2013
  25. 3/4 teach add -f option for ignored submodulesHeiko Voigt, Dec 4, 2013
  26. Junio C HamanoDec 6, 2013
  27. Heiko VoigtDec 9, 2013
  28. 4/4 always show committed submodules in summary after commitHeiko Voigt, Dec 4, 2013
  29. Heiko VoigtDec 4, 2013
  30. Junio C HamanoDec 4, 2013
  31. Heiko VoigtDec 4, 2013
  32. Jens LehmannDec 5, 2013
  33. Heiko VoigtDec 9, 2013
  34. Junio C HamanoDec 9, 2013
  35. Junio C HamanoNov 25, 2013
  36. Jens LehmannNov 26, 2013
  37. Junio C HamanoNov 26, 2013
  38. Jonathan NiederNov 26, 2013
  39. Junio C HamanoNov 26, 2013
  40. disable complete ignorance of submodules for index <-> HEAD diffHeiko Voigt, Nov 23, 2013
  41. Sergey SharybinNov 25, 2013
  42. Heiko VoigtNov 28, 2013
  43. disable complete ignorance of submodules for index <-> HEAD diffHeiko Voigt, Nov 29, 2013
  44. Ramkumar RamachandraNov 23, 2013
  45. Jens LehmannNov 23, 2013
  46. Heiko VoigtNov 24, 2013
  47. Junio C HamanoNov 25, 2013
  48. Heiko VoigtNov 29, 2013
  49. Ramkumar RamachandraNov 23, 2013
  50. Ramkumar RamachandraNov 22, 2013
  51. Jens LehmannNov 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.