submodule inline diff format
v12 cover submodule inline diff format
From: Jacob Keller <[email protected]>
Hopefully the final revision here. I've squashed in the memory leak fix suggested by Stefan, and the suggested changes from Junio, including his re-worded commit messages.
interdiff between v11 and v12
path.c +4 -2
@@ -467,7 +467,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)return pathname->buf; } -/* Returns 0 on success, non-zero on failure. */ +/* Returns 0 on success, negative on failure. */ #define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1static int do_submodule_path (struct strbuf *buf,const char *path,const char *fmt,va_list args)
@@ -523,8 +523,10 @@ char *git_pathdup_submodule(const char *path, const char *fmt, ...)va_start (args, fmt); err =do_submodule_path (&buf, path, fmt, args);va_end (args); -if (err) +if (err) { +strbuf_release (&buf);return NULL ; + }return strbuf_detach (&buf,NULL ); }
-------->8
Jacob Keller (7):
cache: add empty_tree_oid object and helper function
graph: add support for --line-prefix on all graph-aware output
diff: prepare for additional submodule formats
allow do_submodule_path to work even if submodule isn't checked out
submodule: convert show_submodule_summary to use struct object_id *
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 +- cache.h | 29 +- diff.c | 64 +- diff.h | 11 +- graph.c | 100 ++- graph.h | 22 +- log-tree.c | 5 +- path.c | 39 +- refs/files-backend.c | 8 +- sha1_file.c | 6 + submodule.c | 190 +++++- submodule.h | 8 +- 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-not-initialized.sh | 127 ++++ t/t4060-diff-submodule-option-diff-format.sh | 749 +++++++++++++++++++++ t/t4202-log.sh | 323 +++++++++ 20 files changed, 1666 insertions(+), 164 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-not-initialized.sh create mode 100755 t/t4060-diff-submodule-option-diff-format.sh
Signature · 1 line
2.10.0.rc2.311.g2bd286e
PATCH v12 1/8 cache: add empty_tree_oid object and helper function
From: Jacob Keller <[email protected]>
Similar to is_null_oid(), and is_empty_blob_sha1() add an empty_tree_oid along with helper function is_empty_tree_oid(). For completeness, also add an "is_empty_tree_sha1()", "is_empty_blob_sha1()", "is_empty_tree_oid()" and "is_empty_blob_oid()" helpers.
To ensure we only get one singleton, implement EMPTY_BLOB_SHA1_BIN as simply getting the hash of empty_blob_oid structure.
--- cache.h | 25 +++++++++++++++++++++---- sha1_file.c | 6 ++++++ 2 files changed, 27 insertions(+), 4 deletions(-)
cache.h +21 -4
@@ -953,22 +953,39 @@ static inline void oidclr(struct object_id *oid)#define EMPTY_TREE_SHA1_BIN_LITERAL \ "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \ "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04" -#define EMPTY_TREE_SHA1_BIN \ - ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL) +extern const struct object_id empty_tree_oid; +#define EMPTY_TREE_SHA1_BIN (empty_tree_oid.hash)#define EMPTY_BLOB_SHA1_HEX \ "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"#define EMPTY_BLOB_SHA1_BIN_LITERAL \ "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \ "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91" -#define EMPTY_BLOB_SHA1_BIN \ - ((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL) +extern const struct object_id empty_blob_oid; +#define EMPTY_BLOB_SHA1_BIN (empty_blob_oid.hash) +static inline int is_empty_blob_sha1 (const unsigned char *sha1) {return !hashcmp (sha1,EMPTY_BLOB_SHA1_BIN ); } +static inline int is_empty_blob_oid (const struct object_id *oid) +{ +return !hashcmp (oid->hash,EMPTY_BLOB_SHA1_BIN ); +} + +static inline int is_empty_tree_sha1 (const unsigned char *sha1) +{ +return !hashcmp (sha1,EMPTY_TREE_SHA1_BIN ); +} + +static inline int is_empty_tree_oid (const struct object_id *oid) +{ +return !hashcmp (oid->hash,EMPTY_TREE_SHA1_BIN ); +} + +int git_mkstemp (char *path,size_t n,const char *template);/* set default permissions by passing mode arguments to open(2) */
sha1_file.c +6 -0
@@ -38,6 +38,12 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }const unsigned char null_sha1[20 ];const struct object_id null_oid; +const struct object_id empty_tree_oid = { +EMPTY_TREE_SHA1_BIN_LITERAL +}; +const struct object_id empty_blob_oid = { +EMPTY_BLOB_SHA1_BIN_LITERAL +};/* * This is meant to hold a *small* number of objects that you would
Signature · 1 line
2.10.0.rc2.311.g2bd286e
PATCH v12 2/8 diff.c: remove output_prefix_length field
In reply to Jacob KellerFrom: 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
@@ -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
@@ -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
@@ -197,7 +197,6 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, voidassert (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.rc2.311.g2bd286e
PATCH v12 3/8 graph: add support for --line-prefix on all graph-aware output
In reply to Jacob KellerFrom: 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 | 98 ++++--- 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, 502 insertions(+), 78 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
@@ -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
@@ -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
@@ -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 +64 -34
206 lines not on this page · raw message
graph.h +21 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.rc2.311.g2bd286e
Re: [PATCH v12 3/8] graph: add support for --line-prefix on all graph-aware output
Quoted 5 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.
This patch breaks git rev-list --header, also breaking gitweb.
The NUL between commits has gone missing, causing gitweb to interpret the output of git rev-list as one commit.
Sorry for not catching this earlier, I actually encountered this early september but thought it was caused by us running an ancient gitweb with a modern git. Finally managed to upgrade gitweb today, and the bug didn't go away. git bisect says 660e113ce is the culprit. Checking out 'next' and reverting this single patch makes the problem disappear.
Haven't yet tried to fix the bug, but this hunk looks suspicious:
- if (revs->commit_format != CMIT_FMT_USERFORMAT || - buf.len) {
- fwrite(buf.buf, 1, buf.len, stdout); - putchar(info->hdr_termination); - }
+ /*
+ * If the message buffer is empty, just show + * the rest of the graph output for this + * commit.
+ */
+ if (graph_show_remainder(revs->graph)) + putchar('\n');
+ if (revs->commit_format == CMIT_FMT_ONELINE) +
D.
PATCH 1/1 rev-list: restore the NUL commit separator in --header mode
Commit 660e113 (graph: add support for --line-prefix on all graph-aware output) changed the way commits were shown. Unfortunately this dropped the NUL between commits in --header mode. Restore the NUL and add a test for this feature.
--- builtin/rev-list.c | 4 ++++ t/t6000-rev-list-misc.sh | 7 +++++++ 2 files changed, 11 insertions(+)
builtin/rev-list.c +4 -0
@@ -157,6 +157,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->commit_format ==CMIT_FMT_ONELINE )putchar ('\n' ); } +if (revs->commit_format ==CMIT_FMT_RAW ) { +putchar (info->hdr_termination); + } +strbuf_release (&buf); }else {if (graph_show_remainder (revs->graph))
t/t6000-rev-list-misc.sh +7 -0
@@ -100,4 +100,11 @@ test_expect_success '--bisect and --first-parent can not be combined' ' test_must_fail git rev-list --bisect --first-parent HEAD ' +test_expect_success '--header shows a NUL after each commit' ' + touch expect && + printf "\0" > expect && + git rev-list --header --max-count=1 HEAD | tail -n1 >actual && + test_cmp_bin expect actual +' + test_done
Signature · 6 lines
2.10.1-449-gab0f84c -- Dennis Kaarsemaker <[email protected]> http://twitter.com/seveas
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Hi,
Quoted 5 lines · Dennis Kaarsemaker
Commit 660e113 (graph: add support for --line-prefix on all graph-aware output) changed the way commits were shown. Unfortunately this dropped the NUL between commits in --header mode. Restore the NUL and add a test for this feature.
Oops! Thanks for the bug fix.
Quoted 11 lines
Signed-off-by Dennis Kaarsemaker <[email protected]>--- builtin/rev-list.c | 4 ++++ t/t6000-rev-list-misc.sh | 7 +++++++ 2 files changed, 11 insertions(+)builtin/rev-list.c +0
-0
builtin/rev-list.c static void show_commit(struct commit *commit, void *data) · line 163
Quoted 7 lines
builtin/rev-list.c +4
-0@@ -157,6 +157,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->commit_format ==CMIT_FMT_ONELINE )putchar ('\n' ); } +if (revs->commit_format ==CMIT_FMT_RAW ) { +putchar (info->hdr_termination); + } +
This seems right to me. My one concern is that we make sure we restore it for every case (in case it needs to be there for other formats?) I'm not entirely sure about whether other non-raw modes need this or not?
Thanks,
Jake
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Quoted 27 lines · Jacob Keller
Hi,
Quoted 5 lines · Dennis Kaarsemaker
Commit 660e113 (graph: add support for --line-prefix on all graph-aware output) changed the way commits were shown. Unfortunately this dropped the NUL between commits in --header mode. Restore the NUL and add a test for this feature.
Oops! Thanks for the bug fix.
Quoted 15 lines
Signed-off-by Dennis Kaarsemaker <[email protected]>--- builtin/rev-list.c | 4 ++++ t/t6000-rev-list-misc.sh | 7 +++++++ 2 files changed, 11 insertions(+)builtin/rev-list.c +1
-0@@ -157,6 +157,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->commit_format ==CMIT_FMT_ONELINE )putchar ('\n' ); } +if (revs->commit_format ==CMIT_FMT_RAW ) {
Quoted 8 lines
builtin/rev-list.c static void show_commit(struct commit *commit, void *data) · line 163
Quoted 3 lines
builtin/rev-list.c +3
-0+putchar (info->hdr_termination); + } +This seems right to me. My one concern is that we make sure we restore it for every case (in case it needs to be there for other formats?) I'm not entirely sure about whether other non-raw modes need this or not?
Right. The original didn't do anything special for CMIT_FMT_RAW, and 660e113 did not remove anything special for CMIT_FMT_RAW, so it isn't immediately obvious why this patch is sufficient.
Dennis, care to elaborate?
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Quoted 48 lines · Junio C Hamano
Quoted 37 lines · Jacob Keller
Hi,
Quoted 9 lines · Dennis Kaarsemaker
Commit 660e113 (graph: add support for --line-prefix on all graph-aware
output) changed the way commits were shown. Unfortunately this dropped
the NUL between commits in --header mode. Restore the NUL and add a test
for this feature.Oops! Thanks for the bug fix.
Quoted 20 lines
Signed-off-by Dennis Kaarsemaker <[email protected]>---
builtin/rev-list.c | 4 ++++
t/t6000-rev-list-misc.sh | 7 +++++++2 files changed, 11 insertions(+)builtin/rev-list.c +0
-0@@ -157,6 +157,10 @@ static void show_commit(struct commit *commit, void *data)if (
revs->commit_format==CMIT_FMT_ONELINE)
putchar('\n');
}
+ if (revs->commit_format==CMIT_FMT_RAW) { + putchar(info->hdr_termination); + }Quoted 8 lines
Quoted 1 line
+
This seems right to me. My one concern is that we make sure we restore
it for every case (in case it needs to be there for other formats?) I'm not entirely sure about whether other non-raw modes need this or
not?
Quoted 5 lines
Right. The original didn't do anything special for
CMIT_FMT_RAW, and 660e113 did not remove anything special forCMIT_FMT_RAW, so it isn't immediately obvious why this patch is sufficient.Dennis, care to elaborate?
I believe all we need to do is change one of the places where we emit "\n" with emiting info->hdr_termination instead.
I'm looking at the original code now.
Thanks,
Jake
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
In reply to Junio C HamanoQuoted 41 lines · Junio C Hamano
Quoted 29 lines · Jacob Keller
Hi,
Quoted 5 lines · Dennis Kaarsemaker
Commit 660e113 (graph: add support for --line-prefix on all graph-aware output) changed the way commits were shown. Unfortunately this dropped the NUL between commits in --header mode. Restore the NUL and add a test for this feature.
Oops! Thanks for the bug fix.
Quoted 16 lines
Signed-off-by Dennis Kaarsemaker <[email protected]>--- builtin/rev-list.c | 4 ++++ t/t6000-rev-list-misc.sh | 7 +++++++ 2 files changed, 11 insertions(+)builtin/rev-list.c +2
-0@@ -157,6 +157,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->commit_format ==CMIT_FMT_ONELINE )putchar ('\n' ); } +if (revs->commit_format ==CMIT_FMT_RAW ) { +putchar (info->hdr_termination);Quoted 8 lines
builtin/rev-list.c static void show_commit(struct commit *commit, void *data) · line 163
Quoted 2 lines
builtin/rev-list.c +2
-0+ } +This seems right to me. My one concern is that we make sure we restore it for every case (in case it needs to be there for other formats?) I'm not entirely sure about whether other non-raw modes need this or not?
Quoted 5 lines
Right. The original didn't do anything special for
CMIT_FMT_RAW, and 660e113 did not remove anything special forCMIT_FMT_RAW, so it isn't immediately obvious why this patch is sufficient.Dennis, care to elaborate?
The original logic was (best seen with git show -w 660e113):
if(showing graphs) {
do pretty things
}
else {
just print the buffer and the header terminator
}
660e113 changed that to
do pretty things
Given that the 'do pretty things part' works for other uses of git rev- list, it made sense that the \0 should only be added back in CMIT_FMT_RAW mode. Changing the first putchar('\n') as Jacob proposes (that mail arrived while I'm typing this) might work too, I haven't tested it.
D.
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
In reply to Dennis Kaarsemakert/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 105
Quoted 2 lines · Dennis Kaarsemaker
t/t6000-rev-list-misc.sh +2
-0+ touch expect && + printf "\0" > expect &&
What's the point of that "touch", especially if you are going to overwrite it immediately after?
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 106
Quoted 1 line
t/t6000-rev-list-misc.sh +1
-0+ git rev-list --header --max-count=1 HEAD | tail -n1 >actual &&
As "tail" is a tool for text files, it is likely unportable to use "tail -n1" to grab the "last incomplete line that happens to contain a single NUL".
Quoted 2 lines
t/t6000-rev-list-misc.sh +2
-0+ test_cmp_bin expect actual +'
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Quoted 8 lines · Junio C Hamano
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 105
Quoted 2 lines · Dennis Kaarsemaker
t/t6000-rev-list-misc.sh +2
-0+ touch expect && + printf "\0" > expect &&What's the point of that "touch", especially if you are going to overwrite it immediately after?
Leftover debugging crud. I tried various ways of generating an actual/expect to compare.
Quoted 9 lines
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 106
Quoted 1 line
t/t6000-rev-list-misc.sh +1
-0+ git rev-list --header --max-count=1 HEAD | tail -n1 >actual &&As "tail" is a tool for text files, it is likely unportable to use "tail -n1" to grab the "last incomplete line that happens to contain a single NUL".
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 108
Quoted 2 lines
t/t6000-rev-list-misc.sh +2
-0+ test_cmp_bin expect actual +'
Yeah, I was fearing that. I didn't find anything in the testsuite that helps answering the question "does this file end with a NUL" and would appreciate a hint :)
D.
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Quoted 20 lines · Dennis Kaarsemaker
Quoted 8 lines · Junio C Hamano
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 105
Quoted 2 lines · Dennis Kaarsemaker
t/t6000-rev-list-misc.sh +2
-0+ touch expect && + printf "\0" > expect &&What's the point of that "touch", especially if you are going to overwrite it immediately after?
Leftover debugging crud. I tried various ways of generating an actual/expect to compare.
Quoted 7 lines
Quoted 1 line
+ git rev-list --header --max-count=1 HEAD | tail -n1 >actual &&
As "tail" is a tool for text files, it is likely unportable to use "tail -n1" to grab the "last incomplete line that happens to contain a single NUL".
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
+
test_cmp_binexpect actual
+'Yeah, I was fearing that. I didn't find anything in the testsuite that helps answering the question "does this file end with a NUL" and would appreciate a hint :)
D.
I did some searching, and we do use sed so I replaced it with sed \$!d which appears to work. I think we should probably implement a test_ends_with_nul or something.
Thanks,
Jake
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
Quoted 3 lines · Jacob Keller
I did some searching, and we do use sed so I replaced it with sed \$!d which appears to work. I think we should probably implement a
test_ends_with_nulor something.
As it is "a stream editor that shall read one or more text files", I do not think "sed" is any better (or any worse) than "tail -n" from the portability point of view. They both may happen to work on GNU systems.
Re: [PATCH] rev-list: restore the NUL commit separator in --header mode
In reply to Dennis Kaarsemakert/t6000-rev-list-misc.sh +0 -0
t/t6000-rev-list-misc.sh test_expect_success '--bisect and --first-parent can not be combined' ' · line 105
Quoted 10 lines
index 3e752ce..a2acff3 100755
t/t6000-rev-list-misc.sh +3
-0@@ -100,4 +100,11 @@ test_expect_success '--bisect and --first-parent can not be combined' ' test_must_fail git rev-list --bisect --first-parent HEAD ' +test_expect_success '--header shows a NUL after each commit' ' + touch expect && + printf "\0" > expect &&
Micronit: No ' ' after '>'
(And why do we need the touch ?)
+ printf "\0" >expect &&
Quoted 5 lines
t/t6000-rev-list-misc.sh +4
-0+ git rev-list --header --max-count=1 HEAD | tail -n1 >actual && + test_cmp_bin expect actual +' + test_done
Re: [PATCH v12 3/8] graph: add support for --line-prefix on all graph-aware output
In reply to Dennis KaarsemakerHi,
Quoted 9 lines · Dennis Kaarsemaker
Quoted 5 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.
This patch breaks git rev-list --header, also breaking gitweb.
Oops! Is it possible you have a test case already?
Quoted 3 lines
The NUL between commits has gone missing, causing gitweb to interpret the output of git rev-list as one commit.
That is obviously not what we want!
Quoted 6 lines
Sorry for not catching this earlier, I actually encountered this early september but thought it was caused by us running an ancient gitweb with a modern git. Finally managed to upgrade gitweb today, and the bug didn't go away. git bisect says
660e113ceis the culprit. Checking out 'next' and reverting this single patch makes the problem disappear.
Ok.
Quoted 7 lines
Haven't yet tried to fix the bug, but this hunk looks suspicious:
builtin/rev-list.c +0
-2-if (revs->commit_format !=CMIT_FMT_USERFORMAT || - buf.len) {
builtin/rev-list.c static void show_commit(struct commit *commit, void *data) · line 156
Quoted 10 lines
builtin/rev-list.c +7
-3-fwrite (buf.buf,1 , buf.len, stdout); -putchar (info->hdr_termination); - } +/* +* If the message buffer is empty, just show +* the rest of the graph output for this +* commit. +*/ +if (graph_show_remainder (revs->graph)) +putchar ('\n' );
Most likely this should have been "putchar(info->hdr_termination);" I think? Not entirely sure.
If we can get a test case in we can use that to help debug the issue.
Thanks,
Jake
Quoted 4 lines
(quoted diff) +2
-0+ if (revs->commit_format == CMIT_FMT_ONELINE) +D.
PATCH v12 4/8 diff: prepare for additional submodule formats
In reply to Jacob KellerFrom: 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
@@ -132,9 +132,9 @@ static int parse_dirstat_params(struct diff_options *options, const char *paramsstatic 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
@@ -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.rc2.311.g2bd286e
PATCH v12 5/8 allow do_submodule_path to work even if submodule isn't checked out
In reply to Jacob KellerFrom: Jacob Keller <[email protected]>
Currently, do_submodule_path will attempt locating the .git directory by using read_gitfile on <path>/.git. If this fails it just assumes the <path>/.git is actually a git directory.
This is good because it allows for handling submodules which were cloned in a regular manner first before being added to the superproject.
Unfortunately this fails if the <path> is not actually checked out any longer, such as by removing the directory.
Fix this by checking if the directory we found is actually a gitdir. In the case it is not, attempt to lookup the submodule configuration and find the name of where it is stored in the .git/modules/ directory of the superproject.
If we can't locate the submodule configuration, this might occur because for example a submodule gitlink was added but the corresponding .gitmodules file was not properly updated. A die() here would not be pleasant to the users of submodule diff formats, so instead, modify do_submodule_path() to return an error code:
- git_pathdup_submodule() returns NULL when we fail to find a path.
- strbuf_git_path_submodule() propagates the error code to the caller.
Modify the callers of these functions to check the error code and fail properly. This ensures we don't attempt to use a bad path that doesn't match the corresponding submodule.
Because this change fixes add_submodule_odb() to work even if the submodule is not checked out, update the wording of the submodule log diff format to correctly display that the submodule is "not initialized" instead of "not checked out"
Add tests to ensure this change works as expected.
--- cache.h | 4 +- path.c | 39 +++++++-- refs/files-backend.c | 8 +- submodule.c | 6 +- t/t4059-diff-submodule-not-initialized.sh | 127 ++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 11 deletions(-) create mode 100755 t/t4059-diff-submodule-not-initialized.sh
cache.h +2 -2
@@ -819,8 +819,8 @@ extern void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...) __attribute__((format (printf, 2, 3)));extern char *git_path_buf (struct strbuf *buf,const char *fmt, ...) __attribute__((format (printf,2 ,3 ))); -extern void strbuf_git_path_submodule (struct strbuf *sb,const char *path, -const char *fmt, ...) +extern int strbuf_git_path_submodule (struct strbuf *sb,const char *path, +const char *fmt, ...) __attribute__((format (printf,3 ,4 )));extern char *git_pathdup (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));
path.c +33 -6
@@ -6,6 +6,7 @@#include "string-list.h" #include "dir.h" #include "worktree.h" +#include "submodule-config.h" static int get_st_mode_bits (const char *path,int *mode) {
@@ -466,12 +467,16 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)return pathname->buf; } -static void do_submodule_path (struct strbuf *buf,const char *path, -const char *fmt,va_list args) +/* Returns 0 on success, negative on failure. */ +#define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1 +static int do_submodule_path (struct strbuf *buf,const char *path, +const char *fmt,va_list args) {const char *git_dir;struct strbuf git_submodule_common_dir =STRBUF_INIT ;struct strbuf git_submodule_dir =STRBUF_INIT ; +const struct submodule *sub; +int err =0 ;strbuf_addstr (buf, path);strbuf_complete (buf,'/' );
@@ -482,6 +487,17 @@ static void do_submodule_path(struct strbuf *buf, const char *path,strbuf_reset (buf);strbuf_addstr (buf, git_dir); } +if (!is_git_directory (buf->buf)) { +gitmodules_config (); + sub =submodule_from_path (null_sha1, path); +if (!sub) { + err =SUBMODULE_PATH_ERR_NOT_CONFIGURED ; + goto cleanup; + } +strbuf_reset (buf); +strbuf_git_path (buf,"%s/%s" ,"modules" , sub->name); + } +strbuf_addch (buf,'/' );strbuf_addbuf (&git_submodule_dir, buf);
@@ -492,27 +508,38 @@ static void do_submodule_path(struct strbuf *buf, const char *path,strbuf_cleanup_path (buf); +cleanup:strbuf_release (&git_submodule_dir);strbuf_release (&git_submodule_common_dir); + +return err; }char *git_pathdup_submodule (const char *path,const char *fmt, ...) { +int err;va_list args;struct strbuf buf =STRBUF_INIT ;va_start (args, fmt); -do_submodule_path (&buf, path, fmt, args); + err =do_submodule_path (&buf, path, fmt, args);va_end (args); +if (err) { +strbuf_release (&buf); +return NULL ; + }return strbuf_detach (&buf,NULL ); } -void strbuf_git_path_submodule (struct strbuf *buf,const char *path, -const char *fmt, ...) +int strbuf_git_path_submodule (struct strbuf *buf,const char *path, +const char *fmt, ...) { +int err;va_list args;va_start (args, fmt); -do_submodule_path (buf, path, fmt, args); + err =do_submodule_path (buf, path, fmt, args);va_end (args); + +return err; } static void do_git_common_path(struct strbuf *buf,
refs/files-backend.c +7 -1
@@ -1225,13 +1225,19 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)struct strbuf refname;struct strbuf path =STRBUF_INIT ;size_t path_baselen; +int err =0 ;if (*refs->name) -strbuf_git_path_submodule (&path, refs->name,"%s" , dirname); + err =strbuf_git_path_submodule (&path, refs->name,"%s" , dirname);else strbuf_git_path (&path,"%s" , dirname); path_baselen = path.len; +if (err) { +strbuf_release (&path); +return ; + } + d =opendir (path.buf);if (!d) {strbuf_release (&path);
submodule.c +4 -2
@@ -127,7 +127,9 @@ static int add_submodule_odb(const char *path)int ret =0 ;size_t alloc; -strbuf_git_path_submodule (&objects_directory, path,"objects/" ); + ret =strbuf_git_path_submodule (&objects_directory, path,"objects/" ); +if (ret) + goto done;if (!is_directory (objects_directory.buf)) { ret =-1 ; goto done;
@@ -348,7 +350,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)) ||
t/t4059-diff-submodule-not-initialized.sh new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.10.0.rc2.311.g2bd286e
PATCH v12 6/8 submodule: convert show_submodule_summary to use struct object_id *
In reply to Jacob KellerFrom: Jacob Keller <[email protected]>
Since we're going to be changing this function in a future patch, lets go ahead and convert this to use object_id now.
--- diff.c | 2 +- submodule.c | 16 ++++++++-------- submodule.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
diff.c +1 -1
@@ -2307,7 +2307,7 @@ static void builtin_diff(const char *name_a,const char *add =diff_get_color_opt (o,DIFF_FILE_NEW );show_submodule_summary (o->file, one->path ? one->path : two->path, line_prefix, - one->oid.hash, two->oid.hash, + &one->oid, &two->oid, two->dirty_submodule, meta, del, add, reset);return ;
submodule.c +8 -8
@@ -337,7 +337,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,void show_submodule_summary (FILE *f,const char *path,const char *line_prefix, -unsigned char one[20 ],unsigned char two[20 ], +struct object_id *one,struct object_id *two,unsigned dirty_submodule,const char *meta,const char *del,const char *add,const char *reset) {
@@ -347,14 +347,14 @@ void show_submodule_summary(FILE *f, const char *path,struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ; -if (is_null_sha1 (two)) +if (is_null_oid (two)) message ="(submodule deleted)" ;else if (add_submodule_odb (path)) message ="(not initialized)" ; -else if (is_null_sha1 (one)) +else if (is_null_oid (one)) message ="(new submodule)" ; -else if (!(left =lookup_commit_reference (one)) || - !(right =lookup_commit_reference (two))) +else if (!(left =lookup_commit_reference (one->hash)) || + !(right =lookup_commit_reference (two->hash))) message ="(commits not present)" ;else if (prepare_submodule_summary (&rev, path, left, right, &fast_forward, &fast_backward))
@@ -367,16 +367,16 @@ void show_submodule_summary(FILE *f, const char *path,fprintf (f,"%sSubmodule %s contains modified content\n" , line_prefix, path); -if (!hashcmp (one, two)) { +if (!oidcmp (one, two)) {strbuf_release (&sb);return ; }strbuf_addf (&sb,"%s%sSubmodule %s %s.." , line_prefix, meta, path, -find_unique_abbrev (one,DEFAULT_ABBREV )); +find_unique_abbrev (one->hash,DEFAULT_ABBREV ));if (!fast_backward && !fast_forward)strbuf_addch (&sb,'.' ); -strbuf_addf (&sb,"%s" ,find_unique_abbrev (two,DEFAULT_ABBREV )); +strbuf_addf (&sb,"%s" ,find_unique_abbrev (two->hash,DEFAULT_ABBREV ));if (message)strbuf_addf (&sb," %s%s\n" , message, reset);else
submodule.h +1 -1
@@ -43,7 +43,7 @@ const char *submodule_strategy_to_string(const struct submodule_update_strategyvoid handle_ignore_submodules_arg (struct diff_options *diffopt,const char *);void show_submodule_summary (FILE *f,const char *path,const char *line_prefix, -unsigned char one[20 ],unsigned char two[20 ], +struct object_id *one,struct object_id *two,unsigned dirty_submodule,const char *meta,const char *del,const char *add,const char *reset);void set_config_fetch_recurse_submodules (int value);
Signature · 1 line
2.10.0.rc2.311.g2bd286e
PATCH v12 7/8 submodule: refactor show_submodule_summary with helper function
In reply to Jacob KellerFrom: 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 as most causes of the failure will be due to a missing commit which we already check for and avoid previously. flow. However, this is a rare case and shouldn't impact much.
--- submodule.c | 115 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 33 deletions(-)
submodule.c +82 -33
@@ -280,9 +280,9 @@ 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_list *merge_bases) { -struct commit_list *merge_bases, *list; +struct commit_list *list;init_revisions (rev,NULL );setup_revisions (0 ,NULL , rev,NULL );
@@ -291,13 +291,6 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path, left->object.flags |=SYMMETRIC_LEFT ;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,
@@ -335,31 +328,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,struct object_id *one,struct object_id *two,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 commit_list **merge_bases) { -struct rev_info rev; -struct commit *left =NULL , *right =NULL ;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ; -if (is_null_oid (two)) - message ="(submodule deleted)" ; -else if (add_submodule_odb (path)) - message ="(not initialized)" ; -else if (is_null_oid (one)) - message ="(new submodule)" ; -else if (!(left =lookup_commit_reference (one->hash)) || - !(right =lookup_commit_reference (two->hash))) - 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);
@@ -367,11 +352,46 @@ void show_submodule_summary(FILE *f, const char *path,fprintf (f,"%sSubmodule %s contains modified content\n" , line_prefix, path); +if (is_null_oid (one)) + message ="(new submodule)" ; +else if (is_null_oid (two)) + message ="(submodule deleted)" ; + +if (add_submodule_odb (path)) { +if (!message) + message ="(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->hash); + *right =lookup_commit_reference (two->hash); + +/* +* Warn about missing commits in the submodule project, but only if +* they aren't null. +*/ +if ((!is_null_oid (one) && !*left) || + (!is_null_oid (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 (!oidcmp (one, two)) {strbuf_release (&sb);return ; } +output_header:strbuf_addf (&sb,"%s%sSubmodule %s %s.." , line_prefix, meta, path,find_unique_abbrev (one->hash,DEFAULT_ABBREV ));if (!fast_backward && !fast_forward)
@@ -383,16 +403,45 @@ 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); -if (left) -clear_commit_marks (left, ~0 ); -if (right) -clear_commit_marks (right, ~0 ); -strbuf_release (&sb); } +void show_submodule_summary (FILE *f,const char *path, +const char *line_prefix, +struct object_id *one,struct object_id *two, +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 ; +struct commit_list *merge_bases =NULL ; + +show_submodule_header (f, path, line_prefix, one, two, dirty_submodule, + meta, reset, &left, &right, &merge_bases); + +/* +* If we don't have both a left and a right pointer, there is no +* reason to try and display a summary. The header line should contain +* all the information the user needs. +*/ +if (!left || !right) + goto out; + +/* Treat revision walker failure the same as missing commits */ +if (prepare_submodule_summary (&rev, path, left, right, merge_bases)) { +fprintf (f,"%s(revision walker failed)\n" , line_prefix); + goto out; + } + +print_submodule_summary (&rev, f, line_prefix, del, add, reset); + +out: +if (merge_bases) +free_commit_list (merge_bases); +clear_commit_marks (left, ~0 ); +clear_commit_marks (right, ~0 ); +} +void set_config_fetch_recurse_submodules (int value) { config_fetch_recurse_submodules = value;
Signature · 1 line
2.10.0.rc2.311.g2bd286e
PATCH v12 8/8 diff: teach diff to display submodule difference with an inline diff
In reply to Jacob KellerFrom: 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 | 3 +- submodule.c | 69 +++ submodule.h | 6 + t/t4060-diff-submodule-option-diff-format.sh | 749 +++++++++++++++++++++++++++ 7 files changed, 863 insertions(+), 21 deletions(-) create mode 100755 t/t4060-diff-submodule-option-diff-format.sh
Documentation/diff-config.txt +5 -4
@@ -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
@@ -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
@@ -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, &two->oid, + 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 +2 -1
@@ -111,7 +111,8 @@ enum diff_words_type {enum diff_submodule_format {DIFF_SUBMODULE_SHORT =0 , -DIFF_SUBMODULE_LOG +DIFF_SUBMODULE_LOG , +DIFF_SUBMODULE_INLINE_DIFF };struct diff_options {
submodule.c +69 -0
75 lines not on this page · raw message
submodule.h +6 -0
@@ -46,6 +46,12 @@ void show_submodule_summary(FILE *f, const char *path, struct object_id *one, struct object_id *two, 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, +struct object_id *one,struct object_id *two, +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/t4060-diff-submodule-option-diff-format.sh new file +749 -0
749 lines not on this page · raw message
Signature · 1 line
2.10.0.rc2.311.g2bd286e
Quoted 22 lines · Jacob Keller
From: Jacob Keller <[email protected]>
Hopefully the final revision here. I've squashed in the memory leak fix suggested by Stefan, and the suggested changes from Junio, including his re-worded commit messages.
interdiff between v11 and v12
path.c +1
-1@@ -467,7 +467,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)return pathname->buf; } -/* Returns 0 on success, non-zero on failure. */ +/* Returns 0 on success, negative on failure. */ #define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1static int do_submodule_path (struct strbuf *buf,const char *path,const char *fmt,va_list args)@@ -523,8 +523,10 @@ char *git_pathdup_submodule(const char *path, const char *fmt, ...)va_start (args, fmt);
path.c char *git_pathdup_submodule(const char *path, const char *fmt, ...) · line 532
Quoted 10 lines
path.c +3
-1err =do_submodule_path (&buf, path, fmt, args);va_end (args); -if (err) +if (err) { +strbuf_release (&buf);return NULL ; + }return strbuf_detach (&buf,NULL ); }
Skimmed all patches very quickly and they look good to me.
Thanks,
Stefan
path.c char *git_pathdup_submodule(const char *path, const char *fmt, ...) · line 531
Quoted 11 lines · Jacob Keller
path.c +3
-1@@ -523,8 +523,10 @@ char *git_pathdup_submodule(const char *path, const char *fmt, ...)va_start (args, fmt); err =do_submodule_path (&buf, path, fmt, args);va_end (args); -if (err) +if (err) { +strbuf_release (&buf);return NULL ; + }return strbuf_detach (&buf,NULL ); }
Thanks. My copy was lacking this hunk. Will replace.