Skip to contentSkip to conversation

implement inline submodule diff format

PATCH Superseded Jacob Keller 5 participants 27 messages Aug 18, 2016 – Aug 19, 2016 Documentation

v7 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#1 lore raw

PATCH v7 1/7 diff.c: remove output_prefix_length field

In reply to Jacob Keller

From: Junio C Hamano <[email protected]>

"diff/log --stat" has a logic that determines the display columns available for the diffstat part of the output and apportions it for pathnames and diffstat graph automatically.

5e71a84a (Add output_prefix_length to diff_options, 2012-04-16) added the output_prefix_length field to diff_options structure to allow this logic to subtract the display columns used for the history graph part from the total "terminal width"; this matters when the "git log --graph -p" option is in use.

The field must be set to the number of display columns needed to show the output from the output_prefix() callback, which is error prone. As there is only one user of the field, and the user has the actual value of the prefix string, let's get rid of the field and have the user count the display width itself.

---
 diff.c  | 2 +-
 diff.h  | 1 -
 graph.c | 2 --
 3 files changed, 1 insertion(+), 4 deletions(-)
diff.c +1 -1
index 534c12e28ea8..50bef1f07658 100644
@@ -1625,7 +1625,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 	 */
 
 	if (options->stat_width == -1)
-		width = term_columns() - options->output_prefix_length;
+		width = term_columns() - strlen(line_prefix);
 	else
 		width = options->stat_width ? options->stat_width : 80;
 	number_width = decimal_width(max_change) > number_width ?
diff.h +0 -1
index 7883729edf10..747a204d75a4 100644
@@ -174,7 +174,6 @@ struct diff_options {
 	diff_format_fn_t format_callback;
 	void *format_callback_data;
 	diff_prefix_fn_t output_prefix;
-	int output_prefix_length;
 	void *output_prefix_data;
 
 	int diff_path_counter;
graph.c +0 -2
index dd1720148dc5..a46803840511 100644
@@ -197,7 +197,6 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
 	assert(opt);
 	assert(graph);
 
-	opt->output_prefix_length = graph->width;
 	strbuf_reset(&msgbuf);
 	graph_padding_line(graph, &msgbuf);
 	return &msgbuf;
@@ -245,7 +244,6 @@ struct git_graph *graph_init(struct rev_info *opt)
 	 */
 	opt->diffopt.output_prefix = diff_output_prefix_callback;
 	opt->diffopt.output_prefix_data = graph;
-	opt->diffopt.output_prefix_length = 0;
 
 	return graph;
 }
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#0 lore raw

v7 cover implement inline submodule diff format

From: Jacob Keller <[email protected]>

As suggested by Junio, I broke this patch into several pieces, and made a common helper function for the submodule header. Note that there are a couple of complicated modifications to the submodule header portion which (should) still result in the same header but allow the diff format a bit better control. It's a bit awkward but it does pass all the current tests, and the format between the two should be similar.

I tried to break apart the patches properly, so I hope I didn't accidentally munge them too badly.

Jacob Keller (6):
graph: add support for --line-prefix on all graph-aware output
diff: prepare for additional submodule formats
submodule: allow do_submodule_path to work if given gitdir directly
submodule: correct output of submodule log format
submodule: refactor show_submodule_summary with helper function
diff: teach diff to display submodule difference with an inline diff

Junio C Hamano (1):
diff.c: remove output_prefix_length field

 Documentation/diff-config.txt                      |   9 +-
 Documentation/diff-options.txt                     |  20 +-
 builtin/rev-list.c                                 |  70 +-
 diff.c                                             |  52 +-
 diff.h                                             |  11 +-
 graph.c                                            | 106 +--
 graph.h                                            |  22 +-
 log-tree.c                                         |   5 +-
 path.c                                             |   4 +-
 submodule.c                                        | 162 ++++-
 submodule.h                                        |   6 +
 t/t4013-diff-various.sh                            |   6 +
 ...diff.diff_--line-prefix=abc_master_master^_side |  29 +
 t/t4013/diff.diff_--line-prefix_--cached_--_file0  |  15 +
 t/t4059-diff-submodule-option-diff-format.sh       | 733 +++++++++++++++++++++
 t/t4202-log.sh                                     | 323 +++++++++
 16 files changed, 1432 insertions(+), 141 deletions(-)
 create mode 100644 t/t4013/diff.diff_--line-prefix=abc_master_master^_side
 create mode 100644 t/t4013/diff.diff_--line-prefix_--cached_--_file0
 create mode 100755 t/t4059-diff-submodule-option-diff-format.sh
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#15 lore raw

PATCH v7 6/7 submodule: refactor show_submodule_summary with helper function

From: Jacob Keller <[email protected]>

A future patch is going to add a new submodule diff format which displays an inline diff of the submodule changes. To make this easier, and to ensure that both submodule diff formats use the same initial header, factor out show_submodule_header() function which will print the current submodule header line, and then leave the show_submodule_summary function to lookup and print the submodule log format.

This does create one format change in that "(revision walker failed)" will now be displayed on its own line rather than as part of the message because we no longer perform this step directly in the header display flow. However, this is a rare case and shouldn't impact much. In addition, since we no longer need to run prepare_submodule_summary to get the fast_backward and fast_forward variables, these have been removed from that call, and the show_submodule_header() function does its own mergebase lookup.

---
 submodule.c | 103 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 74 insertions(+), 29 deletions(-)
submodule.c +74 -29
index e1a51b7506ff..e341ca7ffefd 100644
@@ -277,8 +277,7 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,
 }
 
 static int prepare_submodule_summary(struct rev_info *rev, const char *path,
-		struct commit *left, struct commit *right,
-		int *fast_forward, int *fast_backward)
+		struct commit *left, struct commit *right)
 {
 	struct commit_list *merge_bases, *list;
 
@@ -290,12 +289,6 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
 	add_pending_object(rev, &left->object, path);
 	add_pending_object(rev, &right->object, path);
 	merge_bases = get_merge_bases(left, right);
-	if (merge_bases) {
-		if (merge_bases->item == left)
-			*fast_forward = 1;
-		else if (merge_bases->item == right)
-			*fast_backward = 1;
-	}
 	for (list = merge_bases; list; list = list->next) {
 		list->item->object.flags |= UNINTERESTING;
 		add_pending_object(rev, &list->item->object,
@@ -333,31 +326,23 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	strbuf_release(&sb);
 }
 
-void show_submodule_summary(FILE *f, const char *path,
+/* Helper function to display the submodule header line prior to the full
+ * summary output. If it can locate the submodule objects directory it will
+ * attempt to lookup both the left and right commits and put them into the
+ * left and right pointers.
+ */
+static void show_submodule_header(FILE *f, const char *path,
 		const char *line_prefix,
 		unsigned char one[20], unsigned char two[20],
 		unsigned dirty_submodule, const char *meta,
-		const char *del, const char *add, const char *reset)
+		const char *reset,
+		struct commit **left, struct commit **right)
 {
-	struct rev_info rev;
-	struct commit *left = NULL, *right = NULL;
+	struct commit_list *merge_bases;
 	const char *message = NULL;
 	struct strbuf sb = STRBUF_INIT;
 	int fast_forward = 0, fast_backward = 0;
 
-	if (is_null_sha1(two))
-		message = "(submodule deleted)";
-	else if (add_submodule_odb(path))
-		message = "(not initialized)";
-	else if (is_null_sha1(one))
-		message = "(new submodule)";
-	else if (!(left = lookup_commit_reference(one)) ||
-		 !(right = lookup_commit_reference(two)))
-		message = "(commits not present)";
-	else if (prepare_submodule_summary(&rev, path, left, right,
-					   &fast_forward, &fast_backward))
-		message = "(revision walker failed)";
-
 	if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
 		fprintf(f, "%sSubmodule %s contains untracked content\n",
 			line_prefix, path);
@@ -365,11 +350,46 @@ void show_submodule_summary(FILE *f, const char *path,
 		fprintf(f, "%sSubmodule %s contains modified content\n",
 			line_prefix, path);
 
+	if (is_null_sha1(one))
+		message = "(new submodule)";
+	else if (is_null_sha1(two))
+		message = "(submodule deleted)";
+
+	if (add_submodule_odb(path)) {
+		if (!message)
+			message = "(submodule not initialized)";
+		goto output_header;
+	}
+
+	/*
+	 * Attempt to lookup the commit references, and determine if this is
+	 * a fast forward or fast backwards update
+	 */
+	*left = lookup_commit_reference(one);
+	*right = lookup_commit_reference(two);
+
+	/*
+	 * Warn about missing commits in the submodule project, but only if
+	 * they aren't null
+	 */
+	if ((!is_null_sha1(one) && !*left) ||
+	     (!is_null_sha1(two) && !*right))
+		message = "(commits not present)";
+
+	merge_bases = get_merge_bases(*left, *right);
+	if (merge_bases) {
+		if (merge_bases->item == *left)
+			fast_forward = 1;
+		else if (merge_bases->item == *right)
+			fast_backward = 1;
+	}
+
 	if (!hashcmp(one, two)) {
 		strbuf_release(&sb);
 		return;
 	}
 
+output_header:
 	strbuf_addf(&sb, "%s%sSubmodule %s %s..", line_prefix, meta, path,
 			find_unique_abbrev(one, DEFAULT_ABBREV));
 	if (!fast_backward && !fast_forward)
@@ -381,14 +401,39 @@ void show_submodule_summary(FILE *f, const char *path,
 		strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
 	fwrite(sb.buf, sb.len, 1, f);
 
-	if (!message) /* only NULL if we succeeded in setting up the walk */
-		print_submodule_summary(&rev, f, line_prefix, del, add, reset);
+	strbuf_release(&sb);
+}
+
+void show_submodule_summary(FILE *f, const char *path,
+		const char *line_prefix,
+		unsigned char one[20], unsigned char two[20],
+		unsigned dirty_submodule, const char *meta,
+		const char *del, const char *add, const char *reset)
+{
+	struct rev_info rev;
+	struct commit *left = NULL, *right = NULL;
+
+	show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
+			      meta, reset, &left, &right);
+
+	/*
+	 * if we don't have both a left and a right pointer, then we can't
+	 * display a summary
+	 */
+	if (!left || !right)
+		return;
+
+	if (prepare_submodule_summary(&rev, path, left, right)) {
+		fprintf(f, "%s(revision walker failed)\n", line_prefix);
+		return;
+	}
+
+	print_submodule_summary(&rev, f, line_prefix, del, add, reset);
+
 	if (left)
 		clear_commit_marks(left, ~0);
 	if (right)
 		clear_commit_marks(right, ~0);
-
-	strbuf_release(&sb);
 }
 
 void set_config_fetch_recurse_submodules(int value)
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#24 lore raw

PATCH v7 7/7 diff: teach diff to display submodule difference with an inline diff

In reply to Jacob Keller

From: Jacob Keller <[email protected]>

Teach git-diff and friends a new format for displaying the difference of a submodule. The new format is an inline diff of the contents of the submodule between the commit range of the update. This allows the user to see the actual code change caused by a submodule update.

Add tests for the new format and option.

---
 Documentation/diff-config.txt                |   9 +-
 Documentation/diff-options.txt               |  17 +-
 diff.c                                       |  31 +-
 diff.h                                       |   1 +
 submodule.c                                  |  61 +++
 submodule.h                                  |   6 +
 t/t4059-diff-submodule-option-diff-format.sh | 733 +++++++++++++++++++++++++++
 7 files changed, 838 insertions(+), 20 deletions(-)
 create mode 100755 t/t4059-diff-submodule-option-diff-format.sh
Documentation/diff-config.txt +5 -4
index d5a5b17d5088..0eded24034b5 100644
@@ -122,10 +122,11 @@ diff.suppressBlankEmpty::
 
 diff.submodule::
 	Specify the format in which differences in submodules are
-	shown.  The "log" format lists the commits in the range like
-	linkgit:git-submodule[1] `summary` does.  The "short" format
-	format just shows the names of the commits at the beginning
-	and end of the range.  Defaults to short.
+	shown.  The "short" format just shows the names of the commits
+	at the beginning and end of the range. The "log" format lists
+	the commits in the range like linkgit:git-submodule[1] `summary`
+	does. The "diff" format shows an inline diff of the changed
+	contents of the submodule. Defaults to "short".
 
 diff.wordRegex::
 	A POSIX Extended Regular Expression used to determine what is a "word"
Documentation/diff-options.txt +10 -7
index cc4342e2034d..7805a0ccadf2 100644
@@ -210,13 +210,16 @@ any of those replacements occurred.
 	of the `--diff-filter` option on what the status letters mean.
 
 --submodule[=<format>]::
-	Specify how differences in submodules are shown.  When `--submodule`
-	or `--submodule=log` is given, the 'log' format is used.  This format lists
-	the commits in the range like linkgit:git-submodule[1] `summary` does.
-	Omitting the `--submodule` option or specifying `--submodule=short`,
-	uses the 'short' format. This format just shows the names of the commits
-	at the beginning and end of the range.  Can be tweaked via the
-	`diff.submodule` configuration variable.
+	Specify how differences in submodules are shown.  When specifying
+	`--submodule=short` the 'short' format is used.  This format just
+	shows the names of the commits at the beginning and end of the range.
+	When `--submodule` or `--submodule=log` is specified, the 'log'
+	format is used.  This format lists the commits in the range like
+	linkgit:git-submodule[1] `summary` does.  When `--submodule=diff`
+	is specified, the 'diff' format is used.  This format shows an
+	inline diff of the changes in the submodule contents between the
+	commit range.  Defaults to `diff.submodule` or the 'short' format
+	if the config option is unset.
 
 --color[=<when>]::
 	Show colored diff.
diff.c +22 -9
index d6b321da3d1d..e119758aba82 100644
@@ -135,6 +135,8 @@ static int parse_submodule_params(struct diff_options *options, const char *valu
 		options->submodule_format = DIFF_SUBMODULE_LOG;
 	else if (!strcmp(value, "short"))
 		options->submodule_format = DIFF_SUBMODULE_SHORT;
+	else if (!strcmp(value, "diff"))
+		options->submodule_format = DIFF_SUBMODULE_INLINE_DIFF;
 	else
 		return -1;
 	return 0;
@@ -2300,6 +2302,15 @@ static void builtin_diff(const char *name_a,
 	struct strbuf header = STRBUF_INIT;
 	const char *line_prefix = diff_line_prefix(o);
 
+	diff_set_mnemonic_prefix(o, "a/", "b/");
+	if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
+		a_prefix = o->b_prefix;
+		b_prefix = o->a_prefix;
+	} else {
+		a_prefix = o->a_prefix;
+		b_prefix = o->b_prefix;
+	}
+
 	if (o->submodule_format == DIFF_SUBMODULE_LOG &&
 	    (!one->mode || S_ISGITLINK(one->mode)) &&
 	    (!two->mode || S_ISGITLINK(two->mode))) {
@@ -2311,6 +2322,17 @@ static void builtin_diff(const char *name_a,
 				two->dirty_submodule,
 				meta, del, add, reset);
 		return;
+	} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
+		   (!one->mode || S_ISGITLINK(one->mode)) &&
+		   (!two->mode || S_ISGITLINK(two->mode))) {
+		const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
+		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
+		show_submodule_inline_diff(o->file, one->path ? one->path : two->path,
+				line_prefix,
+				one->oid.hash, two->oid.hash,
+				two->dirty_submodule,
+				meta, del, add, reset, o);
+		return;
 	}
 
 	if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
@@ -2318,15 +2340,6 @@ static void builtin_diff(const char *name_a,
 		textconv_two = get_textconv(two);
 	}
 
-	diff_set_mnemonic_prefix(o, "a/", "b/");
-	if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
-		a_prefix = o->b_prefix;
-		b_prefix = o->a_prefix;
-	} else {
-		a_prefix = o->a_prefix;
-		b_prefix = o->b_prefix;
-	}
-
 	/* Never use a non-valid filename anywhere if at all possible */
 	name_a = DIFF_FILE_VALID(one) ? name_a : name_b;
 	name_b = DIFF_FILE_VALID(two) ? name_b : name_a;
diff.h +1 -0
index ea5aba668eaa..192c0eedd0ff 100644
@@ -112,6 +112,7 @@ enum diff_words_type {
 enum diff_submodule_format {
 	DIFF_SUBMODULE_SHORT = 0,
 	DIFF_SUBMODULE_LOG,
+	DIFF_SUBMODULE_INLINE_DIFF,
 };
 
 struct diff_options {
submodule.c +61 -0

67 lines not on this page · raw message

submodule.h +6 -0
index 2af939099819..e2ebc0756f6a 100644
@@ -46,6 +46,12 @@ void show_submodule_summary(FILE *f, const char *path,
 		unsigned char one[20], unsigned char two[20],
 		unsigned dirty_submodule, const char *meta,
 		const char *del, const char *add, const char *reset);
+void show_submodule_inline_diff(FILE *f, const char *path,
+		const char *line_prefix,
+		unsigned char one[20], unsigned char two[20],
+		unsigned dirty_submodule, const char *meta,
+		const char *del, const char *add, const char *reset,
+		const struct diff_options *opt);
 void set_config_fetch_recurse_submodules(int value);
 void check_for_new_submodule_commits(unsigned char new_sha1[20]);
 int fetch_populated_submodules(const struct argv_array *options,
t/t4059-diff-submodule-option-diff-format.sh new file +733 -0

733 lines not on this page · raw message

Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#6 lore raw

PATCH v7 3/7 diff: prepare for additional submodule formats

In reply to Jacob Keller

From: Jacob Keller <[email protected]>

A future patch will add a new format for displaying the difference of a submodule. Make it easier by changing how we store the current selected format. Replace the DIFF_OPT flag with an enumeration, as each format will be mutually exclusive.

---
 diff.c | 12 ++++++------
 diff.h |  7 ++++++-
 2 files changed, 12 insertions(+), 7 deletions(-)
diff.c +6 -6
index e57cf39ad109..d6b321da3d1d 100644
@@ -132,9 +132,9 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
 static int parse_submodule_params(struct diff_options *options, const char *value)
 {
 	if (!strcmp(value, "log"))
-		DIFF_OPT_SET(options, SUBMODULE_LOG);
+		options->submodule_format = DIFF_SUBMODULE_LOG;
 	else if (!strcmp(value, "short"))
-		DIFF_OPT_CLR(options, SUBMODULE_LOG);
+		options->submodule_format = DIFF_SUBMODULE_SHORT;
 	else
 		return -1;
 	return 0;
@@ -2300,9 +2300,9 @@ static void builtin_diff(const char *name_a,
 	struct strbuf header = STRBUF_INIT;
 	const char *line_prefix = diff_line_prefix(o);
 
-	if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
-			(!one->mode || S_ISGITLINK(one->mode)) &&
-			(!two->mode || S_ISGITLINK(two->mode))) {
+	if (o->submodule_format == DIFF_SUBMODULE_LOG &&
+	    (!one->mode || S_ISGITLINK(one->mode)) &&
+	    (!two->mode || S_ISGITLINK(two->mode))) {
 		const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
 		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
 		show_submodule_summary(o->file, one->path ? one->path : two->path,
@@ -3916,7 +3916,7 @@ int diff_opt_parse(struct diff_options *options,
 		DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
 		handle_ignore_submodules_arg(options, arg);
 	} else if (!strcmp(arg, "--submodule"))
-		DIFF_OPT_SET(options, SUBMODULE_LOG);
+		options->submodule_format = DIFF_SUBMODULE_LOG;
 	else if (skip_prefix(arg, "--submodule=", &arg))
 		return parse_submodule_opt(options, arg);
 	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
diff.h +6 -1
index 1f57aad25c71..ea5aba668eaa 100644
@@ -83,7 +83,6 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_DIRSTAT_BY_FILE     (1 << 20)
 #define DIFF_OPT_ALLOW_TEXTCONV      (1 << 21)
 #define DIFF_OPT_DIFF_FROM_CONTENTS  (1 << 22)
-#define DIFF_OPT_SUBMODULE_LOG       (1 << 23)
 #define DIFF_OPT_DIRTY_SUBMODULES    (1 << 24)
 #define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
 #define DIFF_OPT_IGNORE_DIRTY_SUBMODULES (1 << 26)
@@ -110,6 +109,11 @@ enum diff_words_type {
 	DIFF_WORDS_COLOR
 };
 
+enum diff_submodule_format {
+	DIFF_SUBMODULE_SHORT = 0,
+	DIFF_SUBMODULE_LOG,
+};
+
 struct diff_options {
 	const char *orderfile;
 	const char *pickaxe;
@@ -157,6 +161,7 @@ struct diff_options {
 	int stat_count;
 	const char *word_regex;
 	enum diff_words_type word_diff;
+	enum diff_submodule_format submodule_format;
 
 	/* this is set by diffcore for DIFF_FORMAT_PATCH */
 	int found_changes;
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#12 lore raw

PATCH v7 5/7 submodule: correct output of submodule log format

In reply to Jacob Keller

From: Jacob Keller <[email protected]>

The submodule log diff output incorrectly states that the submodule is "not checked out" in cases where it wants to say the submodule is "not initialized". Change the wording to reflect the actual check being performed.

---
 submodule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
submodule.c +1 -1
index 1b5cdfb7e784..e1a51b7506ff 100644
@@ -348,7 +348,7 @@ void show_submodule_summary(FILE *f, const char *path,
 	if (is_null_sha1(two))
 		message = "(submodule deleted)";
 	else if (add_submodule_odb(path))
-		message = "(not checked out)";
+		message = "(not initialized)";
 	else if (is_null_sha1(one))
 		message = "(new submodule)";
 	else if (!(left = lookup_commit_reference(one)) ||
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#8 lore raw

PATCH v7 4/7 submodule: allow do_submodule_path to work if given gitdir directly

In reply to Jacob Keller

From: Jacob Keller <[email protected]>

Currently, do_submodule_path relies on read_gitfile, which will die() if it can't read from the specified gitfile. Unfortunately, this means that do_submodule_path will not work when given the path to a submodule which is checked out directly, such as a newly added submodule which you cloned and then "git submodule add". Instead, replace the call with resolve_gitdir. This first checks to see if we've been given a gitdir already.

Because resolve_gitdir may return the same buffer it was passed, we have to check for this case as well, since strbuf_reset() will not work as expected here, and indeed is not necessary.

---
 path.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
path.c +2 -2
index 17551c483476..d1af029152a2 100644
@@ -477,8 +477,8 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
 	strbuf_complete(buf, '/');
 	strbuf_addstr(buf, ".git");
 
-	git_dir = read_gitfile(buf->buf);
-	if (git_dir) {
+	git_dir = resolve_gitdir(buf->buf);
+	if (git_dir && git_dir != buf->buf) {
 		strbuf_reset(buf);
 		strbuf_addstr(buf, git_dir);
 	}
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#2 lore raw

PATCH v7 2/7 graph: add support for --line-prefix on all graph-aware output

In reply to Jacob Keller

From: Jacob Keller <[email protected]>

Add an extension to git-diff and git-log (and any other graph-aware displayable output) such that "--line-prefix=<string>" will print the additional line-prefix on every line of output.

To make this work, we have to fix a few bugs in the graph API that force graph_show_commit_msg to be used only when you have a valid graph. Additionally, we extend the default_diff_output_prefix handler to work even when no graph is enabled.

This is somewhat of a hack on top of the graph API, but I think it should be acceptable here.

This will be used by a future extension of submodule display which displays the submodule diff as the actual diff between the pre and post commit in the submodule project.

Add some tests for both git-log and git-diff to ensure that the prefix is honored correctly.

---
 Documentation/diff-options.txt                     |   3 +
 builtin/rev-list.c                                 |  70 ++---
 diff.c                                             |   7 +
 diff.h                                             |   2 +
 graph.c                                            | 104 ++++---
 graph.h                                            |  22 +-
 log-tree.c                                         |   5 +-
 t/t4013-diff-various.sh                            |   6 +
 ...diff.diff_--line-prefix=abc_master_master^_side |  29 ++
 t/t4013/diff.diff_--line-prefix_--cached_--_file0  |  15 +
 t/t4202-log.sh                                     | 323 +++++++++++++++++++++
 11 files changed, 506 insertions(+), 80 deletions(-)
 create mode 100644 t/t4013/diff.diff_--line-prefix=abc_master_master^_side
 create mode 100644 t/t4013/diff.diff_--line-prefix_--cached_--_file0
Documentation/diff-options.txt +3 -0
index 705a87394200..cc4342e2034d 100644
@@ -569,5 +569,8 @@ endif::git-format-patch[]
 --no-prefix::
 	Do not show any source or destination prefix.
 
+--line-prefix=<prefix>::
+	Prepend an additional prefix to every line of output.
+
 For more detailed explanation on these common options, see also
 linkgit:gitdiffcore[7].
builtin/rev-list.c +31 -39

79 lines not on this page · raw message

diff.c +7 -0
index 50bef1f07658..e57cf39ad109 100644
@@ -18,6 +18,7 @@
 #include "ll-merge.h"
 #include "string-list.h"
 #include "argv-array.h"
+#include "graph.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -3966,6 +3967,12 @@ int diff_opt_parse(struct diff_options *options,
 		options->a_prefix = optarg;
 		return argcount;
 	}
+	else if ((argcount = parse_long_opt("line-prefix", av, &optarg))) {
+		options->line_prefix = optarg;
+		options->line_prefix_length = strlen(options->line_prefix);
+		graph_setup_line_prefix(options);
+		return argcount;
+	}
 	else if ((argcount = parse_long_opt("dst-prefix", av, &optarg))) {
 		options->b_prefix = optarg;
 		return argcount;
diff.h +2 -0
index 747a204d75a4..1f57aad25c71 100644
@@ -115,6 +115,8 @@ struct diff_options {
 	const char *pickaxe;
 	const char *single_follow;
 	const char *a_prefix, *b_prefix;
+	const char *line_prefix;
+	size_t line_prefix_length;
 	unsigned flags;
 	unsigned touched_flags;
 
graph.c +68 -36

216 lines not on this page · raw message

graph.h +21 -1
index 3f48c19b6208..af623390b605 100644
@@ -1,9 +1,22 @@
 #ifndef GRAPH_H
 #define GRAPH_H
+#include "diff.h"
 
 /* A graph is a pointer to this opaque structure */
 struct git_graph;
 
+/*
+ * Called to setup global display of line_prefix diff option.
+ *
+ * Passed a diff_options structure which indicates the line_prefix and the
+ * file to output the prefix to. This is sort of a hack used so that the
+ * line_prefix will be honored by all flows which also honor "--graph"
+ * regardless of whether a graph has actually been setup. The normal graph
+ * flow will honor the exact diff_options passed, but a NULL graph will cause
+ * display of a line_prefix to stdout.
+ */
+void graph_setup_line_prefix(struct diff_options *diffopt);
+
 /*
  * Set up a custom scheme for column colors.
  *
@@ -113,7 +126,14 @@ int graph_show_remainder(struct git_graph *graph);
  * missing a terminating newline (including if it is empty), the output
  * printed by graph_show_commit_msg() will also be missing a terminating
  * newline.
+ *
+ * Note that unlike some other graph display functions, you must pass the file
+ * handle directly. It is assumed that this is the same file handle as the
+ * file specified by the graph diff options. This is necessary so that
+ * graph_show_commit_msg can be called even with a NULL graph.
  */
-void graph_show_commit_msg(struct git_graph *graph, struct strbuf const *sb);
+void graph_show_commit_msg(struct git_graph *graph,
+			   FILE *file,
+			   struct strbuf const *sb);
 
 #endif /* GRAPH_H */
log-tree.c +1 -4
index bfb735c84556..8c2415747a26 100644
@@ -715,10 +715,7 @@ void show_log(struct rev_info *opt)
 	else
 		opt->missing_newline = 0;
 
-	if (opt->graph)
-		graph_show_commit_msg(opt->graph, &msgbuf);
-	else
-		fwrite(msgbuf.buf, sizeof(char), msgbuf.len, opt->diffopt.file);
+	graph_show_commit_msg(opt->graph, opt->diffopt.file, &msgbuf);
 	if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {
 		if (!opt->missing_newline)
 			graph_show_padding(opt->graph);
t/t4013-diff-various.sh +6 -0
index 94ef5000e787..566817e2efdc 100755
@@ -306,6 +306,8 @@ diff --no-index --name-status dir2 dir
 diff --no-index --name-status -- dir2 dir
 diff --no-index dir dir3
 diff master master^ side
+# Can't use spaces...
+diff --line-prefix=abc master master^ side
 diff --dirstat master~1 master~2
 diff --dirstat initial rearrange
 diff --dirstat-by-file initial rearrange
@@ -325,6 +327,10 @@ test_expect_success 'diff --cached -- file on unborn branch' '
 	git diff --cached -- file0 >result &&
 	test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
 '
+test_expect_success 'diff --line-prefix with spaces' '
+	git diff --line-prefix="| | | " --cached -- file0 >result &&
+	test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
+'
 
 test_expect_success 'diff-tree --stdin with log formatting' '
 	cat >expect <<-\EOF &&
t/t4013/diff.diff_--line-prefix=abc_master_master^_side new file +29 -0
new file mode 100644
index 000000000000..99f91e7f0e32
@@ -0,0 +1,29 @@
+$ git diff --line-prefix=abc master master^ side
+abcdiff --cc dir/sub
+abcindex cead32e,7289e35..992913c
+abc--- a/dir/sub
+abc+++ b/dir/sub
+abc@@@ -1,6 -1,4 +1,8 @@@
+abc  A
+abc  B
+abc +C
+abc +D
+abc +E
+abc +F
+abc+ 1
+abc+ 2
+abcdiff --cc file0
+abcindex b414108,f4615da..10a8a9f
+abc--- a/file0
+abc+++ b/file0
+abc@@@ -1,6 -1,6 +1,9 @@@
+abc  1
+abc  2
+abc  3
+abc +4
+abc +5
+abc +6
+abc+ A
+abc+ B
+abc+ C
+$
t/t4013/diff.diff_--line-prefix_--cached_--_file0 new file +15 -0
new file mode 100644
index 000000000000..f41ba4d36aa1
@@ -0,0 +1,15 @@
+| | | diff --git a/file0 b/file0
+| | | new file mode 100644
+| | | index 0000000..10a8a9f
+| | | --- /dev/null
+| | | +++ b/file0
+| | | @@ -0,0 +1,9 @@
+| | | +1
+| | | +2
+| | | +3
+| | | +4
+| | | +5
+| | | +6
+| | | +A
+| | | +B
+| | | +C
t/t4202-log.sh +323 -0

347 lines not on this page · raw message

Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#16 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Jacob Keller
Quoted 8 lines · Jacob Keller

[snip]

submodule.c +2 -1
@@ -333,31 +326,23 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	strbuf_release(&sb);
 }
 
-void show_submodule_summary(FILE *f, const char *path,
+/* Helper function to display the submodule header line prior to the full
+ * summary output. If it can locate the submodule objects directory it will

submodule.c static void print_submodule_summary(struct rev_info *rev, FILE *f, · line 339

Quoted 10 lines
submodule.c +6 -1
+ * attempt to lookup both the left and right commits and put them into the
+ * left and right pointers.
+ */
+static void show_submodule_header(FILE *f, const char *path,
 		const char *line_prefix,
 		unsigned char one[20], unsigned char two[20],
 		unsigned dirty_submodule, const char *meta,
-		const char *del, const char *add, const char *reset)
+		const char *reset,
+		struct commit **left, struct commit **right)

Note the pre-existing unsigned char[20]s in the signature above...

Quoted 5 lines

[snip]

submodule.c +0 -0
@@ -381,14 +401,39 @@ void show_submodule_summary(FILE *f, const char *path,
 		strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
 	fwrite(sb.buf, sb.len, 1, f);
 

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 411

Quoted 10 lines
submodule.c +8 -2
-	if (!message) /* only NULL if we succeeded in setting up the walk */
-		print_submodule_summary(&rev, f, line_prefix, del, add, reset);
+	strbuf_release(&sb);
+}
+
+void show_submodule_summary(FILE *f, const char *path,
+		const char *line_prefix,
+		unsigned char one[20], unsigned char two[20],
+		unsigned dirty_submodule, const char *meta,
+		const char *del, const char *add, const char *reset)

... and here too.

There's an ongoing effort to replace unsigned char sha1[20] with struct object_id. It might make sense to pass "one" and "two" as "unsigned char*" instead of hard-coding the SHA1-length here. Alternatively, we could pass in the struct object_id* instead.

The [20] in the show_submodule_header() function above is pre-existing and not added by this patch, but that function's signature is touched by this patch so it might make sense to tidy that up while we're in here, possibly as a separate patch.

Signature · 1 line
David
#17 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

Quoted 15 lines · David Aguilar

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 411

Quoted 5 lines
submodule.c +5 -0
+void show_submodule_summary(FILE *f, const char *path,
+             const char *line_prefix,
+             unsigned char one[20], unsigned char two[20],
+             unsigned dirty_submodule, const char *meta,
+             const char *del, const char *add, const char *reset)

... and here too.

There's an ongoing effort to replace unsigned char sha1[20] with struct object_id. It might make sense to pass "one" and "two" as "unsigned char*" instead of hard-coding the SHA1-length here. Alternatively, we could pass in the struct object_id* instead.

Quoted 5 lines

The [20] in the show_submodule_header() function above is pre-existing and not added by this patch, but that function's signature is touched by this patch so it might make sense to tidy that up while we're in here, possibly as a separate patch. --

I'll add a patch to the series that does this inbetween these commits.

Thanks,
Jake

#7 lore raw

Re: [PATCH v7 3/7] diff: prepare for additional submodule formats

In reply to Jacob Keller
Quoted 9 lines · Jacob Keller

From: Jacob Keller <[email protected]>

A future patch will add a new format for displaying the difference of a submodule. Make it easier by changing how we store the current selected format. Replace the DIFF_OPT flag with an enumeration, as each format will be mutually exclusive.

---

Looks good,
Thanks
Stefan

#9 lore raw

Re: [PATCH v7 4/7] submodule: allow do_submodule_path to work if given gitdir directly

In reply to Jacob Keller
Quoted 7 lines · Jacob Keller

From: Jacob Keller <[email protected]>

Currently, do_submodule_path relies on read_gitfile, which will die() if it can't read from the specified gitfile. Unfortunately, this means that do_submodule_path will not work when given the path to a submodule which is checked out directly, such as a newly added submodule which you cloned and then "git submodule add".

Hmm, are you sure about that?

A call to read_gitfile() turns into a call to read_gitfile_gently() with the return_error_code parameter set to NULL. The function does a stat(2), and if the given path is not a file (e.g. we created the submodule working tree and repository in-place ourselves, instead of cloning an existing project from elsewhere, in which case we would see a directory there), it says READ_GIT_FILE_ERR_NOT_A_FILE and returns NULL, because that is not a fatal error condition. The same thing happens if path does not yet exist.

This caller is given <path>, prepares "<path>/.git" in buf, and calls read_gitfile(). If it returns a non-NULL, it replaces what is in buf and continues, but if it returns a NULL (i.e. the two cases I mentioned in the above paragraph), it continues with "<path>/.git".

While I do not think changing it to resolve_gitdir() is wrong per-se, I am not sure if it is necessary.

I must be misreading something in the existing code.

Quoted 28 lines

Instead, replace the call with
resolve_gitdir. This first checks to see if we've been given a gitdir already.

Because resolve_gitdir may return the same buffer it was passed, we have to check for this case as well, since strbuf_reset() will not work as expected here, and indeed is not necessary.

---
 path.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
path.c +2 -2
index 17551c483476..d1af029152a2 100644
@@ -477,8 +477,8 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
 	strbuf_complete(buf, '/');
 	strbuf_addstr(buf, ".git");
 
-	git_dir = read_gitfile(buf->buf);
-	if (git_dir) {
+	git_dir = resolve_gitdir(buf->buf);
+	if (git_dir && git_dir != buf->buf) {
 		strbuf_reset(buf);
 		strbuf_addstr(buf, git_dir);
 	}
#22 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Jacob Keller
Quoted 8 lines · Jacob Keller
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

If we were to change those, we could discuss if we want to go with full sentences
all the time:

submodule is new
submodule is deleted
submodule is not initialized

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

I agree, I'll make a new patch that does this as a cleanup prior to this re-work.

...

Sorry for being unclear myself, too. I'm keeping it as "not initialized" and updating the description of the patch that changed it from "not checked out" to "not initialized"

Whether it is done inside or outside the scope of this series, the other two "is new"/"is deleted" updates look very sensible ones to make in the longer run. I'd further suggest to unify "commits not present" and "revision walker failed" into one error class. From the end user's point of view, they aren't very different.

#23 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

Quoted 17 lines · Junio C Hamano
Quoted 8 lines · Jacob Keller
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

If we were to change those, we could discuss if we want to go with full sentences
all the time:

submodule is new
submodule is deleted
submodule is not initialized

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

I agree, I'll make a new patch that does this as a cleanup prior to this re-work.

...

Sorry for being unclear myself, too. I'm keeping it as "not initialized" and updating the description of the patch that changed it from "not checked out" to "not initialized"

Quoted 5 lines

Whether it is done inside or outside the scope of this series, the other two "is new"/"is deleted" updates look very sensible ones to make in the longer run. I'd further suggest to unify "commits not present" and "revision walker failed" into one error class. From the end user's point of view, they aren't very different.

That won't work exactly due to the new way we separate the header format from the revision walk. I can change the error case though. The new show_submodule_header will not actually attempt a revision walk at all and thus won't know to display "revision walker failed" at the same place as the header fails. However I think almost all of the time it should succeed if commits are present.

Thanks,
Jake

#25 lore raw

Re: [PATCH v7 7/7] diff: teach diff to display submodule difference with an inline diff

In reply to Jacob Keller

diff.c static void builtin_diff(const char *name_a, · line 2327

Quoted 10 lines · Jacob Keller
        if (o->submodule_format == DIFF_SUBMODULE_LOG &&
            (!one->mode || S_ISGITLINK(one->mode)) &&
            (!two->mode || S_ISGITLINK(two->mode))) {
diff.c +3 -0
@@ -2311,6 +2322,17 @@ static void builtin_diff(const char *name_a,
                                two->dirty_submodule,
                                meta, del, add, reset);
                return;
+       } else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
+                  (!one->mode || S_ISGITLINK(one->mode)) &&
+                  (!two->mode || S_ISGITLINK(two->mode))) {

The ! mode is for added and deleted submodules, I guess?

Quoted 18 lines
diff.h +1 -0
index ea5aba668eaa..192c0eedd0ff 100644
@@ -112,6 +112,7 @@ enum diff_words_type {
 enum diff_submodule_format {
        DIFF_SUBMODULE_SHORT = 0,
        DIFF_SUBMODULE_LOG,
+       DIFF_SUBMODULE_INLINE_DIFF,
 };
 
 struct diff_options {
submodule.c +0 -0
index e341ca7ffefd..e5f1138f4362 100644
@@ -436,6 +436,67 @@ void show_submodule_summary(FILE *f, const char *path,
                clear_commit_marks(right, ~0);

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 446

Quoted 10 lines
submodule.c +8 -0
 }
 
+void show_submodule_inline_diff(FILE *f, const char *path,
+               const char *line_prefix,
+               unsigned char one[20], unsigned char two[20],
+               unsigned dirty_submodule, const char *meta,
+               const char *del, const char *add, const char *reset,
+               const struct diff_options *o)
+{
+       const char *old = EMPTY_TREE_SHA1_BIN, *new = EMPTY_TREE_SHA1_BIN;

submodule.c: In function ‘show_submodule_inline_diff’:
cache.h:957:3: warning: pointer targets in initialization differ in signedness [-Wpointer-sign]
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)

submodule.c:446:20: note: in expansion of macro ‘EMPTY_TREE_SHA1_BIN’
const char *old = EMPTY_TREE_SHA1_BIN, *new = EMPTY_TREE_SHA1_BIN;

Quoted 4 lines
submodule.c +4 -0
+       struct commit *left = NULL, *right = NULL;
+       struct strbuf submodule_dir = STRBUF_INIT;
+       struct child_process cp = CHILD_PROCESS_INIT;
+

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 460

Quoted 10 lines
submodule.c +10 -0
+       show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
+                             meta, reset, &left, &right);
+
+       /* We need a valid left and right commit to display a difference */
+       if (!(left || is_null_sha1(one)) ||
+           !(right || is_null_sha1(two)))
+               goto done;
+
+       if (left)
+               old = one;

submodule.c:460:7: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
old = one;

Quoted 14 lines
submodule.c +14 -0
+       if (right)
+               new = two;
+
+       fflush(f);
+       cp.git_cmd = 1;
+       cp.dir = path;
+       cp.out = dup(fileno(f));
+       cp.no_stdin = 1;
+
+       /* TODO: other options may need to be passed here. */
+       argv_array_pushl(&cp.args, "diff");
+       argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
+       if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
+               argv_array_pushf(&cp.args, "--src-prefix=%s%s/",

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 484

Quoted 10 lines
submodule.c +10 -0
+                                o->b_prefix, path);
+               argv_array_pushf(&cp.args, "--dst-prefix=%s%s/",
+                                o->a_prefix, path);
+       } else {
+               argv_array_pushf(&cp.args, "--src-prefix=%s%s/",
+                                o->a_prefix, path);
+               argv_array_pushf(&cp.args, "--dst-prefix=%s%s/",
+                                o->b_prefix, path);
+       }
+       argv_array_push(&cp.args, sha1_to_hex(old));

submodule.c:484:2: warning: pointer targets in passing argument 1 of ‘sha1_to_hex’ differ in signedness [-Wpointer-sign]
argv_array_push(&cp.args, sha1_to_hex(old));

/*
* nit: the following comment doesn't adhere to Gits way of doing comments:
*/

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 489

Quoted 5 lines
submodule.c +5 -0
+       /* If the submodule has modified content, we will diff against the
+        * work tree, under the assumption that the user has asked for the
+        * diff format and wishes to actually see all differences even if they
+        * haven't yet been committed to the submodule yet.
+        */

Makes sort of sense when new is HEAD.

However if I have given an explicit sha1 in the superproject, e.g.:

# (in the e.g. gerrit with a dirty submodule, I'd still expect to # get the dirtyness ignored, but the diff of those two states?) git diff --submodule=diff cc82b24..5222e66 plugins/

Quoted 7 lines
submodule.c +5 -0
+       if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
+               argv_array_push(&cp.args, sha1_to_hex(new));
+
 
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"

...

Quoted 28 lines
submodule.c +26 -0
+# String "added" in German (translated with Google Translate), encoded in UTF-8,
+# used in sample commit log messages in add_file() function below.
+added=$(printf "hinzugef\303\274gt")
 
 
+add_file () {
+       (
+               cd "$1" &&
+               shift &&
+               for name
+               do
+                       echo "$name" >"$name" &&
+                       git add "$name" &&
+                       test_tick &&
+                       # "git commit -m" would break MinGW, as Windows refuse to pass
+                       # $test_encoding encoded parameter to git.
+                       echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
+                       git -c "i18n.commitEncoding=$test_encoding" commit -F -
+               done >/dev/null &&
+               git rev-parse --short --verify HEAD
+       )
+}
+commit_file () {
+       test_tick &&
+       git commit "$@" -m "Commit $*" >/dev/null
+}
+
+test_create_repo sm1 &&

submodule.c

Quoted 10 lines
submodule.c +10 -0
+add_file . foo >/dev/null
+
+head1=$(add_file sm1 foo1 foo2)
+fullhead1=$(cd sm1; git rev-parse --verify HEAD)
+
+test_expect_success 'added submodule' '
+       git add sm1 &&
+       git diff-index -p --submodule=diff HEAD >actual &&
+       cat >expected <<-EOF &&
+       Submodule sm1 0000000...1beffeb (new submodule)

Do we also want to make the 1beffeb a variable?

submodule.c

Quoted 2 lines
submodule.c +2 -0
+       cat >expected <<-EOF &&
+       Submodule sm1 0000000...$head1 (new submodule)

In the prior test we have spelled out the sha1s, here we refer to a variable?

submodule.c

Quoted 2 lines
submodule.c +2 -0
+       EOF
+       git config --unset diff.submodule &&

Use this one weird trick to make the tests more readable!
Use "test_config" from test-lib-functions.sh
(# Set git config, automatically unsetting it after the test is over.) (I am involved in Git for 3 years now, but just recently was pointed at it)

#11 lore raw

Re: [PATCH v7 4/7] submodule: allow do_submodule_path to work if given gitdir directly

In reply to Jacob Keller
Quoted 10 lines · Jacob Keller

From: Jacob Keller <[email protected]>

Currently, do_submodule_path relies on read_gitfile, which will die() if it can't read from the specified gitfile. Unfortunately, this means that do_submodule_path will not work when given the path to a submodule which is checked out directly, such as a newly added submodule which you cloned and then "git submodule add". Instead, replace the call with resolve_gitdir. This first checks to see if we've been given a gitdir already.

Quoted 8 lines

Because resolve_gitdir may return the same buffer it was passed, we have to check for this case as well, since strbuf_reset() will not work as expected here, and indeed is not necessary.

---
 path.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good,
Thanks,
Stefan

#21 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Stefan Beller
Quoted 29 lines · Stefan Beller
Quoted 19 lines · Jacob Keller
Quoted 18 lines · Stefan Beller

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 360

Quoted 8 lines · Jacob Keller
submodule.c +8 -0
+       if (is_null_sha1(one))
+               message = "(new submodule)";
+       else if (is_null_sha1(two))
+               message = "(submodule deleted)";
+
+       if (add_submodule_odb(path)) {
+               if (!message)
+                       message = "(submodule not initialized)";

Before it was "(not initialized)" for this case, I think we'd rather keep that? Though this code path is only used by the porcelain commands, we'd rather not want to change this in a subtle way in this commit.

If we were to change those, we could discuss if we want to go with full sentences
all the time:

Quoted 8 lines
Quoted 5 lines

submodule is new
submodule is deleted
submodule is not initialized

I agree, I'll make a new patch that does this as a cleanup prior to this re-work.

Quoted 7 lines

I was actually not suggesting to change that. I rather wanted to point out that if we'd want that we'd rather do it consistently and in a different patch. Sorry for not being clear.

Thanks,
Stefan

Sorry for being unclear myself, too. I'm keeping it as "not initialized" and updating the description of the patch that changed it from "not checked out" to "not initialized"

Thanks,
Jake

Quoted 3 lines
Quoted 3 lines

Thanks,
Jake

#4 lore raw

Re: [PATCH v7 2/7] graph: add support for --line-prefix on all graph-aware output

In reply to Stefan Beller

From: Jacob Keller <[email protected]>

Quoted 34 lines · Stefan Beller
Quoted 22 lines · Jacob Keller

From: Jacob Keller <[email protected]>

(quoted diff) +0 -21
-                               /*
-                                * Add a newline after the commit message.
-                                *
-                                * Usually, this newline produces a blank
-                                * padding line between entries, in which case
-                                * we need to add graph padding on this line.
-                                *
-                                * However, the commit message may not end in a
-                                * newline.  In this case the newline simply
-                                * ends the last line of the commit message,
-                                * and we don't need any graph output.  (This
-                                * always happens with CMIT_FMT_ONELINE, and it
-                                * happens with CMIT_FMT_USERFORMAT when the
-                                * format doesn't explicitly end in a newline.)
-                                */
-                               if (buf.len && buf.buf[buf.len - 1] == '\n')
-                                       graph_show_padding(revs->graph);
-                               putchar('\n');
-                       } else {
-                               /*
-                                * If the message buffer is empty, just show

Review

Quoted 10 lines
(quoted diff) +2 -8
-                                * the rest of the graph output for this
-                                * commit.
-                                */
-                               if (graph_show_remainder(revs->graph))
-                                       putchar('\n');
-                               if (revs->commit_format == CMIT_FMT_ONELINE)
-                                       putchar('\n');
-                       }
+                       /*
+                               * Add a newline after the commit message.
Quoted 6 lines

I wondered if it is my webmailer displaying things wrongly here so I checked it at public inbox, and fetched the mails and applied them.

It seems to me as if this long comment is broken in indentation (i.e. you removed a blank ' ' directly in front of the '*' instead of a '\t' ?)

Yea it is indeed broken. Something like the following squash should fix it. We could also re-flow the text if desired too, but I don't really see the advantage.

8<-----

From 345bbaa47cc14aba7049738e99c3649e2c06748c Mon Sep 17 00:00:00 2001
From: Jacob Keller <[email protected]>
Date: Thu, 18 Aug 2016 11:13:04 -0700
Subject: [PATCH] SQUASH: fix indentation of comment in builtin/rev-list.c

---
 builtin/rev-list.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
builtin/rev-list.c +14 -14
index 1a75a83538f4..21cde8dd6b31 100644
@@ -129,20 +129,20 @@ static void show_commit(struct commit *commit, void *data)
 			graph_show_commit_msg(revs->graph, stdout, &buf);
 
 			/*
-				* Add a newline after the commit message.
-				*
-				* Usually, this newline produces a blank
-				* padding line between entries, in which case
-				* we need to add graph padding on this line.
-				*
-				* However, the commit message may not end in a
-				* newline.  In this case the newline simply
-				* ends the last line of the commit message,
-				* and we don't need any graph output.  (This
-				* always happens with CMIT_FMT_ONELINE, and it
-				* happens with CMIT_FMT_USERFORMAT when the
-				* format doesn't explicitly end in a newline.)
-				*/
+			* Add a newline after the commit message.
+			*
+			* Usually, this newline produces a blank
+			* padding line between entries, in which case
+			* we need to add graph padding on this line.
+			*
+			* However, the commit message may not end in a
+			* newline.  In this case the newline simply
+			* ends the last line of the commit message,
+			* and we don't need any graph output.  (This
+			* always happens with CMIT_FMT_ONELINE, and it
+			* happens with CMIT_FMT_USERFORMAT when the
+			* format doesn't explicitly end in a newline.)
+			*/
 			if (buf.len && buf.buf[buf.len - 1] == '\n')
 				graph_show_padding(revs->graph);
 			putchar('\n');
Signature · 1 line
2.10.0.rc0.217.g609f9e8.dirty
#5 lore raw

Re: [PATCH v7 2/7] graph: add support for --line-prefix on all graph-aware output

In reply to Stefan Beller
Quoted 13 lines · Stefan Beller

graph.c int graph_show_remainder(struct git_graph *graph) · line 1289

Quoted 11 lines · Jacob Keller

- if (!graph)
+ if (!graph) {

graph.c +5 -1
+         graph_show_line_prefix(default_diffopt);
          return;
+ }
 
-       if (graph_is_commit_finished(graph))
+       if (graph_is_commit_finished(graph)) {
+               graph_show_line_prefix(&graph->revs->diffopt);
                return 0;
+       }
Quoted 5 lines

This seems to be a reoccurring pattern, i.e. we need to add a lot of one off instructions before a return. Is it possible to make the call earlier instead
of just before the returns? (or later for that matter) ?

Not sure what you mean by this...? Just move the call up above this? I think that will work, let me give it a try.

Thanks,
Jake

Quoted 3 lines

Thanks,
Stefan

#3 lore raw

Re: [PATCH v7 2/7] graph: add support for --line-prefix on all graph-aware output

In reply to Jacob Keller
Quoted 91 lines · Jacob Keller

From: Jacob Keller <[email protected]>

Add an extension to git-diff and git-log (and any other graph-aware displayable output) such that "--line-prefix=<string>" will print the additional line-prefix on every line of output.

To make this work, we have to fix a few bugs in the graph API that force graph_show_commit_msg to be used only when you have a valid graph. Additionally, we extend the default_diff_output_prefix handler to work even when no graph is enabled.

This is somewhat of a hack on top of the graph API, but I think it should be acceptable here.

This will be used by a future extension of submodule display which displays the submodule diff as the actual diff between the pre and post commit in the submodule project.

Add some tests for both git-log and git-diff to ensure that the prefix is honored correctly.

---
 Documentation/diff-options.txt                     |   3 +
 builtin/rev-list.c                                 |  70 ++---
 diff.c                                             |   7 +
 diff.h                                             |   2 +
 graph.c                                            | 104 ++++---
 graph.h                                            |  22 +-
 log-tree.c                                         |   5 +-
 t/t4013-diff-various.sh                            |   6 +
 ...diff.diff_--line-prefix=abc_master_master^_side |  29 ++
 t/t4013/diff.diff_--line-prefix_--cached_--_file0  |  15 +
 t/t4202-log.sh                                     | 323 +++++++++++++++++++++
 11 files changed, 506 insertions(+), 80 deletions(-)
 create mode 100644 t/t4013/diff.diff_--line-prefix=abc_master_master^_side
 create mode 100644 t/t4013/diff.diff_--line-prefix_--cached_--_file0
Documentation/diff-options.txt +3 -0
index 705a87394200..cc4342e2034d 100644
@@ -569,5 +569,8 @@ endif::git-format-patch[]
 --no-prefix::
        Do not show any source or destination prefix.
 
+--line-prefix=<prefix>::
+       Prepend an additional prefix to every line of output.
+
 For more detailed explanation on these common options, see also
 linkgit:gitdiffcore[7].
builtin/rev-list.c +4 -26
index 0ba82b1635b6..1a75a83538f4 100644
@@ -122,48 +122,40 @@ static void show_commit(struct commit *commit, void *data)
                ctx.fmt = revs->commit_format;
                ctx.output_encoding = get_log_output_encoding();
                pretty_print_commit(&ctx, commit, &buf);
-               if (revs->graph) {
-                       if (buf.len) {
-                               if (revs->commit_format != CMIT_FMT_ONELINE)
-                                       graph_show_oneline(revs->graph);
+               if (buf.len) {
+                       if (revs->commit_format != CMIT_FMT_ONELINE)
+                               graph_show_oneline(revs->graph);
 
-                               graph_show_commit_msg(revs->graph, &buf);
+                       graph_show_commit_msg(revs->graph, stdout, &buf);
 
-                               /*
-                                * Add a newline after the commit message.
-                                *
-                                * Usually, this newline produces a blank
-                                * padding line between entries, in which case
-                                * we need to add graph padding on this line.
-                                *
-                                * However, the commit message may not end in a
-                                * newline.  In this case the newline simply
-                                * ends the last line of the commit message,
-                                * and we don't need any graph output.  (This
-                                * always happens with CMIT_FMT_ONELINE, and it
-                                * happens with CMIT_FMT_USERFORMAT when the
-                                * format doesn't explicitly end in a newline.)
-                                */
-                               if (buf.len && buf.buf[buf.len - 1] == '\n')
-                                       graph_show_padding(revs->graph);
-                               putchar('\n');
-                       } else {
-                               /*
-                                * If the message buffer is empty, just show

builtin/rev-list.c static void show_commit(struct commit *commit, void *data) · line 132

Quoted 10 lines
builtin/rev-list.c +2 -8
-                                * the rest of the graph output for this
-                                * commit.
-                                */
-                               if (graph_show_remainder(revs->graph))
-                                       putchar('\n');
-                               if (revs->commit_format == CMIT_FMT_ONELINE)
-                                       putchar('\n');
-                       }
+                       /*
+                               * Add a newline after the commit message.

I wondered if it is my webmailer displaying things wrongly here so I checked it at public inbox, and fetched the mails and applied them.

It seems to me as if this long comment is broken in indentation (i.e. you removed a blank ' ' directly in front of the '*' instead of a '\t' ?)

Quoted 15 lines
builtin/rev-list.c +13 -1
+                               *
+                               * Usually, this newline produces a blank
+                               * padding line between entries, in which case
+                               * we need to add graph padding on this line.
+                               *
+                               * However, the commit message may not end in a
+                               * newline.  In this case the newline simply
+                               * ends the last line of the commit message,
+                               * and we don't need any graph output.  (This
+                               * always happens with CMIT_FMT_ONELINE, and it
+                               * happens with CMIT_FMT_USERFORMAT when the
+                               * format doesn't explicitly end in a newline.)
+                               */
 
- if (!graph)

builtin/rev-list.c static void show_commit(struct commit *commit, void *data)

Quoted 10 lines
builtin/rev-list.c +6 -1
+ if (!graph) {
+         graph_show_line_prefix(default_diffopt);
          return;
+ }
 
-       if (graph_is_commit_finished(graph))
+       if (graph_is_commit_finished(graph)) {
+               graph_show_line_prefix(&graph->revs->diffopt);
                return 0;
+       }

This seems to be a reoccurring pattern, i.e. we need to add a lot of one off instructions before a return. Is it possible to make the call earlier instead
of just before the returns? (or later for that matter) ?

Thanks,
Stefan

#10 lore raw

Re: [PATCH v7 4/7] submodule: allow do_submodule_path to work if given gitdir directly

In reply to Junio C Hamano
Quoted 26 lines · Junio C Hamano
Quoted 7 lines · Jacob Keller

From: Jacob Keller <[email protected]>

Currently, do_submodule_path relies on read_gitfile, which will die() if it can't read from the specified gitfile. Unfortunately, this means that do_submodule_path will not work when given the path to a submodule which is checked out directly, such as a newly added submodule which you cloned and then "git submodule add".

Hmm, are you sure about that?

A call to read_gitfile() turns into a call to read_gitfile_gently() with the return_error_code parameter set to NULL. The function does a stat(2), and if the given path is not a file (e.g. we created the submodule working tree and repository in-place ourselves, instead of cloning an existing project from elsewhere, in which case we would see a directory there), it says READ_GIT_FILE_ERR_NOT_A_FILE and returns NULL, because that is not a fatal error condition. The same thing happens if path does not yet exist.

This caller is given <path>, prepares "<path>/.git" in buf, and calls read_gitfile(). If it returns a non-NULL, it replaces what is in buf and continues, but if it returns a NULL (i.e. the two cases I mentioned in the above paragraph), it continues with "<path>/.git".

Quoted 5 lines

While I do not think changing it to resolve_gitdir() is wrong per-se, I am not sure if it is necessary.

I must be misreading something in the existing code.

No I think you're correct. I was under the assumption that it would die here. I think it's probably better to stick with read_gitfile() here, it should work. The main issue is what happens after this needs to be fixed.

I'll investigate this more.

Thanks,
Jake

#18 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Jacob Keller
Quoted 93 lines · Jacob Keller

From: Jacob Keller <[email protected]>

A future patch is going to add a new submodule diff format which displays an inline diff of the submodule changes. To make this easier, and to ensure that both submodule diff formats use the same initial header, factor out show_submodule_header() function which will print the current submodule header line, and then leave the show_submodule_summary function to lookup and print the submodule log format.

This does create one format change in that "(revision walker failed)" will now be displayed on its own line rather than as part of the message because we no longer perform this step directly in the header display flow. However, this is a rare case and shouldn't impact much. In addition, since we no longer need to run prepare_submodule_summary to get the fast_backward and fast_forward variables, these have been removed from that call, and the show_submodule_header() function does its own mergebase lookup.

---
 submodule.c | 103 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 74 insertions(+), 29 deletions(-)
submodule.c +10 -25
index e1a51b7506ff..e341ca7ffefd 100644
@@ -277,8 +277,7 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,
 }
 
 static int prepare_submodule_summary(struct rev_info *rev, const char *path,
-               struct commit *left, struct commit *right,
-               int *fast_forward, int *fast_backward)
+               struct commit *left, struct commit *right)
 {
        struct commit_list *merge_bases, *list;
 
@@ -290,12 +289,6 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
        add_pending_object(rev, &left->object, path);
        add_pending_object(rev, &right->object, path);
        merge_bases = get_merge_bases(left, right);
-       if (merge_bases) {
-               if (merge_bases->item == left)
-                       *fast_forward = 1;
-               else if (merge_bases->item == right)
-                       *fast_backward = 1;
-       }
        for (list = merge_bases; list; list = list->next) {
                list->item->object.flags |= UNINTERESTING;
                add_pending_object(rev, &list->item->object,
@@ -333,31 +326,23 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
        strbuf_release(&sb);
 }
 
-void show_submodule_summary(FILE *f, const char *path,
+/* Helper function to display the submodule header line prior to the full
+ * summary output. If it can locate the submodule objects directory it will
+ * attempt to lookup both the left and right commits and put them into the
+ * left and right pointers.
+ */
+static void show_submodule_header(FILE *f, const char *path,
                const char *line_prefix,
                unsigned char one[20], unsigned char two[20],
                unsigned dirty_submodule, const char *meta,
-               const char *del, const char *add, const char *reset)
+               const char *reset,
+               struct commit **left, struct commit **right)
 {
-       struct rev_info rev;
-       struct commit *left = NULL, *right = NULL;
+       struct commit_list *merge_bases;
        const char *message = NULL;
        struct strbuf sb = STRBUF_INIT;
        int fast_forward = 0, fast_backward = 0;
 
-       if (is_null_sha1(two))
-               message = "(submodule deleted)";
-       else if (add_submodule_odb(path))
-               message = "(not initialized)";
-       else if (is_null_sha1(one))
-               message = "(new submodule)";
-       else if (!(left = lookup_commit_reference(one)) ||
-                !(right = lookup_commit_reference(two)))
-               message = "(commits not present)";
-       else if (prepare_submodule_summary(&rev, path, left, right,
-                                          &fast_forward, &fast_backward))
-               message = "(revision walker failed)";
-
        if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
                fprintf(f, "%sSubmodule %s contains untracked content\n",
                        line_prefix, path);
@@ -365,11 +350,46 @@ void show_submodule_summary(FILE *f, const char *path,
                fprintf(f, "%sSubmodule %s contains modified content\n",

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 360

Quoted 10 lines
submodule.c +8 -0
                        line_prefix, path);
 
+       if (is_null_sha1(one))
+               message = "(new submodule)";
+       else if (is_null_sha1(two))
+               message = "(submodule deleted)";
+
+       if (add_submodule_odb(path)) {
+               if (!message)
+                       message = "(submodule not initialized)";

Before it was "(not initialized)" for this case, I think we'd rather keep that? Though this code path is only used by the porcelain commands, we'd rather not want to change this in a subtle way in this commit.

If we were to change those, we could discuss if we want to go with full sentences
all the time:

submodule is new
submodule is deleted
submodule is not initialized

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 366

Quoted 6 lines
submodule.c +6 -0
+               goto output_header;
+       }
+
+       /*
+        * Attempt to lookup the commit references, and determine if this is
+        * a fast forward or fast backwards update

nit: end the sentence with a period

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 373

Quoted 7 lines
submodule.c +7 -0
+        */
+       *left = lookup_commit_reference(one);
+       *right = lookup_commit_reference(two);
+
+       /*
+        * Warn about missing commits in the submodule project, but only if
+        * they aren't null

nit: end the sentence with a period

Quoted 7 lines
submodule.c +7 -0
+
+void show_submodule_summary(FILE *f, const char *path,
+               const char *line_prefix,
+               unsigned char one[20], unsigned char two[20],
+               unsigned dirty_submodule, const char *meta,
+               const char *del, const char *add, const char *reset)
+{

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 422

Quoted 10 lines
submodule.c +10 -0
+       struct rev_info rev;
+       struct commit *left = NULL, *right = NULL;
+
+       show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
+                             meta, reset, &left, &right);
+
+       /*
+        * if we don't have both a left and a right pointer, then we can't
+        * display a summary
+        */

nit: Start the sentence with capital letters and end the sentence with a period. Do we need to do another thing here before the return? (Maybe that could go into the comment as well?)

#20 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Jacob Keller
Quoted 19 lines · Jacob Keller
Quoted 18 lines · Stefan Beller

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 360

Quoted 8 lines · Jacob Keller
submodule.c +8 -0
+       if (is_null_sha1(one))
+               message = "(new submodule)";
+       else if (is_null_sha1(two))
+               message = "(submodule deleted)";
+
+       if (add_submodule_odb(path)) {
+               if (!message)
+                       message = "(submodule not initialized)";

Before it was "(not initialized)" for this case, I think we'd rather keep that? Though this code path is only used by the porcelain commands, we'd rather not want to change this in a subtle way in this commit.

If we were to change those, we could discuss if we want to go with full sentences
all the time:

Quoted 8 lines
Quoted 5 lines

submodule is new
submodule is deleted
submodule is not initialized

I agree, I'll make a new patch that does this as a cleanup prior to this re-work.

I was actually not suggesting to change that. I rather wanted to point out that if we'd want that we'd rather do it consistently and in a different patch. Sorry for not being clear.

Thanks,
Stefan

Quoted 3 lines

Thanks,
Jake

#26 lore raw

Re: [PATCH v7 7/7] diff: teach diff to display submodule difference with an inline diff

In reply to Stefan Beller
Quoted 4 lines · Stefan Beller

On Wed, Aug 17, 2016 at 5:51 PM, Jacob Keller <[email protected]> wrote:

Quoted 13 lines

diff.c static void builtin_diff(const char *name_a, · line 2327

Quoted 10 lines
        if (o->submodule_format == DIFF_SUBMODULE_LOG &&
            (!one->mode || S_ISGITLINK(one->mode)) &&
            (!two->mode || S_ISGITLINK(two->mode))) {
diff.c +3 -0
@@ -2311,6 +2322,17 @@ static void builtin_diff(const char *name_a,
                                two->dirty_submodule,
                                meta, del, add, reset);
                return;
+       } else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
+                  (!one->mode || S_ISGITLINK(one->mode)) &&
+                  (!two->mode || S_ISGITLINK(two->mode))) {

The ! mode is for added and deleted submodules, I guess?

I think so? I don't really know, but it was there before for show_submodule_summary so I left it this way.

Quoted 34 lines
Quoted 18 lines
diff.h +1 -0
index ea5aba668eaa..192c0eedd0ff 100644
@@ -112,6 +112,7 @@ enum diff_words_type {
 enum diff_submodule_format {
        DIFF_SUBMODULE_SHORT = 0,
        DIFF_SUBMODULE_LOG,
+       DIFF_SUBMODULE_INLINE_DIFF,
 };
 
 struct diff_options {
submodule.c +0 -0
index e341ca7ffefd..e5f1138f4362 100644
@@ -436,6 +436,67 @@ void show_submodule_summary(FILE *f, const char *path,
                clear_commit_marks(right, ~0);

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 446

Quoted 10 lines
submodule.c +8 -0
 }
 
+void show_submodule_inline_diff(FILE *f, const char *path,
+               const char *line_prefix,
+               unsigned char one[20], unsigned char two[20],
+               unsigned dirty_submodule, const char *meta,
+               const char *del, const char *add, const char *reset,
+               const struct diff_options *o)
+{
+       const char *old = EMPTY_TREE_SHA1_BIN, *new = EMPTY_TREE_SHA1_BIN;

submodule.c: In function ‘show_submodule_inline_diff’:
cache.h:957:3: warning: pointer targets in initialization differ in signedness [-Wpointer-sign]
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)

Quoted 3 lines

submodule.c:446:20: note: in expansion of macro ‘EMPTY_TREE_SHA1_BIN’
const char *old = EMPTY_TREE_SHA1_BIN, *new = EMPTY_TREE_SHA1_BIN;

This should actually be "EMPTY_TREE_SHA1_BIN_LITERAL, and these should be unsigned, you're right. This will be fixed differently by using struct object_id * instead, though.

Thanks,
Jake

Quoted 12 lines
Quoted 12 lines
submodule.c +10 -0
+       struct commit *left = NULL, *right = NULL;
+       struct strbuf submodule_dir = STRBUF_INIT;
+       struct child_process cp = CHILD_PROCESS_INIT;
+
+       show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
+                             meta, reset, &left, &right);
+
+       /* We need a valid left and right commit to display a difference */
+       if (!(left || is_null_sha1(one)) ||
+           !(right || is_null_sha1(two)))
Quoted 10 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 460

Quoted 4 lines
submodule.c +4 -0
+               goto done;
+
+       if (left)
+               old = one;

submodule.c:460:7: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
old = one;

This will also be fixed by switching to object_id.

Quoted 31 lines
Quoted 15 lines
submodule.c +14 -0
+       if (right)
+               new = two;
+
+       fflush(f);
+       cp.git_cmd = 1;
+       cp.dir = path;
+       cp.out = dup(fileno(f));
+       cp.no_stdin = 1;
+
+       /* TODO: other options may need to be passed here. */
+       argv_array_pushl(&cp.args, "diff");
+       argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
+       if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
+               argv_array_pushf(&cp.args, "--src-prefix=%s%s/",

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 484

Quoted 10 lines
submodule.c +10 -0
+                                o->b_prefix, path);
+               argv_array_pushf(&cp.args, "--dst-prefix=%s%s/",
+                                o->a_prefix, path);
+       } else {
+               argv_array_pushf(&cp.args, "--src-prefix=%s%s/",
+                                o->a_prefix, path);
+               argv_array_pushf(&cp.args, "--dst-prefix=%s%s/",
+                                o->b_prefix, path);
+       }
+       argv_array_push(&cp.args, sha1_to_hex(old));

submodule.c:484:2: warning: pointer targets in passing argument 1 of ‘sha1_to_hex’ differ in signedness [-Wpointer-sign]
argv_array_push(&cp.args, sha1_to_hex(old));

Quoted 4 lines

/*
* nit: the following comment doesn't adhere to Gits way of doing comments:
*/

Yea, sorry. I have a habbit of the other format because the Linux kernel networking tree requires this style, despite the rest of the Linux kernel requiring the style used by git. So, I have to break out of that habbit but sometimes I miss them.

Quoted 6 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 489

Quoted 5 lines
submodule.c +5 -0
+       /* If the submodule has modified content, we will diff against the
+        * work tree, under the assumption that the user has asked for the
+        * diff format and wishes to actually see all differences even if they
+        * haven't yet been committed to the submodule yet.
+        */
Quoted 8 lines

Makes sort of sense when new is HEAD.

However if I have given an explicit sha1 in the superproject, e.g.:

# (in the e.g. gerrit with a dirty submodule, I'd still expect to # get the dirtyness ignored, but the diff of those two states?) git diff --submodule=diff cc82b24..5222e66 plugins/

AFAIK it actually does, because dirty_submodule won't be set with DIRTY_SUBMODULE_MODIFIED unless you're actually diffing against the index or worktree directly. So if you diff two commits they never show these flags regardless of what's in your work tree.

If you diff some commit against your work tree then you might have this flag set.

Quoted 9 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 495

Quoted 6 lines
submodule.c +6 -0
+
+test_expect_success 'added submodule' '
+       git add sm1 &&
+       git diff-index -p --submodule=diff HEAD >actual &&
+       cat >expected <<-EOF &&
+       Submodule sm1 0000000...1beffeb (new submodule)

Do we also want to make the 1beffeb a variable?

Sure

Quoted 5 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 497

Quoted 2 lines
submodule.c +2 -0
+       cat >expected <<-EOF &&
+       Submodule sm1 0000000...$head1 (new submodule)

In the prior test we have spelled out the sha1s, here we refer to a variable?

I copied these from another file and modified them to use diff, but I can work this to use variables consistently.

Quoted 8 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 499

Quoted 3 lines
submodule.c +2 -0
+       EOF
+       git config --unset diff.submodule &&

Use this one weird trick to make the tests more readable!
Use "test_config" from test-lib-functions.sh
(# Set git config, automatically unsetting it after the test is over.) (I am involved in Git for 3 years now, but just recently was pointed at it)

Yea, this was copied directly from another test file and modified to use "inline diff" format instead of log format, which is why some of these are done this way. I'll switch this to test_config.

Thanks,
Jake

#19 lore raw

Re: [PATCH v7 6/7] submodule: refactor show_submodule_summary with helper function

In reply to Stefan Beller
Quoted 14 lines · Stefan Beller

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 360

Quoted 8 lines · Jacob Keller
submodule.c +8 -0
+       if (is_null_sha1(one))
+               message = "(new submodule)";
+       else if (is_null_sha1(two))
+               message = "(submodule deleted)";
+
+       if (add_submodule_odb(path)) {
+               if (!message)
+                       message = "(submodule not initialized)";

Before it was "(not initialized)" for this case, I think we'd rather keep that? Though this code path is only used by the porcelain commands, we'd rather not want to change this in a subtle way in this commit.

Quoted 9 lines

If we were to change those, we could discuss if we want to go with full sentences
all the time:

submodule is new
submodule is deleted
submodule is not initialized

I agree, I'll make a new patch that does this as a cleanup prior to this re-work.

Thanks,
Jake

#14 lore raw

Re: [PATCH v7 5/7] submodule: correct output of submodule log format

In reply to Stefan Beller
Quoted 13 lines · Stefan Beller
Quoted 12 lines · Jacob Keller

From: Jacob Keller <[email protected]>

The submodule log diff output incorrectly states that the submodule is "not checked out" in cases where it wants to say the submodule is "not initialized". Change the wording to reflect the actual check being performed.

---
 submodule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 351

Quoted 10 lines
submodule.c +1 -1
index 1b5cdfb7e784..e1a51b7506ff 100644
@@ -348,7 +348,7 @@ void show_submodule_summary(FILE *f, const char *path,
        if (is_null_sha1(two))
                message = "(submodule deleted)";
        else if (add_submodule_odb(path))
-               message = "(not checked out)";
+               message = "(not initialized)";

I think "not checked" out is actually correct here.

Hmmm.. It shouldn't say not checked out. I was running iinto problems in some of my tests which indicated that the entire sub module didn't exist. I think I had already assumed it wasn't failing when no checkout. I think I have some fix for add_submodule_odb that can help with this, making submodule dir behave correctly for this case.

I want add_submodule_odb to work in both of these cases:

a) we don't have a working checkout but we have the objects in the usual location
b) we have a working directory with objects inside a .git folder but it hasn't yet been moved into .git/modules/<>

I'll take a look and see what I can do.

Quoted 29 lines
    $ git clone https://gerrit.googlesource.com/gerrit
    $ cd gerrit
    $ git submodule update --init
      ...
    $ git diff cc82b24..5222e66 plugins/
    Submodule plugins/cookbook-plugin 2d40ee2..69b8f9f:
     > Organize imports
    $ rm -rf plugins/cookbook-plugin/
    $ git diff cc82b24..5222e66 plugins/
    Submodule plugins/cookbook-plugin 2d40ee2...69b8f9f (not checked out)
    $

Mind that by "rm -rf" of the working dir I create the "not checked out, but initialized state and even cloned state".

So as a long term TODO:
I guess we could teach add_submodule_odb to operate inside its git directory instead of its working directory, to have it working whenever we have the object database (no matter if checked out or not). Although this may collide with the plan of a different refs backend? I dunno.

add_submodule_odb is used in a variety of places:
show_submodule_header
submodule_needs_pushing
push_submodule
is_submodule_commit_present
merge_submodule

Quoted 2 lines

And all of them seem to not require a checkout, but the presence of objects is fine.

Yea, they really only need objects, not the working tree.

Thanks,
Jake

#13 lore raw

Re: [PATCH v7 5/7] submodule: correct output of submodule log format

In reply to Jacob Keller
Quoted 17 lines · Jacob Keller

From: Jacob Keller <[email protected]>

The submodule log diff output incorrectly states that the submodule is "not checked out" in cases where it wants to say the submodule is "not initialized". Change the wording to reflect the actual check being performed.

---
 submodule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
submodule.c +0 -0
index 1b5cdfb7e784..e1a51b7506ff 100644

submodule.c void show_submodule_summary(FILE *f, const char *path, · line 351

Quoted 5 lines
submodule.c +1 -1
@@ -348,7 +348,7 @@ void show_submodule_summary(FILE *f, const char *path,
        if (is_null_sha1(two))
                message = "(submodule deleted)";
        else if (add_submodule_odb(path))
-               message = "(not checked out)";
+               message = "(not initialized)";

I think "not checked" out is actually correct here.

    $ git clone https://gerrit.googlesource.com/gerrit
    $ cd gerrit
    $ git submodule update --init
      ...
    $ git diff cc82b24..5222e66 plugins/
    Submodule plugins/cookbook-plugin 2d40ee2..69b8f9f:
     > Organize imports
    $ rm -rf plugins/cookbook-plugin/
    $ git diff cc82b24..5222e66 plugins/
    Submodule plugins/cookbook-plugin 2d40ee2...69b8f9f (not checked out)
    $

Mind that by "rm -rf" of the working dir I create the "not checked out, but initialized state and even cloned state".

So as a long term TODO:
I guess we could teach add_submodule_odb to operate inside its git directory instead of its working directory, to have it working whenever we have the object database (no matter if checked out or not). Although this may collide with the plan of a different refs backend? I dunno.

add_submodule_odb is used in a variety of places:
show_submodule_header
submodule_needs_pushing
push_submodule
is_submodule_commit_present
merge_submodule

And all of them seem to not require a checkout, but the presence of objects is fine.