Use merge_recursive() directly in the builtin am
PATCH v4 12/16 merge-recursive: flush output buffer before printing error messages
In reply to Johannes SchindelinThe data structure passed to the recursive merge machinery has a feature where the caller can ask for the output to be buffered into a strbuf, by setting the field 'buffer_output'.
Previously, we simply swallowed the buffered output when showing error messages. With this patch, we show the output first, and only then print the error message.
Currently, the only user of that buffering is merge_recursive() itself, to avoid the progress output to interfere.
In the next patches, we will introduce a new buffer_output mode that forces merge_recursive() to retain the output buffer for further processing by the caller. If the caller asked for that, we will then also write the error messages into the output buffer. This is necessary to give the caller more control not only how to react in case of errors but also control how/if to display the error messages.
--- merge-recursive.c | 116 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 48 deletions(-)
merge-recursive.c +68 -48
@@ -23,6 +23,28 @@#include "dir.h" #include "submodule.h" +static void flush_output (struct merge_options *o) +{ +if (o->obuf.len) { +fputs (o->obuf.buf, stdout); +strbuf_reset (&o->obuf); + } +} + +static int err (struct merge_options *o,const char *err, ...) +{ +va_list params; + +va_start (params, err); +flush_output (o); +strbuf_vaddf (&o->obuf, err, params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); +va_end (params); + +return -1 ; +} +static struct tree *shift_tree_object (struct tree *one,struct tree *two,const char *subtree_shift) {
@@ -148,14 +170,6 @@ static int show(struct merge_options *o, int v)return (!o->call_depth && o->verbosity >= v) || o->verbosity >=5 ; } -static void flush_output (struct merge_options *o) -{ -if (o->obuf.len) { -fputs (o->obuf.buf, stdout); -strbuf_reset (&o->obuf); - } -} - __attribute__((format (printf,3 ,4 )))static void output (struct merge_options *o,int v,const char *fmt, ...) {
@@ -198,7 +212,8 @@ static void output_commit_title(struct merge_options *o, struct commit *commit) } } -static int add_cacheinfo (unsigned int mode,const struct object_id *oid, +static int add_cacheinfo (struct merge_options *o, +unsigned int mode,const struct object_id *oid,const char *path,int stage,int refresh,int options) {struct cache_entry *ce;
@@ -206,7 +221,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, (refresh ? (CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING) : 0 ));if (!ce) -return error (_ ("addinfo_cache failed for path '%s'" ), path); +return err (o,_ ("addinfo_cache failed for path '%s'" ), path);return add_cache_entry (ce, options); }
@@ -267,7 +282,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)if (!cache_tree_fully_valid (active_cache_tree) &&cache_tree_update (&the_index,0 ) <0 ) { -error (_ ("error building trees" )); +err (o,_ ("error building trees" ));return NULL ; }
@@ -535,7 +550,8 @@ static struct string_list *get_renames(struct merge_options *o,return renames; } -static int update_stages (const char *path,const struct diff_filespec *o, +static int update_stages (struct merge_options *opt,const char *path, +const struct diff_filespec *o,const struct diff_filespec *a,const struct diff_filespec *b) {
@@ -554,13 +570,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,if (remove_file_from_cache (path))return -1 ;if (o) -if (add_cacheinfo (o->mode, &o->oid, path,1 ,0 , options)) +if (add_cacheinfo (opt, o->mode, &o->oid, path,1 ,0 , options))return -1 ;if (a) -if (add_cacheinfo (a->mode, &a->oid, path,2 ,0 , options)) +if (add_cacheinfo (opt, a->mode, &a->oid, path,2 ,0 , options))return -1 ;if (b) -if (add_cacheinfo (b->mode, &b->oid, path,3 ,0 , options)) +if (add_cacheinfo (opt, b->mode, &b->oid, path,3 ,0 , options))return -1 ;return 0 ; }
@@ -711,8 +727,8 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (status) {if (status ==SCLD_EXISTS )/* something else exists */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); -return error (msg, path,"" ); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,"" ); }/*
@@ -720,7 +736,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)* tracking it. */ if (would_lose_untracked (path)) -return error (_ ("refusing to lose untracked file at '%s'" ), +return err (o,_ ("refusing to lose untracked file at '%s'" ), path);/* Successful unlink is good.. */
@@ -730,7 +746,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (errno ==ENOENT )return 0 ;/* .. but not some other error (who really cares what?) */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); } static int update_file_flags(struct merge_options *o,
@@ -762,9 +778,9 @@ static int update_file_flags(struct merge_options *o, buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); +return err (o,_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path);if (type !=OBJ_BLOB ) { - ret =error (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); + ret =err (o,_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); goto free_buf; }if (S_ISREG (mode)) {
@@ -788,8 +804,8 @@ static int update_file_flags(struct merge_options *o, mode =0666 ; fd =open (path,O_WRONLY |O_TRUNC |O_CREAT , mode);if (fd <0 ) { - ret =error_errno (_ ("failed to open '%s'" ), - path); + ret =err (o,_ ("failed to open '%s': %s" ), + path,strerror (errno)); goto free_buf; }write_in_full (fd, buf, size);
@@ -799,17 +815,19 @@ static int update_file_flags(struct merge_options *o,safe_create_leading_directories_const (path);unlink (path);if (symlink (lnk, path)) - ret =error_errno (_ ("failed to symlink '%s'" ), path); + ret =err (o,_ ("failed to symlink '%s': %s" ), + path,strerror (errno));free (lnk); }else - ret =error (_ ("do not know what to do with %06o %s '%s'" ), - mode,oid_to_hex (oid), path); + ret =err (o, +_ ("do not know what to do with %06o %s '%s'" ), + mode,oid_to_hex (oid), path); free_buf:free (buf); } update_index:if (!ret && update_cache) -add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); +add_cacheinfo (o, mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD );return ret; }
@@ -942,12 +960,12 @@ static int merge_file_1(struct merge_options *o, branch1, branch2);if ((merge_status <0 ) || !result_buf.ptr) - ret =error (_ ("Failed to execute internal merge" )); + ret =err (o,_ ("Failed to execute internal merge" ));if (!ret &&write_sha1_file (result_buf.ptr, result_buf.size, blob_type, result->oid.hash)) - ret =error (_ ("Unable to add %s to database" ), - a->path); + ret =err (o,_ ("Unable to add %s to database" ), + a->path);free (result_buf.ptr);if (ret)
@@ -1113,7 +1131,7 @@ static int conflict_rename_delete(struct merge_options *o,if (o->call_depth)return remove_file_from_cache (dest->path);else -return update_stages (dest->path,NULL , +return update_stages (o, dest->path,NULL , rename_branch == o->branch1 ? dest :NULL , rename_branch == o->branch1 ?NULL : dest); }
@@ -1171,9 +1189,9 @@ static int handle_file(struct merge_options *o,if ((ret =update_file (o,0 , &rename->oid, rename->mode, dst_name))) ;/* fall through, do allow dst_name to be released */ else if (stage ==2 ) - ret =update_stages (rename->path,NULL , rename, add); + ret =update_stages (o, rename->path,NULL , rename, add);else - ret =update_stages (rename->path,NULL , add, rename); + ret =update_stages (o, rename->path,NULL , add, rename);if (dst_name != rename->path)free (dst_name);
@@ -1566,23 +1584,25 @@ static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)return (is_null_oid (oid) || mode ==0 ) ?NULL : (struct object_id *)oid; } -static int read_oid_strbuf (const struct object_id *oid,struct strbuf *dst) +static int read_oid_strbuf (struct merge_options *o, +const struct object_id *oid,struct strbuf *dst) {void *buf;enum object_type type;unsigned long size; buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s" ),oid_to_hex (oid)); +return err (o,_ ("cannot read object %s" ),oid_to_hex (oid));if (type !=OBJ_BLOB ) {free (buf); -return error (_ ("object %s is not a blob" ),oid_to_hex (oid)); +return err (o,_ ("object %s is not a blob" ),oid_to_hex (oid)); }strbuf_attach (dst, buf, size, size +1 );return 0 ; } -static int blob_unchanged(const struct object_id *o_oid, +static int blob_unchanged(struct merge_options *opt, + const struct object_id *o_oid, unsigned o_mode, const struct object_id *a_oid, unsigned a_mode,
@@ -1600,7 +1620,7 @@ static int blob_unchanged(const struct object_id *o_oid,return 0 ;assert (o_oid && a_oid); -if (read_oid_strbuf (o_oid, &o) ||read_oid_strbuf (a_oid, &a)) +if (read_oid_strbuf (opt, o_oid, &o) ||read_oid_strbuf (opt, a_oid, &a)) goto error_return;/* * Note: binary | is used so that both renormalizations are
@@ -1689,7 +1709,7 @@ static int merge_content(struct merge_options *o,*/ path_renamed_outside_HEAD = !path2 || !strcmp (path, path2);if (!path_renamed_outside_HEAD) { -add_cacheinfo (mfi.mode, &mfi.oid, path, +add_cacheinfo (o, mfi.mode, &mfi.oid, path,0 , (!o->call_depth),0 );return mfi.clean; }
@@ -1702,7 +1722,7 @@ static int merge_content(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): Merge conflict in %s" ), reason, path);if (rename_conflict_info && !df_conflict_remains) -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }
@@ -1712,7 +1732,7 @@ static int merge_content(struct merge_options *o,remove_file_from_cache (path); }else {if (!mfi.clean) { -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }else {int file_from_stage2 =was_tracked (path);
@@ -1720,7 +1740,7 @@ static int merge_content(struct merge_options *o,oidcpy (&merged.oid, &mfi.oid); merged.mode = mfi.mode; -if (update_stages (path,NULL , +if (update_stages (o, path,NULL , file_from_stage2 ? &merged :NULL , file_from_stage2 ?NULL : &merged))return -1 ;
@@ -1788,8 +1808,8 @@ static int process_entry(struct merge_options *o, }else if (o_oid && (!a_oid || !b_oid)) {/* Case A: Deleted in one */ if ((!a_oid && !b_oid) || - (!b_oid &&blob_unchanged (o_oid, o_mode, a_oid, a_mode, normalize, path)) || - (!a_oid &&blob_unchanged (o_oid, o_mode, b_oid, b_mode, normalize, path))) { + (!b_oid &&blob_unchanged (o, o_oid, o_mode, a_oid, a_mode, normalize, path)) || + (!a_oid &&blob_unchanged (o, o_oid, o_mode, b_oid, b_mode, normalize, path))) {/* Deleted in both or deleted in one and * unchanged in the other */ if (a_oid)
@@ -1885,7 +1905,7 @@ int merge_trees(struct merge_options *o,if (code !=0 ) {if (show (o,4 ) || o->call_depth) -error (_ ("merging of trees %s and %s failed" ), +err (o,_ ("merging of trees %s and %s failed" ),oid_to_hex (&head->object.oid),oid_to_hex (&merge->object.oid));return -1 ;
@@ -2019,7 +2039,7 @@ int merge_recursive(struct merge_options *o, o->call_depth--;if (!merged_common_ancestors) -return error (_ ("merge returned no commit" )); +return err (o,_ ("merge returned no commit" )); }discard_cache ();
@@ -2078,7 +2098,7 @@ int merge_recursive_generic(struct merge_options *o,for (i =0 ; i < num_base_list; ++i) {struct commit *base;if (!(base =get_ref (base_list[i],oid_to_hex (base_list[i])))) -return error (_ ("Could not parse object '%s'" ), +return err (o,_ ("Could not parse object '%s'" ),oid_to_hex (base_list[i]));commit_list_insert (base, &ca); }
@@ -2092,7 +2112,7 @@ int merge_recursive_generic(struct merge_options *o,if (active_cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK )) -return error (_ ("Unable to write index." )); +return err (o,_ ("Unable to write index." ));return clean ?0 :1 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v4 13/16 merge-recursive: write the commit title in one go
In reply to Johannes SchindelinIn 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we changed the code such that it prints the output in one go, to avoid interfering with the progress output.
Let's make sure that the same holds true when outputting the commit
title: previously, we used several printf() statements to stdout and speculated that stdout's buffer is large enough to hold the entire commit title.
Apart from making that speculation unnecessary, we change the code to add the message to the output buffer before flushing for another reason:
the next commit will introduce a new level of output buffering, where the caller can request the output not to be flushed, but to be retained for further processing.
This latter feature will be needed when teaching the sequencer to do rebase -i's brunt work: it wants to control the output of the cherry-picks (i.e. recursive merges).
--- merge-recursive.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
merge-recursive.c +9 -8
@@ -191,25 +191,26 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)static void output_commit_title (struct merge_options *o,struct commit *commit) { -int i; -flush_output (o); -for (i = o->call_depth; i--;) -fputs (" " , stdout); +strbuf_addchars (&o->obuf,' ' , o->call_depth *2 );if (commit->util) -printf ("virtual %s\n" ,merge_remote_util (commit)->name); +strbuf_addf (&o->obuf,"virtual %s\n" , +merge_remote_util (commit)->name);else { -printf ("%s " ,find_unique_abbrev (commit->object.oid.hash,DEFAULT_ABBREV )); +strbuf_addf (&o->obuf,"%s " , +find_unique_abbrev (commit->object.oid.hash, +DEFAULT_ABBREV ));if (parse_commit (commit) !=0 ) -printf (_ ("(bad commit)\n" )); +strbuf_addf (&o->obuf,_ ("(bad commit)\n" ));else {const char *title;const char *msg =get_commit_buffer (commit,NULL );int len =find_commit_subject (msg, &title);if (len) -printf ("%.*s\n" , len, title); +strbuf_addf (&o->obuf,"%.*s\n" , len, title);unuse_commit_buffer (commit, msg); } } +flush_output (o); } static int add_cacheinfo(struct merge_options *o,
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v4 14/16 merge-recursive: offer an option to retain the output in 'obuf'
In reply to Johannes SchindelinSince 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we already accumulate the output in a buffer. The idea was to avoid interfering with the progress output that goes to stderr, which is unbuffered, when we write to stdout, which is buffered.
We extend that buffering to allow the caller to handle the output (possibly suppressing it). This will help us when extending the sequencer to do rebase -i's brunt work: it does not want the picks to print anything by default but instead determine itself whether to print the output or not.
Note that we also redirect the error messages into the output buffer when the caller asked not to flush the output buffer, for two reasons:
1) to retain the correct output order, and 2) to allow the caller to suppress *all* output.
--- merge-recursive.c | 17 +++++++++++++---- merge-recursive.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
merge-recursive.c +13 -4
@@ -25,7 +25,7 @@static void flush_output (struct merge_options *o) { -if (o->obuf.len) { +if (o->buffer_output <2 && o->obuf.len) {fputs (o->obuf.buf, stdout);strbuf_reset (&o->obuf); }
@@ -36,10 +36,19 @@ static int err(struct merge_options *o, const char *err, ...)va_list params;va_start (params, err); -flush_output (o); +if (o->buffer_output <2 ) +flush_output (o); +else { +strbuf_complete (&o->obuf,'\n' ); +strbuf_addstr (&o->obuf,"error: " ); + }strbuf_vaddf (&o->obuf, err, params); -error ("%s" , o->obuf.buf); -strbuf_reset (&o->obuf); +if (o->buffer_output >1 ) +strbuf_addch (&o->obuf,'\n' ); +else { +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); + }va_end (params);return -1 ;
merge-recursive.h +1 -1
@@ -13,7 +13,7 @@ struct merge_options {MERGE_RECURSIVE_THEIRS } recursive_variant;const char *subtree_shift; - unsigned buffer_output : 1; + unsigned buffer_output : 2; /* 1: output at end, 2: keep buffered */ unsigned renormalize : 1;long xdl_opts;int verbosity;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v4 15/16 Ensure that the output buffer is released after calling merge_trees()
In reply to Johannes SchindelinThe recursive merge machinery accumulates its output in an output buffer, to be flushed at the end of merge_recursive(). At this point, we forgot to release the output buffer.
When calling merge_trees() (i.e. the non-recursive part of the recursive merge) directly, the output buffer is never flushed because the caller may be merge_recursive() which wants to flush the output itself.
For the same reason, merge_trees() cannot release the output buffer: it may still be needed.
Forgetting to release the output buffer did not matter much when running git-checkout, or git-merge-recursive, because we exited after the operation anyway. Ever since cherry-pick learned to pick a commit range, however, this memory leak had the potential of becoming a problem.
--- builtin/checkout.c | 1 + merge-recursive.c | 2 ++ sequencer.c | 1 + 3 files changed, 4 insertions(+)
builtin/checkout.c +1 -0
@@ -573,6 +573,7 @@ static int merge_working_tree(const struct checkout_opts *opts,exit (128 ); ret =reset_tree (new->commit->tree, opts,0 , writeout_error); +strbuf_release (&o.obuf);if (ret)return ret; }
merge-recursive.c +2 -0
@@ -2068,6 +2068,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (o->buffer_output <2 ) +strbuf_release (&o->obuf);if (show (o,2 ))diff_warn_rename_limit ("merge.renamelimit" , o->needed_rename_limit,0 );
sequencer.c +1 -0
@@ -293,6 +293,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean =merge_trees (&o, head_tree, next_tree, base_tree, &result); +strbuf_release (&o.obuf);if (clean <0 )return clean;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v4 16/16 merge-recursive: flush output buffer even when erroring out
In reply to Johannes SchindelinEver since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we had a problem: When the merge failed in a fatal way, all regular output was swallowed because we called die() and did not get a chance to drain the output buffers.
To fix this, several modifications were necessary:
- we needed to stop die()ing, to give callers a chance to do something when an error occurred (in this case, flush the output buffers),
- we needed to delay printing the error message so that the caller can print the buffered output before that, and
- we needed to make sure that the output buffers are flushed even when the return value indicates an error.
The first two changes were introduced through earlier commits in this patch series, and this commit addresses the third one.
--- merge-recursive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-recursive.c +1 -1
@@ -2059,6 +2059,7 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +flush_output (o);if (clean <0 )return clean;
@@ -2067,7 +2068,6 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h1, &(*result)->parents);commit_list_insert (h2, &(*result)->parents->next); } -flush_output (o);if (o->buffer_output <2 )strbuf_release (&o->obuf);if (show (o,2 ))
Signature · 1 line
2.9.0.281.g286a8d9
v5 cover Use merge_recursive() directly in the builtin am
In reply to Johannes SchindelinThis is the fifth iteration of the long-awaited re-roll of the attempt to avoid spawning merge-recursive from the builtin am and use merge_recursive() directly instead.
The *real* reason for the reroll is that I need a libified recursive merge to accelerate the interactive rebase by teaching the sequencer to do rebase -i's grunt work. Coming with a very nice 3x-5x speedup of rebase -i.
In this endeavor, we need to be extra careful to retain backwards compatibility. The test script t6022-merge-rename.sh, for example, verifies that git pull exits with status 128 in case of a fatal error. To that end, we need to make sure that fatal errors are handled by existing (builtin) users via exit(128) (or die(), which calls exit(128) at the end). New users (such as a builtin helper doing rebase -i's grunt work) may want to print some helpful advice what happened and how to get out of this mess before erroring out.
The changes relative to the fourth iteration of this patch series:
- the first patch which introduces a tests case to t5520 was prettified:
- it uses test_seq now,
- it avoids printf when echo does the job, too,
- it adds a missing empty line between test cases, and
- it clarifies why we need to check out with force.
- the change that would have made the bug report about a too-small buffer in imap-send was reverted, because it did more than was claimed by the commit message.
- the "Let's teach them manners" part of one commit message was replaced with a less flippant description.
- the comment before merge_recursive() that claims that the return value is ignored now clarifies that it is ignored unless it indicates an error.
- during the rebase to master, a trivial merge conflict with the jc/renormalize-merge-kill-safer-crlf branch was resolved.
This patch series touches rather important code. Now that I addressed concerns such as prettifying some test code, I would appreciate thorough reviews with a focus on the critical parts of the code, those that could result in regressions.
Johannes Schindelin (16):
t5520: verify that pull --rebase shows the helpful advice when
failing
Report bugs consistently
Avoid translating bug messages
merge-recursive: clarify code in was_tracked()
Prepare the builtins for a libified merge_recursive()
merge_recursive: abort properly upon errors
merge-recursive: avoid returning a wholesale struct
merge-recursive: allow write_tree_from_memory() to error out
merge-recursive: handle return values indicating errors
merge-recursive: switch to returning errors instead of dying am -3: use merge_recursive() directly again
merge-recursive: flush output buffer before printing error messages
merge-recursive: write the commit title in one go
merge-recursive: offer an option to retain the output in 'obuf' Ensure that the output buffer is released after calling merge_trees()
merge-recursive: flush output buffer even when erroring out
builtin/am.c | 62 ++---- builtin/checkout.c | 5 +- builtin/ls-files.c | 3 +- builtin/merge.c | 2 + builtin/update-index.c | 2 +- grep.c | 8 +- imap-send.c | 2 +- merge-recursive.c | 578 +++++++++++++++++++++++++++++-------------------- merge-recursive.h | 2 +- sequencer.c | 5 + sha1_file.c | 4 +- t/t5520-pull.sh | 32 +++ trailer.c | 2 +- transport.c | 2 +- wt-status.c | 4 +- 15 files changed, 418 insertions(+), 295 deletions(-)
Published-As: https://github.com/dscho/git/releases/tag/am-3-merge-recursive-direct-v5
Interdiff vs v4:
diff --git a/imap-send.c b/imap-send.c
index 67d67f8..0f5f476 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -506,12 +506,12 @@ static char *next_arg(char **s)
static int nfsnprintf(char *buf, int blen, const char *fmt, ...) {
- int ret = -1;
+ int ret;
va_list va;
va_start(va, fmt);
if (blen <= 0 || (unsigned)(ret = vsnprintf(buf, blen, fmt, va)) >= (unsigned)blen)
- die("BUG: buffer too small (%d < %d)", ret, blen);
+ die("BUG: buffer too small. Please report a bug.");
va_end(va);
return ret;
}
diff --git a/merge-recursive.c b/merge-recursive.c
index a3d12e6..66e93e0 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2041,9 +2041,10 @@ int merge_recursive(struct merge_options *o,
/*
* When the merge fails, the result contains files
* with conflict markers. The cleanness flag is
- * ignored, it was never actually used, as result of
- * merge_trees has always overwritten it: the committed
- * "conflicts" were already resolved.
+ * ignored (unless indicating an error), it was never
+ * actually used, as result of merge_trees has always
+ * overwritten it: the committed "conflicts" were
+ * already resolved.
*/
discard_cache();
saved_b1 = o->branch1;
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index d289056..6ad37b5 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -258,20 +258,21 @@ test_expect_success '--rebase' '
test_expect_success '--rebase with conflicts shows advice' '
test_when_finished "git rebase --abort; git checkout -f to-rebase" && git checkout -b seq &&
- printf "1\\n2\\n3\\n4\\n5\\n" >seq.txt &&
+ test_seq 5 >seq.txt &&
git add seq.txt &&
test_tick &&
git commit -m "Add seq.txt" &&
- printf "6\\n" >>seq.txt &&
+ echo 6 >>seq.txt &&
test_tick &&
git commit -m "Append to seq.txt" seq.txt &&
git checkout -b with-conflicts HEAD^ &&
- printf "conflicting\\n" >>seq.txt &&
+ echo conflicting >>seq.txt &&
test_tick &&
git commit -m "Create conflict" seq.txt &&
test_must_fail git pull --rebase . seq 2>err >out &&
grep "When you have resolved this problem" out
'
+
test_expect_success 'failed --rebase shows advice' '
test_when_finished "git rebase --abort; git checkout -f to-rebase" && git checkout -b diverging &&
@@ -279,6 +280,7 @@ test_expect_success 'failed --rebase shows advice' '
sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
git update-index --cacheinfo 0644 $sha1 file &&
git commit -m v1-with-cr &&
+ # force checkout because git reset --hard will not leave clean file
git checkout -f -b fails-to-rebase HEAD^ &&
test_commit v2-without-cr file "2" file2-lf &&
test_must_fail git pull --rebase . diverging 2>err >out &&
Signature · 3 lines
2.9.0.281.g286a8d9 base-commit: 8c6d1f9807c67532e7fb545a944b064faff0f70b
PATCH v5 1/16 t5520: verify that `pull --rebase` shows the helpful advice when failing
It was noticed by Brendan Forster last October that the builtin git am regressed on that. Our hot fix reverted to spawning the recursive merge instead of using it as a library function.
As we are about to revert that hot fix, after making the recursive merge a true library function (i.e. a function that does not die() in case of "normal" errors), let's add a test that verifies that we do not regress on the same problem which made the hot fix necessary in the first place.
--- t/t5520-pull.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
t/t5520-pull.sh +32 -0
@@ -255,6 +255,38 @@ test_expect_success '--rebase' ' test new = "$(git show HEAD:file2)" ' +test_expect_success '--rebase with conflicts shows advice' ' + test_when_finished "git rebase --abort; git checkout -f to-rebase" && + git checkout -b seq && + test_seq 5 >seq.txt && + git add seq.txt && + test_tick && + git commit -m "Add seq.txt" && + echo 6 >>seq.txt && + test_tick && + git commit -m "Append to seq.txt" seq.txt && + git checkout -b with-conflicts HEAD^ && + echo conflicting >>seq.txt && + test_tick && + git commit -m "Create conflict" seq.txt && + test_must_fail git pull --rebase . seq 2>err >out && + grep "When you have resolved this problem" out +' + +test_expect_success 'failed --rebase shows advice' ' + test_when_finished "git rebase --abort; git checkout -f to-rebase" && + git checkout -b diverging && + test_commit attributes .gitattributes "* text=auto" attrs && + sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" && + git update-index --cacheinfo 0644 $sha1 file && + git commit -m v1-with-cr && + # force checkout because `git reset --hard` will not leave clean `file` + git checkout -f -b fails-to-rebase HEAD^ && + test_commit v2-without-cr file "2" file2-lf && + test_must_fail git pull --rebase . diverging 2>err >out && + grep "When you have resolved this problem" out +' + test_expect_success '--rebase fails with multiple branches' ' git reset --hard before-rebase && test_must_fail git pull --rebase . copy master 2>err &&
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 2/16 Report bugs consistently
In reply to Johannes SchindelinThe vast majority of error messages in Git's source code which report a bug use the convention to prefix the message with "BUG:".
As part of cleaning up merge-recursive to stop die()ing except in case of detected bugs, let's just make the remainder of the bug reports consistent with the de facto rule.
--- builtin/ls-files.c | 3 ++- builtin/update-index.c | 2 +- grep.c | 8 ++++---- imap-send.c | 2 +- merge-recursive.c | 15 +++++++-------- sha1_file.c | 4 ++-- trailer.c | 2 +- transport.c | 2 +- wt-status.c | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-)
builtin/ls-files.c +2 -1
@@ -118,7 +118,8 @@ static void show_killed_files(struct dir_struct *dir)*/ pos =cache_name_pos (ent->name, ent->len);if (0 <= pos) -die ("bug in show-killed-files" ); +die ("BUG: killed-file %.*s not found" , + ent->len, ent->name); pos = -pos -1 ;while (pos < active_nr &&ce_stage (active_cache[pos]))
builtin/update-index.c +1 -1
@@ -1146,7 +1146,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)report (_ ("Untracked cache enabled for '%s'" ),get_git_work_tree ());break ;default : -die ("Bug: bad untracked_cache value: %d" , untracked_cache); +die ("BUG: bad untracked_cache value: %d" , untracked_cache); }if (active_cache_changed) {
grep.c +4 -4
@@ -693,10 +693,10 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)for (p = opt->header_list; p; p = p->next) {if (p->token !=GREP_PATTERN_HEAD ) -die ("bug: a non-header pattern in grep header list." ); +die ("BUG: a non-header pattern in grep header list." );if (p->field <GREP_HEADER_FIELD_MIN ||GREP_HEADER_FIELD_MAX <= p->field) -die ("bug: unknown header field %d" , p->field); +die ("BUG: unknown header field %d" , p->field);compile_regexp (p, opt); }
@@ -709,7 +709,7 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt) h =compile_pattern_atom (&pp);if (!h || pp != p->next) -die ("bug: malformed header expr" ); +die ("BUG: malformed header expr" );if (!header_group[p->field]) { header_group[p->field] = h;continue ;
@@ -1514,7 +1514,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int collecase GREP_BINARY_TEXT :break ;default : -die ("bug: unknown binary handling mode" ); +die ("BUG: unknown binary handling mode" ); } }
imap-send.c +1 -1
@@ -511,7 +511,7 @@ static int nfsnprintf(char *buf, int blen, const char *fmt, ...)va_start (va, fmt);if (blen <=0 || (unsigned )(ret =vsnprintf (buf, blen, fmt, va)) >= (unsigned )blen) -die ("Fatal: buffer too small. Please report a bug." ); +die ("BUG: buffer too small. Please report a bug." );va_end (va);return ret; }
merge-recursive.c +7 -8
@@ -268,7 +268,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)fprintf (stderr,"BUG: %d %.*s\n" ,ce_stage (ce), (int )ce_namelen (ce), ce->name); } -die ("Bug in merge-recursive.c" ); +die ("BUG: unmerged index entries in merge-recursive.c" ); }if (!active_cache_tree)
@@ -966,9 +966,8 @@ static struct merge_file_info merge_file_1(struct merge_options *o,if (!oid_eq (&a->oid, &b->oid)) result.clean =0 ; - }else { -die (_ ("unsupported object type in the tree" )); - } + }else +die (_ ("BUG: unsupported object type in the tree" )); }return result;
@@ -1354,7 +1353,7 @@ static int process_renames(struct merge_options *o,const char *ren2_dst = ren2->pair->two->path;enum rename_type rename_type;if (strcmp (ren1_src, ren2_src) !=0 ) -die ("ren1_src != ren2_src" ); +die ("BUG: ren1_src != ren2_src" ); ren2->dst_entry->processed =1 ; ren2->processed =1 ;if (strcmp (ren1_dst, ren2_dst) !=0 ) {
@@ -1388,7 +1387,7 @@ static int process_renames(struct merge_options *o, ren2 = lookup->util; ren2_dst = ren2->pair->two->path;if (strcmp (ren1_dst, ren2_dst) !=0 ) -die ("ren1_dst != ren2_dst" ); +die ("BUG: ren1_dst != ren2_dst" ); clean_merge =0 ; ren2->processed =1 ;
@@ -1812,7 +1811,7 @@ static int process_entry(struct merge_options *o,*/ remove_file (o,1 , path, !a_mode); }else -die (_ ("Fatal merge failure, shouldn't happen." )); +die (_ ("BUG: fatal merge failure, shouldn't happen." ));return clean_merge; }
@@ -1870,7 +1869,7 @@ int merge_trees(struct merge_options *o,for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;if (!e->processed) -die (_ ("Unprocessed path??? %s" ), +die (_ ("BUG: unprocessed path??? %s" ), entries->items[i].string); }
sha1_file.c +2 -2
@@ -795,7 +795,7 @@ void close_all_packs(void)for (p = packed_git; p; p = p->next)if (p->do_not_close) -die ("BUG! Want to close pack marked 'do-not-close'" ); +die ("BUG: want to close pack marked 'do-not-close'" );else close_pack (p); }
@@ -2330,7 +2330,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,case OBJ_OFS_DELTA :case OBJ_REF_DELTA :if (data) -die ("BUG in unpack_entry: left loop at a valid delta" ); +die ("BUG: unpack_entry: left loop at a valid delta" );break ;case OBJ_COMMIT :case OBJ_TREE :
trailer.c +1 -1
@@ -562,7 +562,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)warning (_ ("unknown value '%s' for key '%s'" ), value, conf_key);break ;default : -die ("internal bug in trailer.c" ); +die ("BUG: trailer.c: unhandled type %d" , type); }return 0 ; }
transport.c +1 -1
@@ -566,7 +566,7 @@ void transport_take_over(struct transport *transport,struct git_transport_data *data;if (!transport->smart_options) -die ("Bug detected: Taking over transport requires non-NULL " +die ("BUG: taking over transport requires non-NULL " "smart_options field." ); data =xcalloc (1 ,sizeof (*data));
wt-status.c +2 -2
@@ -263,7 +263,7 @@ static const char *wt_status_unmerged_status_string(int stagemask)case 7 :return _ ("both modified:" );default : -die ("bug: unhandled unmerged status %x" , stagemask); +die ("BUG: unhandled unmerged status %x" , stagemask); } }
@@ -388,7 +388,7 @@ static void wt_status_print_change_data(struct wt_status *s,status_printf (s,color (WT_STATUS_HEADER , s),"\t" ); what =wt_status_diff_status_string (status);if (!what) -die ("bug: unhandled diff status %c" , status); +die ("BUG: unhandled diff status %c" , status); len = label_width -utf8_strwidth (what);assert (len >=0 );if (status ==DIFF_STATUS_COPIED || status ==DIFF_STATUS_RENAMED )
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 3/16 Avoid translating bug messages
In reply to Johannes SchindelinWhile working on the patch series that avoids die()ing in recursive merges, the issue came up that bug reports (i.e. die("BUG: ...") constructs) should never be translated, as the target audience is the Git developer community, not necessarily the current user, and hence a translated message would make it *harder* to address the problem.
So let's stop translating the obvious ones. As it is really, really outside the purview of this patch series to see whether there are more die() statements that report bugs and are currently translated, that task is left for another day and patch.
--- merge-recursive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
merge-recursive.c +3 -3
@@ -967,7 +967,7 @@ static struct merge_file_info merge_file_1(struct merge_options *o,if (!oid_eq (&a->oid, &b->oid)) result.clean =0 ; }else -die (_ ("BUG: unsupported object type in the tree" )); +die ("BUG: unsupported object type in the tree" ); }return result;
@@ -1811,7 +1811,7 @@ static int process_entry(struct merge_options *o,*/ remove_file (o,1 , path, !a_mode); }else -die (_ ("BUG: fatal merge failure, shouldn't happen." )); +die ("BUG: fatal merge failure, shouldn't happen." );return clean_merge; }
@@ -1869,7 +1869,7 @@ int merge_trees(struct merge_options *o,for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;if (!e->processed) -die (_ ("BUG: unprocessed path??? %s" ), +die ("BUG: unprocessed path??? %s" , entries->items[i].string); }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 4/16 merge-recursive: clarify code in was_tracked()
In reply to Johannes SchindelinIt can be puzzling to see that was_tracked() asks to get an index entry by name, but does not take a negative return value for an answer.
The reason we have to do this is that cache_name_pos() only looks for entries in stage 0, even if nobody asked for any stage in particular.
Let's rewrite the logic a little bit, to handle the easy case early: if cache_name_pos() returned a non-negative position, we know it is a match, and we do not even have to compare the name again (cache_name_pos() did that for us already). We can say right away: yes, this file was tracked.
Only if there was no exact match do we need to look harder for any matching entry in stage 2.
--- merge-recursive.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
merge-recursive.c +14 -16
@@ -667,23 +667,21 @@ static int was_tracked(const char *path) {int pos =cache_name_pos (path,strlen (path)); -if (pos <0 ) - pos =-1 - pos; -while (pos < active_nr && - !strcmp (path, active_cache[pos]->name)) { -/* -* If stage #0, it is definitely tracked. -* If it has stage #2 then it was tracked -* before this merge started. All other -* cases the path was not tracked. -*/ -switch (ce_stage (active_cache[pos])) { -case 0 : -case 2 : +if (0 <= pos) +/* we have been tracking this path */ +return 1 ; + +/* +* Look for an unmerged entry for the path, +* specifically stage #2, which would indicate +* that "our" side before the merge started +* had the path tracked (and resulted in a conflict). +*/ +for (pos =-1 - pos; + pos < active_nr && !strcmp (path, active_cache[pos]->name); + pos++) +if (ce_stage (active_cache[pos]) ==2 )return 1 ; - } - pos++; - }return 0 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 5/16 Prepare the builtins for a libified merge_recursive()
In reply to Johannes SchindelinPreviously, callers of merge_trees() or merge_recursive() expected that code to die() with an error message. This used to be okay because we called those commands from scripts, and had a chance to print out a message in case the command failed fatally (read: with exit code 128).
As scripting incurs its own set of problems (portability, speed, idiosynchracies of different shells, limited data structures leading to inefficient code), we are converting more and more of these scripts into builtins, using library functions directly.
We already tried to use merge_recursive() directly in the builtin git-am, for example. Unfortunately, we had to roll it back temporarily because some of the code in merge-recursive.c still deemed it okay to call die(), when the builtin am code really wanted to print out a useful advice after the merge failed fatally. In the next commits, we want to fix that.
The code touched by this commit expected merge_trees() to die() with some useful message when there is an error condition, but merge_trees() is going to be improved by converting all die() calls to return error() instead (i.e. return value -1 after printing out the message as before), so that the caller can react more flexibly.
This is a step to prepare for the version of merge_trees() that no longer dies, even if we just imitate the previous behavior by calling exit(128): this is what callers of e.g. git merge have come to expect.
Note that the callers of the sequencer (revert and cherry-pick) already fail fast even for the return value -1; The only difference is that they now get a chance to say "<command> failed".
A caller of merge_trees() might want handle error messages themselves (or even suppress them). As this patch is already complex enough, we leave that change for a later patch.
--- builtin/checkout.c | 4 +++- builtin/merge.c | 2 ++ sequencer.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
builtin/checkout.c +3 -1
@@ -567,8 +567,10 @@ static int merge_working_tree(const struct checkout_opts *opts, o.ancestor = old->name; o.branch1 = new->name; o.branch2 ="local" ; -merge_trees (&o, new->commit->tree, work, + ret =merge_trees (&o, new->commit->tree, work, old->commit->tree, &result); +if (ret <0 ) +exit (128 ); ret =reset_tree (new->commit->tree, opts,0 , writeout_error);if (ret)
builtin/merge.c +2 -0
@@ -673,6 +673,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,hold_locked_index (&lock,1 ); clean =merge_recursive (&o, head, remoteheads->item, reversed, &result); +if (clean <0 ) +exit (128 );if (active_cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))die (_ ("unable to write %s" ),get_index_file ());
sequencer.c +4 -0
@@ -293,6 +293,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean =merge_trees (&o, head_tree, next_tree, base_tree, &result); +if (clean <0 ) +return clean;if (active_cache_changed &&write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))
@@ -559,6 +561,8 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)if (!opts->strategy || !strcmp (opts->strategy,"recursive" ) || opts->action ==REPLAY_REVERT ) { res =do_recursive_merge (base, next, base_label, next_label, head, &msgbuf, opts); +if (res <0 ) +return res;write_message (&msgbuf,git_path_merge_msg ()); }else {struct commit_list *common =NULL ;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 6/16 merge_recursive: abort properly upon errors
In reply to Johannes SchindelinThere are a couple of places where return values never indicated errors before, as wie simply died instead of returning.
But now negative return values mean that there was an error and we have to abort the operation. Let's do exactly that.
--- merge-recursive.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
merge-recursive.c +12 -5
@@ -1949,17 +1949,19 @@ int merge_recursive(struct merge_options *o,/* * When the merge fails, the result contains files * with conflict markers. The cleanness flag is -* ignored, it was never actually used, as result of -* merge_trees has always overwritten it: the committed -* "conflicts" were already resolved. +* ignored (unless indicating an error), it was never +* actually used, as result of merge_trees has always +* overwritten it: the committed "conflicts" were +* already resolved. */ discard_cache (); saved_b1 = o->branch1; saved_b2 = o->branch2; o->branch1 ="Temporary merge branch 1" ; o->branch2 ="Temporary merge branch 2" ; -merge_recursive (o, merged_common_ancestors, iter->item, -NULL , &merged_common_ancestors); +if (merge_recursive (o, merged_common_ancestors, iter->item, +NULL , &merged_common_ancestors) <0 ) +return -1 ; o->branch1 = saved_b1; o->branch2 = saved_b2; o->call_depth--;
@@ -1975,6 +1977,8 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +if (clean <0 ) +return clean;if (o->call_depth) { *result =make_virtual_commit (mrtree,"merged tree" );
@@ -2031,6 +2035,9 @@ int merge_recursive_generic(struct merge_options *o,hold_locked_index (lock,1 ); clean =merge_recursive (o, head_commit, next_commit, ca, result); +if (clean <0 ) +return clean; +if (active_cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 7/16 merge-recursive: avoid returning a wholesale struct
In reply to Johannes SchindelinIt is technically allowed, as per C89, for functions' return type to be complete structs (i.e. *not* just pointers to structs).
However, it was just an oversight of this developer when converting Python code to C code in 6d297f8 (Status update on merge-recursive in C, 2006-07-08) which introduced such a return type.
Besides, by converting this construct to pass in the struct, we can now start returning a value that can indicate errors in future patches. This will help the current effort to libify merge-recursive.c.
--- merge-recursive.c | 106 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 50 deletions(-)
merge-recursive.c +56 -50
@@ -894,47 +894,47 @@ static int merge_3way(struct merge_options *o,return merge_status; } -static struct merge_file_info merge_file_1 (struct merge_options *o, +static int merge_file_1 (struct merge_options *o,const struct diff_filespec *one,const struct diff_filespec *a,const struct diff_filespec *b,const char *branch1, -const char *branch2) +const char *branch2, +struct merge_file_info *result) { -struct merge_file_info result; - result.merge =0 ; - result.clean =1 ; + result->merge =0 ; + result->clean =1 ;if ((S_IFMT & a->mode) != (S_IFMT & b->mode)) { - result.clean =0 ; + result->clean =0 ;if (S_ISREG (a->mode)) { - result.mode = a->mode; -oidcpy (&result.oid, &a->oid); + result->mode = a->mode; +oidcpy (&result->oid, &a->oid); }else { - result.mode = b->mode; -oidcpy (&result.oid, &b->oid); + result->mode = b->mode; +oidcpy (&result->oid, &b->oid); } }else {if (!oid_eq (&a->oid, &one->oid) && !oid_eq (&b->oid, &one->oid)) - result.merge =1 ; + result->merge =1 ;/* * Merge modes */ if (a->mode == b->mode || a->mode == one->mode) - result.mode = b->mode; + result->mode = b->mode;else { - result.mode = a->mode; + result->mode = a->mode;if (b->mode != one->mode) { - result.clean =0 ; - result.merge =1 ; + result->clean =0 ; + result->merge =1 ; } }if (oid_eq (&a->oid, &b->oid) ||oid_eq (&a->oid, &one->oid)) -oidcpy (&result.oid, &b->oid); +oidcpy (&result->oid, &b->oid);else if (oid_eq (&b->oid, &one->oid)) -oidcpy (&result.oid, &a->oid); +oidcpy (&result->oid, &a->oid);else if (S_ISREG (a->mode)) {mmbuffer_t result_buf;int merge_status;
@@ -946,64 +946,66 @@ static struct merge_file_info merge_file_1(struct merge_options *o,die (_ ("Failed to execute internal merge" ));if (write_sha1_file (result_buf.ptr, result_buf.size, - blob_type, result.oid.hash)) + blob_type, result->oid.hash))die (_ ("Unable to add %s to database" ), a->path);free (result_buf.ptr); - result.clean = (merge_status ==0 ); + result->clean = (merge_status ==0 ); }else if (S_ISGITLINK (a->mode)) { - result.clean =merge_submodule (result.oid.hash, + result->clean =merge_submodule (result->oid.hash, one->path, one->oid.hash, a->oid.hash, b->oid.hash, !o->call_depth); }else if (S_ISLNK (a->mode)) { -oidcpy (&result.oid, &a->oid); +oidcpy (&result->oid, &a->oid);if (!oid_eq (&a->oid, &b->oid)) - result.clean =0 ; + result->clean =0 ; }else die ("BUG: unsupported object type in the tree" ); } -return result; +return 0 ; } -static struct merge_file_info -merge_file_special_markers (struct merge_options *o, +static int merge_file_special_markers (struct merge_options *o,const struct diff_filespec *one,const struct diff_filespec *a,const struct diff_filespec *b,const char *branch1,const char *filename1,const char *branch2, -const char *filename2) +const char *filename2, +struct merge_file_info *mfi) {char *side1 =NULL ;char *side2 =NULL ; -struct merge_file_info mfi; +int ret;if (filename1) side1 =xstrfmt ("%s:%s" , branch1, filename1);if (filename2) side2 =xstrfmt ("%s:%s" , branch2, filename2); - mfi =merge_file_1 (o, one, a, b, - side1 ? side1 : branch1, side2 ? side2 : branch2); + ret =merge_file_1 (o, one, a, b, + side1 ? side1 : branch1, + side2 ? side2 : branch2, mfi);free (side1);free (side2); -return mfi; +return ret; } -static struct merge_file_info merge_file_one (struct merge_options *o, +static int merge_file_one (struct merge_options *o,const char *path,const struct object_id *o_oid,int o_mode,const struct object_id *a_oid,int a_mode,const struct object_id *b_oid,int b_mode,const char *branch1, -const char *branch2) +const char *branch2, +struct merge_file_info *mfi) {struct diff_filespec one, a, b;
@@ -1014,7 +1016,7 @@ static struct merge_file_info merge_file_one(struct merge_options *o, a.mode = a_mode;oidcpy (&b.oid, b_oid); b.mode = b_mode; -return merge_file_1 (o, &one, &a, &b, branch1, branch2); +return merge_file_1 (o, &one, &a, &b, branch1, branch2, mfi); } static void handle_change_delete(struct merge_options *o,
@@ -1187,11 +1189,12 @@ static void conflict_rename_rename_1to2(struct merge_options *o,struct merge_file_info mfi;struct diff_filespec other;struct diff_filespec *add; - mfi =merge_file_one (o, one->path, +if (merge_file_one (o, one->path, &one->oid, one->mode, &a->oid, a->mode, &b->oid, b->mode, - ci->branch1, ci->branch2); + ci->branch1, ci->branch2, &mfi)) +return ;/* * FIXME: For rename/add-source conflicts (if we could detect * such), this is wrong. We should instead find a unique
@@ -1245,12 +1248,13 @@ static void conflict_rename_rename_2to1(struct merge_options *o,remove_file (o,1 , a->path, o->call_depth ||would_lose_untracked (a->path));remove_file (o,1 , b->path, o->call_depth ||would_lose_untracked (b->path)); - mfi_c1 =merge_file_special_markers (o, a, c1, &ci->ren1_other, - o->branch1, c1->path, - o->branch2, ci->ren1_other.path); - mfi_c2 =merge_file_special_markers (o, b, &ci->ren2_other, c2, - o->branch1, ci->ren2_other.path, - o->branch2, c2->path); +if (merge_file_special_markers (o, a, c1, &ci->ren1_other, + o->branch1, c1->path, + o->branch2, ci->ren1_other.path, &mfi_c1) || +merge_file_special_markers (o, b, &ci->ren2_other, c2, + o->branch1, ci->ren2_other.path, + o->branch2, c2->path, &mfi_c2)) +return ;if (o->call_depth) {/*
@@ -1473,12 +1477,13 @@ static int process_renames(struct merge_options *o, ren1_dst, branch2);if (o->call_depth) {struct merge_file_info mfi; - mfi =merge_file_one (o, ren1_dst, &null_oid,0 , - &ren1->pair->two->oid, - ren1->pair->two->mode, - &dst_other.oid, - dst_other.mode, - branch1, branch2); +if (merge_file_one (o, ren1_dst, &null_oid,0 , + &ren1->pair->two->oid, + ren1->pair->two->mode, + &dst_other.oid, + dst_other.mode, + branch1, branch2, &mfi)) +return -1 ;output (o,1 ,_ ("Adding merged %s" ), ren1_dst);update_file (o,0 , &mfi.oid, mfi.mode, ren1_dst);
@@ -1636,9 +1641,10 @@ static int merge_content(struct merge_options *o,if (dir_in_way (path, !o->call_depth)) df_conflict_remains =1 ; } - mfi =merge_file_special_markers (o, &one, &a, &b, - o->branch1, path1, - o->branch2, path2); +if (merge_file_special_markers (o, &one, &a, &b, + o->branch1, path1, + o->branch2, path2, &mfi)) +return -1 ;if (mfi.clean && !df_conflict_remains &&oid_eq (&mfi.oid, a_oid) && mfi.mode == a_mode) {
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 8/16 merge-recursive: allow write_tree_from_memory() to error out
In reply to Johannes SchindelinIt is possible that a tree cannot be written (think: disk full). We will want to give the caller a chance to clean up instead of letting the program die() in such a case.
--- merge-recursive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
merge-recursive.c +2 -2
@@ -1888,8 +1888,8 @@ int merge_trees(struct merge_options *o,else clean =1 ; -if (o->call_depth) - *result =write_tree_from_memory (o); +if (o->call_depth && !(*result =write_tree_from_memory (o))) +return -1 ;return clean; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 9/16 merge-recursive: handle return values indicating errors
In reply to Johannes SchindelinWe are about to libify the recursive merge machinery, where we only die() in case of a bug or memory contention. To that end, we must heed negative return values as indicating errors.
This requires our functions to be careful to pass through error conditions in call chains, and for quite a few functions this means that they have to return values to begin with.
The next step will be to convert the places where we currently die() to return negative values (read: -1) instead.
Note that we ignore errors reported by make_room_for_path(), consistent with the previous behavior (update_file_flags() used the return value of make_room_for_path() only to indicate an early return, but not a fatal error): if the error is really a fatal error, we will notice later; If not, it was not that serious a problem to begin with. (Witnesses in favor of this reasoning are t4151-am-abort and t7610-mergetool, which would start failing if we stopped on errors reported by make_room_for_path()).
Also note: while this patch makes the code slightly less readable in update_file_flags() (we introduce a new "goto free_buf;" instead of an explicit "free(buf); return;"), it is a preparatory change for the next patch where we will convert all of the die() calls in the same function to go through the free_buf return path instead.
--- merge-recursive.c | 252 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 150 insertions(+), 102 deletions(-)
merge-recursive.c +150 -102
@@ -742,12 +742,12 @@ static int make_room_for_path(struct merge_options *o, const char *path)return error (msg, path,_ (": perhaps a D/F conflict?" )); } -static void update_file_flags (struct merge_options *o, -const struct object_id *oid, -unsigned mode, -const char *path, -int update_cache, -int update_wd) +static int update_file_flags (struct merge_options *o, +const struct object_id *oid, +unsigned mode, +const char *path, +int update_cache, +int update_wd) {if (o->call_depth) update_wd =0 ;
@@ -783,8 +783,7 @@ static void update_file_flags(struct merge_options *o,if (make_room_for_path (o, path) <0 ) { update_wd =0 ; -free (buf); - goto update_index; + goto free_buf; }if (S_ISREG (mode) || (!has_symlinks &&S_ISLNK (mode))) {int fd;
@@ -807,20 +806,22 @@ static void update_file_flags(struct merge_options *o, }else die (_ ("do not know what to do with %06o %s '%s'" ), mode,oid_to_hex (oid), path); + free_buf:free (buf); } update_index:if (update_cache)add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); +return 0 ; } -static void update_file (struct merge_options *o, -int clean, -const struct object_id *oid, -unsigned mode, -const char *path) +static int update_file (struct merge_options *o, +int clean, +const struct object_id *oid, +unsigned mode, +const char *path) { -update_file_flags (o, oid, mode, path, o->call_depth || clean, !o->call_depth); +return update_file_flags (o, oid, mode, path, o->call_depth || clean, !o->call_depth); }/* Low level file merging, update and removal */
@@ -1019,7 +1020,7 @@ static int merge_file_one(struct merge_options *o,return merge_file_1 (o, &one, &a, &b, branch1, branch2, mfi); } -static void handle_change_delete(struct merge_options *o, +static int handle_change_delete(struct merge_options *o, const char *path, const struct object_id *o_oid, int o_mode, const struct object_id *a_oid, int a_mode,
@@ -1027,6 +1028,7 @@ static void handle_change_delete(struct merge_options *o, const char *change, const char *change_past) { char *renamed = NULL; +int ret =0 ;if (dir_in_way (path, !o->call_depth)) { renamed =unique_path (o, path, a_oid ? o->branch1 : o->branch2); }
@@ -1037,21 +1039,23 @@ static void handle_change_delete(struct merge_options *o,* correct; since there is no true "middle point" between * them, simply reuse the base version for virtual merge base. */ -remove_file_from_cache (path); -update_file (o,0 , o_oid, o_mode, renamed ? renamed : path); + ret =remove_file_from_cache (path); +if (!ret) + ret =update_file (o,0 , o_oid, o_mode, + renamed ? renamed : path); }else if (!a_oid) {if (!renamed) {output (o,1 ,_ ("CONFLICT (%s/delete): %s deleted in %s " "and %s in %s. Version %s of %s left in tree." ), change, path, o->branch1, change_past, o->branch2, o->branch2, path); -update_file (o,0 , b_oid, b_mode, path); + ret =update_file (o,0 , b_oid, b_mode, path); }else {output (o,1 ,_ ("CONFLICT (%s/delete): %s deleted in %s " "and %s in %s. Version %s of %s left in tree at %s." ), change, path, o->branch1, change_past, o->branch2, o->branch2, path, renamed); -update_file (o,0 , b_oid, b_mode, renamed); + ret =update_file (o,0 , b_oid, b_mode, renamed); } }else {if (!renamed) {
@@ -1064,7 +1068,7 @@ static void handle_change_delete(struct merge_options *o, "and %s in %s. Version %s of %s left in tree at %s."), change, path, o->branch2, change_past, o->branch1, o->branch1, path, renamed); -update_file (o,0 , a_oid, a_mode, renamed); + ret =update_file (o,0 , a_oid, a_mode, renamed); }/* * No need to call update_file() on path when !renamed, since
@@ -1074,9 +1078,11 @@ static void handle_change_delete(struct merge_options *o,*/ }free (renamed); + +return ret; } -static void conflict_rename_delete (struct merge_options *o, +static int conflict_rename_delete (struct merge_options *o,struct diff_filepair *pair,const char *rename_branch,const char *other_branch)
@@ -1096,21 +1102,20 @@ static void conflict_rename_delete(struct merge_options *o, b_mode = dest->mode; } -handle_change_delete (o, - o->call_depth ? orig->path : dest->path, - &orig->oid, orig->mode, - a_oid, a_mode, - b_oid, b_mode, -_ ("rename" ),_ ("renamed" )); - -if (o->call_depth) { -remove_file_from_cache (dest->path); - }else { -update_stages (dest->path,NULL , - rename_branch == o->branch1 ? dest :NULL , - rename_branch == o->branch1 ?NULL : dest); - } +if (handle_change_delete (o, + o->call_depth ? orig->path : dest->path, + &orig->oid, orig->mode, + a_oid, a_mode, + b_oid, b_mode, +_ ("rename" ),_ ("renamed" ))) +return -1 ; +if (o->call_depth) +return remove_file_from_cache (dest->path); +else +return update_stages (dest->path,NULL , + rename_branch == o->branch1 ? dest :NULL , + rename_branch == o->branch1 ?NULL : dest); } static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
@@ -1126,7 +1131,7 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,return target; } -static void handle_file (struct merge_options *o, +static int handle_file (struct merge_options *o,struct diff_filespec *rename,int stage,struct rename_conflict_info *ci)
@@ -1136,6 +1141,7 @@ static void handle_file(struct merge_options *o,const char *cur_branch, *other_branch;struct diff_filespec other;struct diff_filespec *add; +int ret;if (stage ==2 ) { dst_entry = ci->dst_entry1;
@@ -1150,7 +1156,8 @@ static void handle_file(struct merge_options *o, add =filespec_from_entry (&other, dst_entry, stage ^1 );if (add) {char *add_name =unique_path (o, rename->path, other_branch); -update_file (o,0 , &add->oid, add->mode, add_name); +if (update_file (o,0 , &add->oid, add->mode, add_name)) +return -1 ;remove_file (o,0 , rename->path,0 ); dst_name =unique_path (o, rename->path, cur_branch);
@@ -1161,17 +1168,20 @@ static void handle_file(struct merge_options *o, rename->path, other_branch, dst_name); } } -update_file (o,0 , &rename->oid, rename->mode, dst_name); -if (stage ==2 ) -update_stages (rename->path,NULL , rename, add); +if ((ret =update_file (o,0 , &rename->oid, rename->mode, dst_name))) + ;/* fall through, do allow dst_name to be released */ +else if (stage ==2 ) + ret =update_stages (rename->path,NULL , rename, add);else -update_stages (rename->path,NULL , add, rename); + ret =update_stages (rename->path,NULL , add, rename);if (dst_name != rename->path)free (dst_name); + +return ret; } -static void conflict_rename_rename_1to2 (struct merge_options *o, +static int conflict_rename_rename_1to2 (struct merge_options *o,struct rename_conflict_info *ci) {/* One file was renamed in both branches, but to different names. */
@@ -1194,14 +1204,16 @@ static void conflict_rename_rename_1to2(struct merge_options *o, &a->oid, a->mode, &b->oid, b->mode, ci->branch1, ci->branch2, &mfi)) - return; +return -1 ; +/* * FIXME: For rename/add-source conflicts (if we could detect * such), this is wrong. We should instead find a unique * pathname and then either rename the add-source file to that * unique path, or use that unique path instead of src here. */ -update_file (o,0 , &mfi.oid, mfi.mode, one->path); +if (update_file (o,0 , &mfi.oid, mfi.mode, one->path)) +return -1 ;/* * Above, we put the merged content at the merge-base's
@@ -1212,22 +1224,26 @@ static void conflict_rename_rename_1to2(struct merge_options *o,* resolving the conflict at that path in its favor. */ add =filespec_from_entry (&other, ci->dst_entry1,2 ^1 ); -if (add) -update_file (o,0 , &add->oid, add->mode, a->path); +if (add) { +if (update_file (o,0 , &add->oid, add->mode, a->path)) +return -1 ; + }else remove_file_from_cache (a->path); add =filespec_from_entry (&other, ci->dst_entry2,3 ^1 ); -if (add) -update_file (o,0 , &add->oid, add->mode, b->path); +if (add) { +if (update_file (o,0 , &add->oid, add->mode, b->path)) +return -1 ; + }else remove_file_from_cache (b->path); - }else { -handle_file (o, a,2 , ci); -handle_file (o, b,3 , ci); - } + }else if (handle_file (o, a,2 , ci) ||handle_file (o, b,3 , ci)) +return -1 ; + +return 0 ; } -static void conflict_rename_rename_2to1 (struct merge_options *o, +static int conflict_rename_rename_2to1 (struct merge_options *o,struct rename_conflict_info *ci) {/* Two files, a & b, were renamed to the same thing, c. */
@@ -1238,6 +1254,7 @@ static void conflict_rename_rename_2to1(struct merge_options *o,char *path = c1->path;/* == c2->path */ struct merge_file_info mfi_c1;struct merge_file_info mfi_c2; +int ret; output(o, 1, _("CONFLICT (rename/rename): " "Rename %s->%s in %s. "
@@ -1254,7 +1271,7 @@ static void conflict_rename_rename_2to1(struct merge_options *o,merge_file_special_markers (o, b, &ci->ren2_other, c2, o->branch1, ci->ren2_other.path, o->branch2, c2->path, &mfi_c2)) - return; + return -1;if (o->call_depth) {/*
@@ -1265,19 +1282,25 @@ static void conflict_rename_rename_2to1(struct merge_options *o,* again later for the non-recursive merge. */ remove_file (o,0 , path,0 ); -update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, a->path); -update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, b->path); + ret =update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, a->path); +if (!ret) + ret =update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, + b->path); }else {char *new_path1 =unique_path (o, path, ci->branch1);char *new_path2 =unique_path (o, path, ci->branch2);output (o,1 ,_ ("Renaming %s to %s and %s to %s instead" ), a->path, new_path1, b->path, new_path2);remove_file (o,0 , path,0 ); -update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, new_path1); -update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, new_path2); + ret =update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, new_path1); +if (!ret) + ret =update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, + new_path2);free (new_path2);free (new_path1); } + +return ret; } static int process_renames(struct merge_options *o,
@@ -1462,12 +1485,13 @@ static int process_renames(struct merge_options *o,* update_file_flags() instead of * update_file(). */ -update_file_flags (o, - &ren1->pair->two->oid, - ren1->pair->two->mode, - ren1_dst, -1 ,/* update_cache */ -0 /* update_wd */ ); +if (update_file_flags (o, + &ren1->pair->two->oid, + ren1->pair->two->mode, + ren1_dst, +1 ,/* update_cache */ +0 /* update_wd */ )) + clean_merge =-1 ; }else if (!oid_eq (&dst_other.oid, &null_oid)) { clean_merge =0 ; try_merge =1 ;
@@ -1482,22 +1506,28 @@ static int process_renames(struct merge_options *o, ren1->pair->two->mode, &dst_other.oid, dst_other.mode, - branch1, branch2, &mfi)) - return -1; + branch1, branch2, &mfi)) { + clean_merge =-1 ; + goto cleanup_and_return; + }output (o,1 ,_ ("Adding merged %s" ), ren1_dst); -update_file (o,0 , &mfi.oid, - mfi.mode, ren1_dst); +if (update_file (o,0 , &mfi.oid, + mfi.mode, ren1_dst)) + clean_merge =-1 ; try_merge =0 ; }else {char *new_path =unique_path (o, ren1_dst, branch2);output (o,1 ,_ ("Adding as %s instead" ), new_path); -update_file (o,0 , &dst_other.oid, - dst_other.mode, new_path); +if (update_file (o,0 , &dst_other.oid, + dst_other.mode, new_path)) + clean_merge =-1 ;free (new_path); } }else try_merge =1 ; +if (clean_merge <0 ) + goto cleanup_and_return;if (try_merge) {struct diff_filespec *one, *a, *b; src_other.path = (char *)ren1_src;
@@ -1524,6 +1554,7 @@ static int process_renames(struct merge_options *o, } } } +cleanup_and_return:string_list_clear (&a_by_dst,0 );string_list_clear (&b_by_dst,0 );
@@ -1586,18 +1617,18 @@ static int blob_unchanged(const struct object_id *o_oid,return ret; } -static void handle_modify_delete (struct merge_options *o, +static int handle_modify_delete (struct merge_options *o,const char *path,struct object_id *o_oid,int o_mode,struct object_id *a_oid,int a_mode,struct object_id *b_oid,int b_mode) { -handle_change_delete (o, - path, - o_oid, o_mode, - a_oid, a_mode, - b_oid, b_mode, -_ ("modify" ),_ ("modified" )); +return handle_change_delete (o, + path, + o_oid, o_mode, + a_oid, a_mode, + b_oid, b_mode, +_ ("modify" ),_ ("modified" )); } static int merge_content(struct merge_options *o,
@@ -1671,7 +1702,8 @@ static int merge_content(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): Merge conflict in %s" ), reason, path);if (rename_conflict_info && !df_conflict_remains) -update_stages (path, &one, &a, &b); +if (update_stages (path, &one, &a, &b)) +return -1 ; }if (df_conflict_remains) {
@@ -1679,30 +1711,33 @@ static int merge_content(struct merge_options *o,if (o->call_depth) {remove_file_from_cache (path); }else { -if (!mfi.clean) -update_stages (path, &one, &a, &b); -else { +if (!mfi.clean) { +if (update_stages (path, &one, &a, &b)) +return -1 ; + }else {int file_from_stage2 =was_tracked (path);struct diff_filespec merged;oidcpy (&merged.oid, &mfi.oid); merged.mode = mfi.mode; -update_stages (path,NULL , - file_from_stage2 ? &merged :NULL , - file_from_stage2 ?NULL : &merged); +if (update_stages (path,NULL , + file_from_stage2 ? &merged :NULL , + file_from_stage2 ?NULL : &merged)) +return -1 ; } } new_path =unique_path (o, path, rename_conflict_info->branch1);output (o,1 ,_ ("Adding as %s instead" ), new_path); -update_file (o,0 , &mfi.oid, mfi.mode, new_path); +if (update_file (o,0 , &mfi.oid, mfi.mode, new_path)) { +free (new_path); +return -1 ; + }free (new_path); mfi.clean =0 ; - }else { -update_file (o, mfi.clean, &mfi.oid, mfi.mode, path); - } + }else if (update_file (o, mfi.clean, &mfi.oid, mfi.mode, path)) +return -1 ;return mfi.clean; - }/* Per entry merge function */
@@ -1730,17 +1765,21 @@ static int process_entry(struct merge_options *o,break ;case RENAME_DELETE : clean_merge =0 ; -conflict_rename_delete (o, conflict_info->pair1, - conflict_info->branch1, - conflict_info->branch2); +if (conflict_rename_delete (o, + conflict_info->pair1, + conflict_info->branch1, + conflict_info->branch2)) + clean_merge =-1 ;break ;case RENAME_ONE_FILE_TO_TWO : clean_merge =0 ; -conflict_rename_rename_1to2 (o, conflict_info); +if (conflict_rename_rename_1to2 (o, conflict_info)) + clean_merge =-1 ;break ;case RENAME_TWO_FILES_TO_ONE : clean_merge =0 ; -conflict_rename_rename_2to1 (o, conflict_info); +if (conflict_rename_rename_2to1 (o, conflict_info)) + clean_merge =-1 ;break ;default : entry->processed =0 ;
@@ -1760,8 +1799,9 @@ static int process_entry(struct merge_options *o, }else {/* Modify/delete; deleted side may have put a directory in the way */ clean_merge =0 ; -handle_modify_delete (o, path, o_oid, o_mode, - a_oid, a_mode, b_oid, b_mode); +if (handle_modify_delete (o, path, o_oid, o_mode, + a_oid, a_mode, b_oid, b_mode)) + clean_merge =-1 ; } }else if ((!o_oid && a_oid && !b_oid) || (!o_oid && !a_oid && b_oid)) {
@@ -1793,14 +1833,16 @@ static int process_entry(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): There is a directory with name %s in %s. " "Adding %s as %s" ), conf, path, other_branch, path, new_path); -update_file (o,0 , oid, mode, new_path); -if (o->call_depth) +if (update_file (o,0 , oid, mode, new_path)) + clean_merge =-1 ; +else if (o->call_depth)remove_file_from_cache (path);free (new_path); }else {output (o,2 ,_ ("Adding %s" ), path);/* do not overwrite file if already present */ -update_file_flags (o, oid, mode, path,1 , !a_oid); +if (update_file_flags (o, oid, mode, path,1 , !a_oid)) + clean_merge =-1 ; } }else if (a_oid && b_oid) {/* Case C: Added in both (check for same permissions) and */
@@ -1863,12 +1905,18 @@ int merge_trees(struct merge_options *o, re_head =get_renames (o, head, common, head, merge, entries); re_merge =get_renames (o, merge, common, head, merge, entries); clean =process_renames (o, re_head, re_merge); +if (clean <0 ) +return clean;for (i = entries->nr-1 ;0 <= i; i--) {const char *path = entries->items[i].string;struct stage_data *e = entries->items[i].util; -if (!e->processed - && !process_entry (o, path, e)) - clean =0 ; +if (!e->processed) { +int ret =process_entry (o, path, e); +if (!ret) + clean =0 ; +else if (ret <0 ) +return ret; + } }for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 10/16 merge-recursive: switch to returning errors instead of dying
In reply to Johannes SchindelinThe recursive merge machinery is supposed to be a library function, i.e. it should return an error when it fails. Originally the functions were part of the builtin "merge-recursive", though, where it was simpler to call die() and be done with error handling.
The existing callers were already prepared to detect negative return values to indicate errors and to behave as previously: exit with code 128 (which is the same thing that die() does, after printing the message).
--- merge-recursive.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-)
merge-recursive.c +35 -27
@@ -275,8 +275,10 @@ struct tree *write_tree_from_memory(struct merge_options *o) active_cache_tree =cache_tree ();if (!cache_tree_fully_valid (active_cache_tree) && -cache_tree_update (&the_index,0 ) <0 ) -die (_ ("error building trees" )); +cache_tree_update (&the_index,0 ) <0 ) { +error (_ ("error building trees" )); +return NULL ; + } result =lookup_tree (active_cache_tree->sha1);
@@ -716,12 +718,10 @@ static int make_room_for_path(struct merge_options *o, const char *path)/* Make sure leading directories are created */ status =safe_create_leading_directories_const (path);if (status) { -if (status ==SCLD_EXISTS ) { +if (status ==SCLD_EXISTS )/* something else exists */ -error (msg, path,_ (": perhaps a D/F conflict?" )); -return -1 ; - } -die (msg, path,"" ); +return error (msg, path,_ (": perhaps a D/F conflict?" )); +return error (msg, path,"" ); }/*
@@ -749,6 +749,8 @@ static int update_file_flags(struct merge_options *o,int update_cache, int update_wd) { + int ret = 0; +if (o->call_depth) update_wd =0 ;
@@ -769,9 +771,11 @@ static int update_file_flags(struct merge_options *o, buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -die (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); -if (type !=OBJ_BLOB ) -die (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); +return error (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); +if (type !=OBJ_BLOB ) { + ret =error (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); + goto free_buf; + }if (S_ISREG (mode)) {struct strbuf strbuf =STRBUF_INIT ;if (convert_to_working_tree (path, buf, size, &strbuf)) {
@@ -792,8 +796,11 @@ static int update_file_flags(struct merge_options *o,else mode =0666 ; fd =open (path,O_WRONLY |O_TRUNC |O_CREAT , mode); -if (fd <0 ) -die_errno (_ ("failed to open '%s'" ), path); +if (fd <0 ) { + ret =error_errno (_ ("failed to open '%s'" ), + path); + goto free_buf; + }write_in_full (fd, buf, size);close (fd); }else if (S_ISLNK (mode)) {
@@ -801,18 +808,18 @@ static int update_file_flags(struct merge_options *o,safe_create_leading_directories_const (path);unlink (path);if (symlink (lnk, path)) -die_errno (_ ("failed to symlink '%s'" ), path); + ret =error_errno (_ ("failed to symlink '%s'" ), path);free (lnk); }else -die (_ ("do not know what to do with %06o %s '%s'" ), - mode,oid_to_hex (oid), path); + ret =error (_ ("do not know what to do with %06o %s '%s'" ), + mode,oid_to_hex (oid), path); free_buf:free (buf); } update_index: -if (update_cache) +if (!ret && update_cache)add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); -return 0 ; +return ret; } static int update_file(struct merge_options *o,
@@ -938,20 +945,22 @@ static int merge_file_1(struct merge_options *o,oidcpy (&result->oid, &a->oid); else if (S_ISREG(a->mode)) {mmbuffer_t result_buf; -int merge_status; +int ret =0 , merge_status; merge_status =merge_3way (o, &result_buf, one, a, b, branch1, branch2);if ((merge_status <0 ) || !result_buf.ptr) -die (_ ("Failed to execute internal merge" )); + ret =error (_ ("Failed to execute internal merge" )); -if (write_sha1_file (result_buf.ptr, result_buf.size, - blob_type, result->oid.hash)) -die (_ ("Unable to add %s to database" ), - a->path); +if (!ret &&write_sha1_file (result_buf.ptr, result_buf.size, + blob_type, result->oid.hash)) + ret =error (_ ("Unable to add %s to database" ), + a->path);free (result_buf.ptr); +if (ret) +return ret; result->clean = (merge_status ==0 ); } else if (S_ISGITLINK(a->mode)) { result->clean = merge_submodule(result->oid.hash,
@@ -1885,11 +1894,10 @@ int merge_trees(struct merge_options *o,if (code !=0 ) {if (show (o,4 ) || o->call_depth) -die (_ ("merging of trees %s and %s failed" ), +error (_ ("merging of trees %s and %s failed" ),oid_to_hex (&head->object.oid),oid_to_hex (&merge->object.oid)); -else -exit (128 ); +return -1 ; }if (unmerged_cache ()) {
@@ -2021,7 +2029,7 @@ int merge_recursive(struct merge_options *o, o->call_depth--;if (!merged_common_ancestors) -die (_ ("merge returned no commit" )); +return error (_ ("merge returned no commit" )); }discard_cache ();
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 11/16 am -3: use merge_recursive() directly again
In reply to Johannes SchindelinLast October, we had to change this code to run git merge-recursive in a child process: git-am wants to print some helpful advice when the merge failed, but the code in question was not prepared to return, it die()d instead.
We are finally at a point when the code *is* prepared to return errors, and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from completing the error codepath, 2015-10-09), with the necessary changes to adjust for the fact that Git's source code changed in the meantime (such as: using OIDs instead of hashes in the recursive merge, and a removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike merge_trees() and merge_recursive(), this function returns 0 upon success, as most of Git's functions. Therefore, the error value -1 naturally is handled correctly, and we do not have to take care of it specifically.
--- builtin/am.c | 62 +++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 40 deletions(-)
builtin/am.c +22 -40
@@ -1579,47 +1579,18 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f }/** -* Do the three-way merge using fake ancestor, their tree constructed -* from the fake ancestor and the postimage of the patch, and our -* state. -*/ -static int run_fallback_merge_recursive (const struct am_state *state, -unsigned char *orig_tree, -unsigned char *our_tree, -unsigned char *their_tree) -{ -struct child_process cp =CHILD_PROCESS_INIT ; -int status; - - cp.git_cmd =1 ; - -argv_array_pushf (&cp.env_array,"GITHEAD_%s=%.*s" , -sha1_to_hex (their_tree),linelen (state->msg), state->msg); -if (state->quiet) -argv_array_push (&cp.env_array,"GIT_MERGE_VERBOSITY=0" ); - -argv_array_push (&cp.args,"merge-recursive" ); -argv_array_push (&cp.args,sha1_to_hex (orig_tree)); -argv_array_push (&cp.args,"--" ); -argv_array_push (&cp.args,sha1_to_hex (our_tree)); -argv_array_push (&cp.args,sha1_to_hex (their_tree)); - - status =run_command (&cp) ? (-1 ) :0 ; -discard_cache (); -read_cache (); -return status; -} - -/** * Attempt a threeway merge, using index_path as the temporary index. */ static int fall_back_threeway (const struct am_state *state,const char *index_path) { -unsigned char orig_tree[GIT_SHA1_RAWSZ ], their_tree[GIT_SHA1_RAWSZ ], - our_tree[GIT_SHA1_RAWSZ ]; +struct object_id orig_tree, their_tree, our_tree; +const struct object_id *bases[1 ] = { &orig_tree }; +struct merge_options o; +struct commit *result; +char *their_tree_name; -if (get_sha1 ("HEAD" , our_tree) <0 ) -hashcpy (our_tree,EMPTY_TREE_SHA1_BIN ); +if (get_oid ("HEAD" , &our_tree) <0 ) +hashcpy (our_tree.hash,EMPTY_TREE_SHA1_BIN );if (build_fake_ancestor (state, index_path))return error ("could not build fake ancestor" );
@@ -1627,7 +1598,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_padiscard_cache ();read_cache_from (index_path); -if (write_index_as_tree (orig_tree, &the_index, index_path,0 ,NULL )) +if (write_index_as_tree (orig_tree.hash, &the_index, index_path,0 ,NULL ))return error (_ ("Repository lacks necessary blobs to fall back on 3-way merge." ));say (state, stdout,_ ("Using index info to reconstruct a base tree..." ));
@@ -1643,7 +1614,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_painit_revisions (&rev_info,NULL ); rev_info.diffopt.output_format =DIFF_FORMAT_NAME_STATUS ;diff_opt_parse (&rev_info.diffopt, &diff_filter_str,1 , rev_info.prefix); -add_pending_sha1 (&rev_info,"HEAD" , our_tree,0 ); +add_pending_sha1 (&rev_info,"HEAD" , our_tree.hash,0 );diff_setup_done (&rev_info.diffopt);run_diff_index (&rev_info,1 ); }
@@ -1652,7 +1623,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pareturn error (_ ("Did you hand edit your patch?\n" "It does not apply to blobs recorded in its index." )); -if (write_index_as_tree (their_tree, &the_index, index_path,0 ,NULL )) +if (write_index_as_tree (their_tree.hash, &the_index, index_path,0 ,NULL ))return error ("could not write tree" );say (state, stdout,_ ("Falling back to patching base and 3-way merge..." ));
@@ -1668,11 +1639,22 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa* changes. */ -if (run_fallback_merge_recursive (state, orig_tree, our_tree, their_tree)) { +init_merge_options (&o); + + o.branch1 ="HEAD" ; + their_tree_name =xstrfmt ("%.*s" ,linelen (state->msg), state->msg); + o.branch2 = their_tree_name; + +if (state->quiet) + o.verbosity =0 ; + +if (merge_recursive_generic (&o, &our_tree, &their_tree,1 , bases, &result)) {rerere (state->allow_rerere_autoupdate); +free (their_tree_name);return error (_ ("Failed to merge in the changes." )); } +free (their_tree_name);return 0 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v5 12/16 merge-recursive: flush output buffer before printing error messages
In reply to Johannes SchindelinThe data structure passed to the recursive merge machinery has a feature where the caller can ask for the output to be buffered into a strbuf, by setting the field 'buffer_output'.
Previously, we simply swallowed the buffered output when showing error messages. With this patch, we show the output first, and only then print the error message.
Currently, the only user of that buffering is merge_recursive() itself, to avoid the progress output to interfere.
In the next patches, we will introduce a new buffer_output mode that forces merge_recursive() to retain the output buffer for further processing by the caller. If the caller asked for that, we will then also write the error messages into the output buffer. This is necessary to give the caller more control not only how to react in case of errors but also control how/if to display the error messages.
--- merge-recursive.c | 116 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 48 deletions(-)
merge-recursive.c +68 -48
@@ -23,6 +23,28 @@#include "dir.h" #include "submodule.h" +static void flush_output (struct merge_options *o) +{ +if (o->obuf.len) { +fputs (o->obuf.buf, stdout); +strbuf_reset (&o->obuf); + } +} + +static int err (struct merge_options *o,const char *err, ...) +{ +va_list params; + +va_start (params, err); +flush_output (o); +strbuf_vaddf (&o->obuf, err, params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); +va_end (params); + +return -1 ; +} +static struct tree *shift_tree_object (struct tree *one,struct tree *two,const char *subtree_shift) {
@@ -148,14 +170,6 @@ static int show(struct merge_options *o, int v)return (!o->call_depth && o->verbosity >= v) || o->verbosity >=5 ; } -static void flush_output (struct merge_options *o) -{ -if (o->obuf.len) { -fputs (o->obuf.buf, stdout); -strbuf_reset (&o->obuf); - } -} - __attribute__((format (printf,3 ,4 )))static void output (struct merge_options *o,int v,const char *fmt, ...) {
@@ -198,7 +212,8 @@ static void output_commit_title(struct merge_options *o, struct commit *commit) } } -static int add_cacheinfo (unsigned int mode,const struct object_id *oid, +static int add_cacheinfo (struct merge_options *o, +unsigned int mode,const struct object_id *oid,const char *path,int stage,int refresh,int options) {struct cache_entry *ce;
@@ -206,7 +221,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, ce =make_cache_entry (mode, oid ? oid->hash : null_sha1, path, stage,0 );if (!ce) -return error (_ ("addinfo_cache failed for path '%s'" ), path); +return err (o,_ ("addinfo_cache failed for path '%s'" ), path); ret =add_cache_entry (ce, options);if (refresh) {
@@ -276,7 +291,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)if (!cache_tree_fully_valid (active_cache_tree) &&cache_tree_update (&the_index,0 ) <0 ) { -error (_ ("error building trees" )); +err (o,_ ("error building trees" ));return NULL ; }
@@ -544,7 +559,8 @@ static struct string_list *get_renames(struct merge_options *o,return renames; } -static int update_stages (const char *path,const struct diff_filespec *o, +static int update_stages (struct merge_options *opt,const char *path, +const struct diff_filespec *o,const struct diff_filespec *a,const struct diff_filespec *b) {
@@ -563,13 +579,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,if (remove_file_from_cache (path))return -1 ;if (o) -if (add_cacheinfo (o->mode, &o->oid, path,1 ,0 , options)) +if (add_cacheinfo (opt, o->mode, &o->oid, path,1 ,0 , options))return -1 ;if (a) -if (add_cacheinfo (a->mode, &a->oid, path,2 ,0 , options)) +if (add_cacheinfo (opt, a->mode, &a->oid, path,2 ,0 , options))return -1 ;if (b) -if (add_cacheinfo (b->mode, &b->oid, path,3 ,0 , options)) +if (add_cacheinfo (opt, b->mode, &b->oid, path,3 ,0 , options))return -1 ;return 0 ; }
@@ -720,8 +736,8 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (status) {if (status ==SCLD_EXISTS )/* something else exists */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); -return error (msg, path,"" ); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,"" ); }/*
@@ -729,7 +745,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)* tracking it. */ if (would_lose_untracked (path)) -return error (_ ("refusing to lose untracked file at '%s'" ), +return err (o,_ ("refusing to lose untracked file at '%s'" ), path);/* Successful unlink is good.. */
@@ -739,7 +755,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (errno ==ENOENT )return 0 ;/* .. but not some other error (who really cares what?) */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); } static int update_file_flags(struct merge_options *o,
@@ -771,9 +787,9 @@ static int update_file_flags(struct merge_options *o, buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); +return err (o,_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path);if (type !=OBJ_BLOB ) { - ret =error (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); + ret =err (o,_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); goto free_buf; }if (S_ISREG (mode)) {
@@ -797,8 +813,8 @@ static int update_file_flags(struct merge_options *o, mode =0666 ; fd =open (path,O_WRONLY |O_TRUNC |O_CREAT , mode);if (fd <0 ) { - ret =error_errno (_ ("failed to open '%s'" ), - path); + ret =err (o,_ ("failed to open '%s': %s" ), + path,strerror (errno)); goto free_buf; }write_in_full (fd, buf, size);
@@ -808,17 +824,19 @@ static int update_file_flags(struct merge_options *o,safe_create_leading_directories_const (path);unlink (path);if (symlink (lnk, path)) - ret =error_errno (_ ("failed to symlink '%s'" ), path); + ret =err (o,_ ("failed to symlink '%s': %s" ), + path,strerror (errno));free (lnk); }else - ret =error (_ ("do not know what to do with %06o %s '%s'" ), - mode,oid_to_hex (oid), path); + ret =err (o, +_ ("do not know what to do with %06o %s '%s'" ), + mode,oid_to_hex (oid), path); free_buf:free (buf); } update_index:if (!ret && update_cache) -add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); +add_cacheinfo (o, mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD );return ret; }
@@ -951,12 +969,12 @@ static int merge_file_1(struct merge_options *o, branch1, branch2);if ((merge_status <0 ) || !result_buf.ptr) - ret =error (_ ("Failed to execute internal merge" )); + ret =err (o,_ ("Failed to execute internal merge" ));if (!ret &&write_sha1_file (result_buf.ptr, result_buf.size, blob_type, result->oid.hash)) - ret =error (_ ("Unable to add %s to database" ), - a->path); + ret =err (o,_ ("Unable to add %s to database" ), + a->path);free (result_buf.ptr);if (ret)
@@ -1122,7 +1140,7 @@ static int conflict_rename_delete(struct merge_options *o,if (o->call_depth)return remove_file_from_cache (dest->path);else -return update_stages (dest->path,NULL , +return update_stages (o, dest->path,NULL , rename_branch == o->branch1 ? dest :NULL , rename_branch == o->branch1 ?NULL : dest); }
@@ -1180,9 +1198,9 @@ static int handle_file(struct merge_options *o,if ((ret =update_file (o,0 , &rename->oid, rename->mode, dst_name))) ;/* fall through, do allow dst_name to be released */ else if (stage ==2 ) - ret =update_stages (rename->path,NULL , rename, add); + ret =update_stages (o, rename->path,NULL , rename, add);else - ret =update_stages (rename->path,NULL , add, rename); + ret =update_stages (o, rename->path,NULL , add, rename);if (dst_name != rename->path)free (dst_name);
@@ -1575,23 +1593,25 @@ static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)return (is_null_oid (oid) || mode ==0 ) ?NULL : (struct object_id *)oid; } -static int read_oid_strbuf (const struct object_id *oid,struct strbuf *dst) +static int read_oid_strbuf (struct merge_options *o, +const struct object_id *oid,struct strbuf *dst) {void *buf;enum object_type type;unsigned long size; buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s" ),oid_to_hex (oid)); +return err (o,_ ("cannot read object %s" ),oid_to_hex (oid));if (type !=OBJ_BLOB ) {free (buf); -return error (_ ("object %s is not a blob" ),oid_to_hex (oid)); +return err (o,_ ("object %s is not a blob" ),oid_to_hex (oid)); }strbuf_attach (dst, buf, size, size +1 );return 0 ; } -static int blob_unchanged(const struct object_id *o_oid, +static int blob_unchanged(struct merge_options *opt, + const struct object_id *o_oid, unsigned o_mode, const struct object_id *a_oid, unsigned a_mode,
@@ -1609,7 +1629,7 @@ static int blob_unchanged(const struct object_id *o_oid,return 0 ;assert (o_oid && a_oid); -if (read_oid_strbuf (o_oid, &o) ||read_oid_strbuf (a_oid, &a)) +if (read_oid_strbuf (opt, o_oid, &o) ||read_oid_strbuf (opt, a_oid, &a)) goto error_return;/* * Note: binary | is used so that both renormalizations are
@@ -1698,7 +1718,7 @@ static int merge_content(struct merge_options *o,*/ path_renamed_outside_HEAD = !path2 || !strcmp (path, path2);if (!path_renamed_outside_HEAD) { -add_cacheinfo (mfi.mode, &mfi.oid, path, +add_cacheinfo (o, mfi.mode, &mfi.oid, path,0 , (!o->call_depth),0 );return mfi.clean; }
@@ -1711,7 +1731,7 @@ static int merge_content(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): Merge conflict in %s" ), reason, path);if (rename_conflict_info && !df_conflict_remains) -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }
@@ -1721,7 +1741,7 @@ static int merge_content(struct merge_options *o,remove_file_from_cache (path); }else {if (!mfi.clean) { -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }else {int file_from_stage2 =was_tracked (path);
@@ -1729,7 +1749,7 @@ static int merge_content(struct merge_options *o,oidcpy (&merged.oid, &mfi.oid); merged.mode = mfi.mode; -if (update_stages (path,NULL , +if (update_stages (o, path,NULL , file_from_stage2 ? &merged :NULL , file_from_stage2 ?NULL : &merged))return -1 ;
@@ -1797,8 +1817,8 @@ static int process_entry(struct merge_options *o, }else if (o_oid && (!a_oid || !b_oid)) {/* Case A: Deleted in one */ if ((!a_oid && !b_oid) || - (!b_oid &&blob_unchanged (o_oid, o_mode, a_oid, a_mode, normalize, path)) || - (!a_oid &&blob_unchanged (o_oid, o_mode, b_oid, b_mode, normalize, path))) { + (!b_oid &&blob_unchanged (o, o_oid, o_mode, a_oid, a_mode, normalize, path)) || + (!a_oid &&blob_unchanged (o, o_oid, o_mode, b_oid, b_mode, normalize, path))) {/* Deleted in both or deleted in one and * unchanged in the other */ if (a_oid)
@@ -1894,7 +1914,7 @@ int merge_trees(struct merge_options *o,if (code !=0 ) {if (show (o,4 ) || o->call_depth) -error (_ ("merging of trees %s and %s failed" ), +err (o,_ ("merging of trees %s and %s failed" ),oid_to_hex (&head->object.oid),oid_to_hex (&merge->object.oid));return -1 ;
@@ -2029,7 +2049,7 @@ int merge_recursive(struct merge_options *o, o->call_depth--;if (!merged_common_ancestors) -return error (_ ("merge returned no commit" )); +return err (o,_ ("merge returned no commit" )); }discard_cache ();
@@ -2088,7 +2108,7 @@ int merge_recursive_generic(struct merge_options *o,for (i =0 ; i < num_base_list; ++i) {struct commit *base;if (!(base =get_ref (base_list[i],oid_to_hex (base_list[i])))) -return error (_ ("Could not parse object '%s'" ), +return err (o,_ ("Could not parse object '%s'" ),oid_to_hex (base_list[i]));commit_list_insert (base, &ca); }
@@ -2102,7 +2122,7 @@ int merge_recursive_generic(struct merge_options *o,if (active_cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK )) -return error (_ ("Unable to write index." )); +return err (o,_ ("Unable to write index." ));return clean ?0 :1 ; }
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v5 12/16] merge-recursive: flush output buffer before printing error messages
Quoted 7 lines · Johannes Schindelin
The data structure passed to the recursive merge machinery has a feature where the caller can ask for the output to be buffered into a strbuf, by setting the field '
buffer_output'.Previously, we simply swallowed the buffered output when showing error messages. With this patch, we show the output first, and only then print the error message.
I didn't quite understand this paragraph until I realized that you meant "when showing die message". We died without flushing, losing accumulated output.
merge-recursive.c line 39
Quoted 6 lines
merge-recursive.c +6
-0+static int err (struct merge_options *o,const char *err, ...) +{ +va_list params; + +va_start (params, err); +flush_output (o);
I would have written the above two swapped; va_start() logically is about what happens in the next four lines.
merge-recursive.c line 42
Quoted 3 lines
merge-recursive.c +3
-0+strbuf_vaddf (&o->obuf, err, params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf);
Sneaky ;-)
The remainder replaces error(...) with err(o, ...) and updates the callchain to pass the merge_options around, which looked good.
Thanks.
Re: [PATCH v5 12/16] merge-recursive: flush output buffer before printing error messages
Quoted 6 lines · Junio C Hamano
merge-recursive.c line 42
Quoted 4 lines
merge-recursive.c +3
-0+strbuf_vaddf (&o->obuf, err, params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf);Sneaky ;-)
Just to avoid confusion, I am _fine_ with this "we happen to have a strbuf that we know to be empty at this point, so let's reuse it and clean after ourselves before returning".
I just found it somewhere between clever and ugly, and "sneaky" was the first word that came to my mind.
Re: [PATCH v5 12/16] merge-recursive: flush output buffer before printing error messages
In reply to Junio C HamanoHi Junio,
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
The data structure passed to the recursive merge machinery has a feature where the caller can ask for the output to be buffered into a strbuf, by setting the field '
buffer_output'.
Quoted 7 lines
Quoted 3 lines
Previously, we simply swallowed the buffered output when showing error messages. With this patch, we show the output first, and only then print the error message.
I didn't quite understand this paragraph until I realized that you meant "when showing die message". We died without flushing, losing accumulated output.
I rephrased it, using your explanation.
Quoted 9 lines
merge-recursive.c line 39
Quoted 6 lines
merge-recursive.c +6
-0+static int err (struct merge_options *o,const char *err, ...) +{ +va_list params; + +va_start (params, err); +flush_output (o);I would have written the above two swapped;
va_start()logically is about what happens in the next four lines.
For some reason, I thought that va_start() must be the first statement of the function. Fixed.
Quoted 5 lines
merge-recursive.c line 42
Quoted 3 lines
merge-recursive.c +3
-0+strbuf_vaddf (&o->obuf, err, params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf);Sneaky ;-)
Thanks ;-)
Dscho
PATCH v5 13/16 merge-recursive: write the commit title in one go
In reply to Johannes SchindelinIn 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we changed the code such that it prints the output in one go, to avoid interfering with the progress output.
Let's make sure that the same holds true when outputting the commit
title: previously, we used several printf() statements to stdout and speculated that stdout's buffer is large enough to hold the entire commit title.
Apart from making that speculation unnecessary, we change the code to add the message to the output buffer before flushing for another reason:
the next commit will introduce a new level of output buffering, where the caller can request the output not to be flushed, but to be retained for further processing.
This latter feature will be needed when teaching the sequencer to do rebase -i's brunt work: it wants to control the output of the cherry-picks (i.e. recursive merges).
--- merge-recursive.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
merge-recursive.c +9 -8
@@ -191,25 +191,26 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)static void output_commit_title (struct merge_options *o,struct commit *commit) { -int i; -flush_output (o); -for (i = o->call_depth; i--;) -fputs (" " , stdout); +strbuf_addchars (&o->obuf,' ' , o->call_depth *2 );if (commit->util) -printf ("virtual %s\n" ,merge_remote_util (commit)->name); +strbuf_addf (&o->obuf,"virtual %s\n" , +merge_remote_util (commit)->name);else { -printf ("%s " ,find_unique_abbrev (commit->object.oid.hash,DEFAULT_ABBREV )); +strbuf_addf (&o->obuf,"%s " , +find_unique_abbrev (commit->object.oid.hash, +DEFAULT_ABBREV ));if (parse_commit (commit) !=0 ) -printf (_ ("(bad commit)\n" )); +strbuf_addf (&o->obuf,_ ("(bad commit)\n" ));else {const char *title;const char *msg =get_commit_buffer (commit,NULL );int len =find_commit_subject (msg, &title);if (len) -printf ("%.*s\n" , len, title); +strbuf_addf (&o->obuf,"%.*s\n" , len, title);unuse_commit_buffer (commit, msg); } } +flush_output (o); } static int add_cacheinfo(struct merge_options *o,
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v5 13/16] merge-recursive: write the commit title in one go
Quoted 4 lines · Johannes Schindelin
Let's make sure that the same holds true when outputting the commit
title: previously, we used severalprintf()statements to stdout and speculated that stdout's buffer is large enough to hold the entire commit title.
s/speculate/assume/; other than that looks very sensible.
Re: [PATCH v5 13/16] merge-recursive: write the commit title in one go
Hi Junio,
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Let's make sure that the same holds true when outputting the commit
title: previously, we used severalprintf()statements to stdout and speculated that stdout's buffer is large enough to hold the entire commit title.s/speculate/assume/; other than that looks very sensible.
Fixed.
Thanks,
Dscho
PATCH v5 14/16 merge-recursive: offer an option to retain the output in 'obuf'
In reply to Johannes SchindelinSince 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we already accumulate the output in a buffer. The idea was to avoid interfering with the progress output that goes to stderr, which is unbuffered, when we write to stdout, which is buffered.
We extend that buffering to allow the caller to handle the output (possibly suppressing it). This will help us when extending the sequencer to do rebase -i's brunt work: it does not want the picks to print anything by default but instead determine itself whether to print the output or not.
Note that we also redirect the error messages into the output buffer when the caller asked not to flush the output buffer, for two reasons:
1) to retain the correct output order, and 2) to allow the caller to suppress *all* output.
--- merge-recursive.c | 17 +++++++++++++---- merge-recursive.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
merge-recursive.c +13 -4
@@ -25,7 +25,7 @@static void flush_output (struct merge_options *o) { -if (o->obuf.len) { +if (o->buffer_output <2 && o->obuf.len) {fputs (o->obuf.buf, stdout);strbuf_reset (&o->obuf); }
@@ -36,10 +36,19 @@ static int err(struct merge_options *o, const char *err, ...)va_list params;va_start (params, err); -flush_output (o); +if (o->buffer_output <2 ) +flush_output (o); +else { +strbuf_complete (&o->obuf,'\n' ); +strbuf_addstr (&o->obuf,"error: " ); + }strbuf_vaddf (&o->obuf, err, params); -error ("%s" , o->obuf.buf); -strbuf_reset (&o->obuf); +if (o->buffer_output >1 ) +strbuf_addch (&o->obuf,'\n' ); +else { +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); + }va_end (params);return -1 ;
merge-recursive.h +1 -1
@@ -13,7 +13,7 @@ struct merge_options {MERGE_RECURSIVE_THEIRS } recursive_variant;const char *subtree_shift; - unsigned buffer_output : 1; + unsigned buffer_output : 2; /* 1: output at end, 2: keep buffered */ unsigned renormalize : 1;long xdl_opts;int verbosity;
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Quoted 11 lines · Johannes Schindelin
Since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we already accumulate the output in a buffer. The idea was to avoid interfering with the progress output that goes to stderr, which is unbuffered, when we write to stdout, which is buffered.
We extend that buffering to allow the caller to handle the output (possibly suppressing it). This will help us when extending the sequencer to do rebase -i's brunt work: it does not want the picks to print anything by default but instead determine itself whether to print the output or not.
Quoted 4 lines
Note that we also redirect the error messages into the output buffer when the caller asked not to flush the output buffer, for two reasons:
1) to retain the correct output order, and 2) to allow the caller to suppress *all* output.
I am not yet sure if it makes sense to mix both the regular output and an error into the same buffer for the callers to process (your "reason 1)" above), and this looks like a wrong way to allow a caller that wants no output (your "reason 2)" above). A caller that wants to massage the output would want to know which ones are errors and which ones are not, I would imagine, and setting a knob to make both output() and err() a no-op would be a more suitable way to give a caller a total silence.
At least I cannot yet judge if this is a good change, only from the material presented here. That does not mean I have a concrete reason to say this is a bad change, either. Only from the material presented here, I cannot judge that, either.
Quoted 47 lines
Signed-off-by Johannes Schindelin <[email protected]>--- merge-recursive.c | 17 +++++++++++++---- merge-recursive.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)merge-recursive.c +13
-4@@ -25,7 +25,7 @@static void flush_output (struct merge_options *o) { -if (o->obuf.len) { +if (o->buffer_output <2 && o->obuf.len) {fputs (o->obuf.buf, stdout);strbuf_reset (&o->obuf); }@@ -36,10 +36,19 @@ static int err(struct merge_options *o, const char *err, ...)va_list params;va_start (params, err); -flush_output (o); +if (o->buffer_output <2 ) +flush_output (o); +else { +strbuf_complete (&o->obuf,'\n' ); +strbuf_addstr (&o->obuf,"error: " ); + }strbuf_vaddf (&o->obuf, err, params); -error ("%s" , o->obuf.buf); -strbuf_reset (&o->obuf); +if (o->buffer_output >1 ) +strbuf_addch (&o->obuf,'\n' ); +else { +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); + }va_end (params);return -1 ;merge-recursive.h +0
-0
merge-recursive.h struct merge_options { · line 17
Quoted 6 lines
merge-recursive.h +1
-1@@ -13,7 +13,7 @@ struct merge_options {MERGE_RECURSIVE_THEIRS } recursive_variant;const char *subtree_shift; - unsigned buffer_output : 1; + unsigned buffer_output : 2; /* 1: output at end, 2: keep buffered */ unsigned renormalize : 1;
Once a field ceases to be a boolean, it is OK not to squish it into a bitfield like this for a struct that we will have only a very small number of instances of. Treating it just like "verbosity", which occupies a whole int even though it can only get up to 5 or so, would be more appropriate.
Quoted 2 lines
merge-recursive.h +0
-0long xdl_opts;int verbosity;
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Quoted 8 lines · Junio C Hamano
I am not yet sure if it makes sense to mix both the regular output and an error into the same buffer for the callers to process (your "reason 1)" above), and this looks like a wrong way to allow a caller that wants no output (your "reason 2)" above). A caller that wants to massage the output would want to know which ones are errors and which ones are not, I would imagine, and setting a knob to make both
output()anderr()a no-op would be a more suitable way to give a caller a total silence.
I actually now see how this would work well for "reason 2)". If a caller wants to run the function and wants to pretend as if it did not run anything when it failed, for example, using this to spool all output and error to a strbuf and discard it when the function returns an error, and emit the spooled output to standard output and standard error in the order the lines were collected when the function returns a success, would be a good way to do so.
That however brings me back to the "reason 1" thing. Shouldn't the spooling be done not just with a single strbuf, but with an array of <bool, const char *> tuples, where the bool says if it is for the standard output, and the string holds the message? output() would mark its element in the array with true, while err() would do so with false.
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Hi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Junio C Hamano
I am not yet sure if it makes sense to mix both the regular output and an error into the same buffer for the callers to process (your "reason 1)" above), and this looks like a wrong way to allow a caller that wants no output (your "reason 2)" above). A caller that wants to massage the output would want to know which ones are errors and which ones are not, I would imagine, and setting a knob to make both
output()anderr()a no-op would be a more suitable way to give a caller a total silence.
Quoted 7 lines
I actually now see how this would work well for "reason 2)". If a caller wants to run the function and wants to pretend as if it did not run anything when it failed, for example, using this to spool all output and error to a strbuf and discard it when the function returns an error, and emit the spooled output to standard output and standard error in the order the lines were collected when the function returns a success, would be a good way to do so.
That is actually the exact opposite of the intended usage: when any pick in an interactive rebase succeeds, its output is discarded so as not to bother the user. We show the complete output only when it fails.
Quoted 6 lines
That however brings me back to the "reason 1" thing. Shouldn't the spooling be done not just with a single strbuf, but with an array of <bool, const char *> tuples, where the bool says if it is for the standard output, and the string holds the message?
output()would mark its element in the array with true, whileerr()would do so with false.
I would like to *not* deviate further from my original focus. My willingness to address comments that have little to nothing to do with accelerating the interactive rebase has cost me already over a month, with this patch series alone.
Do not get me wrong: I think you are right in your assessment that a future caller of the recursive merge might need to be able to tell apart which lines of the output are error messages from the rest, and still retain the order.
But then, maybe no future caller will require this.
What is certain: right now, no caller requires it, and neither do my queued-up patches to speed up the interactive rebase.
And another thing is also certain: *iff* a future caller really will require that fine-grained information of the output, then it will be dramatically easier to implement this on top of the patches we are discussing right now.
In short: I hope you agree with me that it is safe to defer the <bool, const char*> tuple implementation to the time when we will *actually* need it.
Ciao,
Dscho
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Quoted 11 lines · Johannes Schindelin
Quoted 7 lines
I actually now see how this would work well for "reason 2)". If a caller wants to run the function and wants to pretend as if it did not run anything when it failed, for example, using this to spool all output and error to a strbuf and discard it when the function returns an error, and emit the spooled output to standard output and standard error in the order the lines were collected when the function returns a success, would be a good way to do so.
That is actually the exact opposite of the intended usage: when any
pickin an interactive rebase succeeds, its output is discarded so as not to bother the user. We show the complete output only when it fails.
Oh, it makes sense, too, to show the output only when there is an error.
But in that case, there would be both messages meant for the standard output and also meant for the standard error, and we need some way to make sure they go to the right channel.
I however do not think an array of <bool, const char *> is the only way to achieve that. We can get away by a single strbuf that accumulates all output() that we have seen so far, i.e. "we only accumulate output() and ignore flush() as long as what we see are only from output()" mode.
Then the err() routine operating under this new mode can show what has been accumulated to the standard output (because with this tweak I am outlining here, by definition, the strbuf will only keep the output() material and not err() things), show the err() message, and switch back to the normal "we accumulate output() and honor flush()" mode. Of course, when we are doing multiple rounds, the mode must be reset to "accumulate output and ignore flush" mode at the beginning of each rouhd.
That would give us "silence if there is no error, but if we are showing error, show them to the standard error, while giving non-error message to the standard output".
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Hi Junio,
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Johannes Schindelin
Quoted 7 lines
I actually now see how this would work well for "reason 2)". If a caller wants to run the function and wants to pretend as if it did not run anything when it failed, for example, using this to spool all output and error to a strbuf and discard it when the function returns an error, and emit the spooled output to standard output and standard error in the order the lines were collected when the function returns a success, would be a good way to do so.
Quoted 6 lines
Quoted 4 lines
That is actually the exact opposite of the intended usage: when any
pickin an interactive rebase succeeds, its output is discarded so as not to bother the user. We show the complete output only when it fails.Oh, it makes sense, too, to show the output only when there is an error.
Thanks ;-)
Quoted 3 lines
But in that case, there would be both messages meant for the standard output and also meant for the standard error, and we need some way to make sure they go to the right channel.
Not necessarily. Let's have a look at our existing code in git-rebase.sh:
output () {
case "$verbose" in
'')
output=$("$@" 2>&1 )
status=$?
test $status != 0 && printf "%s\n" "$output"
return $status
;;
*)
"$@"
;;
esac
}This incredibly well-named function (</sarcasm>, my fault: dfa49f3 (Shut "git rebase -i" up when no --verbose was given, 2007-07-23)) accumulates all output, both stdout and stderr, and shows it only in case of an error.
Crucially, *all* output goes to stdout. No distinction is being made between stdout and stderr.
This is the existing behavior of rebase -i.
Quoted 15 lines
I however do not think an array of <bool, const char *> is the only way to achieve that. We can get away by a single strbuf that accumulates all
output()that we have seen so far, i.e. "we only accumulateoutput()and ignoreflush()as long as what we see are only fromoutput()" mode.Then the
err()routine operating under this new mode can show what has been accumulated to the standard output (because with this tweak I am outlining here, by definition, the strbuf will only keep theoutput()material and noterr()things), show theerr()message, and switch back to the normal "we accumulateoutput()and honorflush()" mode. Of course, when we are doing multiple rounds, the mode must be reset to "accumulate output and ignore flush" mode at the beginning of each rouhd.
Quoted 3 lines
That would give us "silence if there is no error, but if we are showing error, show them to the standard error, while giving non-error message to the standard output".
It all makes sense what you say. In case you want to preserve the channel in some future modification.
However, I am right now most concerned about keeping existing behavior as faithfully as possible (with the exception of execution speed, which I want to improve dramatically).
As such, it would be a serious mistake to implement that mode and use it in the rebase--helper: it would very likely cause regressions in existing scripts, probably even my own.
So I do understand your concern, and I agree that it would make for a fine design, in a different context than this patch series.
Ciao,
Dscho
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
Quoted 28 lines · Johannes Schindelin
Quoted 3 lines
But in that case, there would be both messages meant for the standard output and also meant for the standard error, and we need some way to make sure they go to the right channel.
Not necessarily. Let's have a look at our existing code in
git-rebase.sh:output () { case "$verbose" in '') output=$("$@" 2>&1 ) status=$? test $status != 0 && printf "%s\n" "$output" return $status ;; *) "$@" ;; esac }This incredibly well-named function (</sarcasm>, my fault: dfa49f3 (Shut "git rebase -i" up when no --verbose was given, 2007-07-23)) accumulates all output, both stdout and stderr, and shows it only in case of an error.
Crucially, *all* output goes to stdout. No distinction is being made between stdout and stderr.
Quoted 6 lines
...
This is the existing behavior of rebase -i.
...
As such, it would be a serious mistake to implement that mode and use it in the rebase--helper: it would very likely cause regressions in existing scripts, probably even my own.
Sounds like we are desperately trying to find an excuse to do a wrong thing by finding an existing piece of code that did a wrong thing already.
That leaves a bad taste in my mouth, but as "rebase -i" is meant to be an "interactive" command, I would imagine that nobody would have expected to run it as "git rebase -i >/dev/null" in order to view only the error messages (or vice versa with "2>errs").
So OK then, at least for now.
Re: [PATCH v5 14/16] merge-recursive: offer an option to retain the output in 'obuf'
In reply to Junio C HamanoHi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Johannes Schindelin
merge-recursive.h +0
-1@@ -13,7 +13,7 @@ struct merge_options { MERGE_RECURSIVE_THEIRS } recursive_variant;const char *subtree_shift; - unsigned buffer_output : 1;
Quoted 8 lines
merge-recursive.h struct merge_options { · line 17
Quoted 2 lines
merge-recursive.h +1
-0+ unsigned buffer_output : 2; /* 1: output at end, 2: keep buffered */ unsigned renormalize : 1;Once a field ceases to be a boolean, it is OK not to squish it into a bitfield like this for a struct that we will have only a very small number of instances of. Treating it just like "verbosity", which occupies a whole int even though it can only get up to 5 or so, would be more appropriate.
I changed it to an int.
Thanks,
Dscho
PATCH v5 15/16 Ensure that the output buffer is released after calling merge_trees()
In reply to Johannes SchindelinThe recursive merge machinery accumulates its output in an output buffer, to be flushed at the end of merge_recursive(). At this point, we forgot to release the output buffer.
When calling merge_trees() (i.e. the non-recursive part of the recursive merge) directly, the output buffer is never flushed because the caller may be merge_recursive() which wants to flush the output itself.
For the same reason, merge_trees() cannot release the output buffer: it may still be needed.
Forgetting to release the output buffer did not matter much when running git-checkout, or git-merge-recursive, because we exited after the operation anyway. Ever since cherry-pick learned to pick a commit range, however, this memory leak had the potential of becoming a problem.
--- builtin/checkout.c | 1 + merge-recursive.c | 2 ++ sequencer.c | 1 + 3 files changed, 4 insertions(+)
builtin/checkout.c +1 -0
@@ -573,6 +573,7 @@ static int merge_working_tree(const struct checkout_opts *opts,exit (128 ); ret =reset_tree (new->commit->tree, opts,0 , writeout_error); +strbuf_release (&o.obuf);if (ret)return ret; }
merge-recursive.c +2 -0
@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (o->buffer_output <2 ) +strbuf_release (&o->obuf);if (show (o,2 ))diff_warn_rename_limit ("merge.renamelimit" , o->needed_rename_limit,0 );
sequencer.c +1 -0
@@ -293,6 +293,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean =merge_trees (&o, head_tree, next_tree, base_tree, &result); +strbuf_release (&o.obuf);if (clean <0 )return clean;
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v5 15/16] Ensure that the output buffer is released after calling merge_trees()
merge-recursive.c int merge_recursive(struct merge_options *o, · line 2085
Quoted 13 lines · Johannes Schindelin
merge-recursive.c +2
-0@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (o->buffer_output <2 ) +strbuf_release (&o->obuf);if (show (o,2 ))diff_warn_rename_limit ("merge.renamelimit" , o->needed_rename_limit,0 );
Other two hunks looked good, but this one I am not sure what is going on. It this were "if call-depth says we are called by another merge_recursive, do not discard the buffer", I would understand, but why does this have to be tied to o->buffer_output being "we buffer the output but not errors"?
Re: [PATCH v5 15/16] Ensure that the output buffer is released after calling merge_trees()
Hi Junio,
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Johannes Schindelin
merge-recursive.c +2
-0@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (o->buffer_output <2 ) +strbuf_release (&o->obuf);if (show (o,2 ))
Quoted 8 lines
merge-recursive.c int merge_recursive(struct merge_options *o, · line 2085
Quoted 2 lines
merge-recursive.c +0
-0diff_warn_rename_limit ("merge.renamelimit" , o->needed_rename_limit,0 );Other two hunks looked good, but this one I am not sure what is going on. It this were "if call-depth says we are called by another
merge_recursive, do not discard the buffer", I would understand, but why does this have to be tied too->buffer_outputbeing "we buffer the output but not errors"?
Good point. I changed it to test for !o->call_depth in addition.
We must not release the output buffer here if buffer_output >= 2: the level "2" of the buffer_output field says that the caller of the recursive merge expects the output to remain in the buffer until after merge_recursive() returns.
Ciao,
Dscho
PATCH v5 16/16 merge-recursive: flush output buffer even when erroring out
In reply to Johannes SchindelinEver since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we had a problem: When the merge failed in a fatal way, all regular output was swallowed because we called die() and did not get a chance to drain the output buffers.
To fix this, several modifications were necessary:
- we needed to stop die()ing, to give callers a chance to do something when an error occurred (in this case, flush the output buffers),
- we needed to delay printing the error message so that the caller can print the buffered output before that, and
- we needed to make sure that the output buffers are flushed even when the return value indicates an error.
The first two changes were introduced through earlier commits in this patch series, and this commit addresses the third one.
--- merge-recursive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-recursive.c +1 -1
@@ -2069,6 +2069,7 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +flush_output (o);if (clean <0 )return clean;
@@ -2077,7 +2078,6 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h1, &(*result)->parents);commit_list_insert (h2, &(*result)->parents->next); } -flush_output (o);if (o->buffer_output <2 )strbuf_release (&o->obuf);if (show (o,2 ))
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v5 16/16] merge-recursive: flush output buffer even when erroring out
merge-recursive.c int merge_recursive(struct merge_options *o, · line 2074
Quoted 11 lines · Johannes Schindelin
merge-recursive.c +1
-0@@ -2069,6 +2069,7 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +flush_output (o);if (clean <0 )return clean;
This is of course a good change, but we need to assume that no further output is made from the remainder of the function for the change in the next hunk to remove the existing flush to be correct.
And once we assume that, then the "we no longer need this buffer, so release it" added in 15/16 can also move here, right?
I am wondering if there is a low-impact way to make sure that assumption will not be broken.
Quoted 8 lines
merge-recursive.c +0
-1@@ -2077,7 +2078,6 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h1, &(*result)->parents);commit_list_insert (h2, &(*result)->parents->next); } -flush_output (o);if (o->buffer_output <2 )strbuf_release (&o->obuf);if (show (o,2 ))
Re: [PATCH v5 16/16] merge-recursive: flush output buffer even when erroring out
Hi Junio,
Quoted 17 lines · Junio C Hamano
merge-recursive.c int merge_recursive(struct merge_options *o, · line 2074
Quoted 11 lines · Johannes Schindelin
merge-recursive.c +1
-0@@ -2069,6 +2069,7 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +flush_output (o);if (clean <0 )return clean;This is of course a good change, but we need to assume that no further output is made from the remainder of the function for the change in the next hunk to remove the existing flush to be correct.
Please note that nothing prevents the code further down from adding more output. All we do here is flushing the output *so far*, in case we return an error. And of course nothing gets flushed if buffer_output == 2, because that value states that the caller wants to take care of displaying the output herself.
But you made me realize that I cannot simply *move* the flush_output() call here, in case that code in between will eventually add output.
Thanks,
Dscho
Re: [PATCH v5 16/16] merge-recursive: flush output buffer even when erroring out
Quoted 6 lines · Johannes Schindelin
Quoted 3 lines
This is of course a good change, but we need to assume that no further output is made from the remainder of the function for the change in the next hunk to remove the existing flush to be correct.
...
But you made me realize that I cannot simply *move* theflush_output()call here, in case that code in between will eventually add output.
Yup, that removal of the original one was the only thing I was pointing out.
v6 cover Use merge_recursive() directly in the builtin am
In reply to Johannes SchindelinThis is the sixth iteration of the long-awaited re-roll of the attempt to avoid spawning merge-recursive from the builtin am and use merge_recursive() directly instead.
The *real* reason for the reroll is that I need a libified recursive merge to accelerate the interactive rebase by teaching the sequencer to do rebase -i's grunt work. Coming with a very nice 3x-5x speedup of rebase -i.
In this endeavor, we need to be extra careful to retain backwards compatibility. The test script t6022-merge-rename.sh, for example, verifies that git pull exits with status 128 in case of a fatal error. To that end, we need to make sure that fatal errors are handled by existing (builtin) users via exit(128) (or die(), which calls exit(128) at the end). New users (such as a builtin helper doing rebase -i's grunt work) may want to print some helpful advice what happened and how to get out of this mess before erroring out.
The changes relative to the fifth iteration of this patch series:
- the commit message that talked about swallowing messages was improved
- the va_start()/va_end() statements were moved closer to the vararg usage
- the buffer_output field is no longer a bit field because it is now logically more like the verbosity level, which we traditionally keep as a full int
- the flush_output() call is no longer moved, but instead added to the code path when we return early
- the commit message saying that we speculated about stdout's buffer size now instead states that we made an assumption
This patch series touches rather important code. I appreciate thorough reviews with a focus on the critical parts of the code, those that could result in regressions.
Johannes Schindelin (16):
t5520: verify that pull --rebase shows the helpful advice when
failing
Report bugs consistently
Avoid translating bug messages
merge-recursive: clarify code in was_tracked()
Prepare the builtins for a libified merge_recursive()
merge_recursive: abort properly upon errors
merge-recursive: avoid returning a wholesale struct
merge-recursive: allow write_tree_from_memory() to error out
merge-recursive: handle return values indicating errors
merge-recursive: switch to returning errors instead of dying am -3: use merge_recursive() directly again
merge-recursive: flush output buffer before printing error messages
merge-recursive: write the commit title in one go
merge-recursive: offer an option to retain the output in 'obuf' Ensure that the output buffer is released after calling merge_trees()
merge-recursive: flush output buffer even when erroring out
builtin/am.c | 62 ++---- builtin/checkout.c | 5 +- builtin/ls-files.c | 3 +- builtin/merge.c | 2 + builtin/update-index.c | 2 +- grep.c | 8 +- imap-send.c | 2 +- merge-recursive.c | 578 +++++++++++++++++++++++++++++-------------------- merge-recursive.h | 2 +- sequencer.c | 5 + sha1_file.c | 4 +- t/t5520-pull.sh | 32 +++ trailer.c | 2 +- transport.c | 2 +- wt-status.c | 4 +- 15 files changed, 419 insertions(+), 294 deletions(-)
Published-As: https://github.com/dscho/git/releases/tag/am-3-merge-recursive-direct-v6
Interdiff vs v5:
diff --git a/merge-recursive.c b/merge-recursive.c
index 66e93e0..c9e4dbc 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -35,21 +35,21 @@ static int err(struct merge_options *o, const char *err, ...)
{
va_list params;
- va_start(params, err);
if (o->buffer_output < 2)
flush_output(o);
else {
strbuf_complete(&o->obuf, '\n'); strbuf_addstr(&o->obuf, "error: ");
}
+ va_start(params, err);
strbuf_vaddf(&o->obuf, err, params);
+ va_end(params);
if (o->buffer_output > 1)
strbuf_addch(&o->obuf, '\n');
else {
error("%s", o->obuf.buf); strbuf_reset(&o->obuf);
}
- va_end(params);
return -1;
}
@@ -2069,16 +2069,18 @@ int merge_recursive(struct merge_options *o,
o->ancestor = "merged common ancestors";
clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
&mrtree);
- flush_output(o);
- if (clean < 0)
+ if (clean < 0) {
+ flush_output(o);
return clean;
+ }
if (o->call_depth) {
*result = make_virtual_commit(mrtree, "merged tree"); commit_list_insert(h1, &(*result)->parents); commit_list_insert(h2, &(*result)->parents->next);
}
- if (o->buffer_output < 2)
+ flush_output(o);
+ if (!o->call_depth && o->buffer_output < 2)
strbuf_release(&o->obuf);
if (show(o, 2))
diff_warn_rename_limit("merge.renamelimit",
diff --git a/merge-recursive.h b/merge-recursive.h
index 340704c..735343b 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -13,7 +13,7 @@ struct merge_options {
MERGE_RECURSIVE_THEIRS
} recursive_variant;
const char *subtree_shift;
- unsigned buffer_output : 2; /* 1: output at end, 2: keep buffered */
+ unsigned buffer_output; /* 1: output at end, 2: keep buffered */
unsigned renormalize : 1;
long xdl_opts;
int verbosity;
Signature · 3 lines
2.9.0.281.g286a8d9 base-commit: f8f7adce9fc50a11a764d57815602dcb818d1816
PATCH v6 1/16 t5520: verify that `pull --rebase` shows the helpful advice when failing
It was noticed by Brendan Forster last October that the builtin git am regressed on that. Our hot fix reverted to spawning the recursive merge instead of using it as a library function.
As we are about to revert that hot fix, after making the recursive merge a true library function (i.e. a function that does not die() in case of "normal" errors), let's add a test that verifies that we do not regress on the same problem which made the hot fix necessary in the first place.
--- t/t5520-pull.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
t/t5520-pull.sh +32 -0
@@ -255,6 +255,38 @@ test_expect_success '--rebase' ' test new = "$(git show HEAD:file2)" ' +test_expect_success '--rebase with conflicts shows advice' ' + test_when_finished "git rebase --abort; git checkout -f to-rebase" && + git checkout -b seq && + test_seq 5 >seq.txt && + git add seq.txt && + test_tick && + git commit -m "Add seq.txt" && + echo 6 >>seq.txt && + test_tick && + git commit -m "Append to seq.txt" seq.txt && + git checkout -b with-conflicts HEAD^ && + echo conflicting >>seq.txt && + test_tick && + git commit -m "Create conflict" seq.txt && + test_must_fail git pull --rebase . seq 2>err >out && + grep "When you have resolved this problem" out +' + +test_expect_success 'failed --rebase shows advice' ' + test_when_finished "git rebase --abort; git checkout -f to-rebase" && + git checkout -b diverging && + test_commit attributes .gitattributes "* text=auto" attrs && + sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" && + git update-index --cacheinfo 0644 $sha1 file && + git commit -m v1-with-cr && + # force checkout because `git reset --hard` will not leave clean `file` + git checkout -f -b fails-to-rebase HEAD^ && + test_commit v2-without-cr file "2" file2-lf && + test_must_fail git pull --rebase . diverging 2>err >out && + grep "When you have resolved this problem" out +' + test_expect_success '--rebase fails with multiple branches' ' git reset --hard before-rebase && test_must_fail git pull --rebase . copy master 2>err &&
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 2/16 Report bugs consistently
In reply to Johannes SchindelinThe vast majority of error messages in Git's source code which report a bug use the convention to prefix the message with "BUG:".
As part of cleaning up merge-recursive to stop die()ing except in case of detected bugs, let's just make the remainder of the bug reports consistent with the de facto rule.
--- builtin/ls-files.c | 3 ++- builtin/update-index.c | 2 +- grep.c | 8 ++++---- imap-send.c | 2 +- merge-recursive.c | 15 +++++++-------- sha1_file.c | 4 ++-- trailer.c | 2 +- transport.c | 2 +- wt-status.c | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-)
builtin/ls-files.c +2 -1
@@ -118,7 +118,8 @@ static void show_killed_files(struct dir_struct *dir)*/ pos =cache_name_pos (ent->name, ent->len);if (0 <= pos) -die ("bug in show-killed-files" ); +die ("BUG: killed-file %.*s not found" , + ent->len, ent->name); pos = -pos -1 ;while (pos < active_nr &&ce_stage (active_cache[pos]))
builtin/update-index.c +1 -1
@@ -1146,7 +1146,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)report (_ ("Untracked cache enabled for '%s'" ),get_git_work_tree ());break ;default : -die ("Bug: bad untracked_cache value: %d" , untracked_cache); +die ("BUG: bad untracked_cache value: %d" , untracked_cache); }if (active_cache_changed) {
grep.c +4 -4
@@ -693,10 +693,10 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)for (p = opt->header_list; p; p = p->next) {if (p->token !=GREP_PATTERN_HEAD ) -die ("bug: a non-header pattern in grep header list." ); +die ("BUG: a non-header pattern in grep header list." );if (p->field <GREP_HEADER_FIELD_MIN ||GREP_HEADER_FIELD_MAX <= p->field) -die ("bug: unknown header field %d" , p->field); +die ("BUG: unknown header field %d" , p->field);compile_regexp (p, opt); }
@@ -709,7 +709,7 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt) h =compile_pattern_atom (&pp);if (!h || pp != p->next) -die ("bug: malformed header expr" ); +die ("BUG: malformed header expr" );if (!header_group[p->field]) { header_group[p->field] = h;continue ;
@@ -1514,7 +1514,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int collecase GREP_BINARY_TEXT :break ;default : -die ("bug: unknown binary handling mode" ); +die ("BUG: unknown binary handling mode" ); } }
imap-send.c +1 -1
@@ -511,7 +511,7 @@ static int nfsnprintf(char *buf, int blen, const char *fmt, ...)va_start (va, fmt);if (blen <=0 || (unsigned )(ret =vsnprintf (buf, blen, fmt, va)) >= (unsigned )blen) -die ("Fatal: buffer too small. Please report a bug." ); +die ("BUG: buffer too small. Please report a bug." );va_end (va);return ret; }
merge-recursive.c +7 -8
@@ -268,7 +268,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)fprintf (stderr,"BUG: %d %.*s\n" ,ce_stage (ce), (int )ce_namelen (ce), ce->name); } -die ("Bug in merge-recursive.c" ); +die ("BUG: unmerged index entries in merge-recursive.c" ); }if (!active_cache_tree)
@@ -966,9 +966,8 @@ static struct merge_file_info merge_file_1(struct merge_options *o,if (!oid_eq (&a->oid, &b->oid)) result.clean =0 ; - }else { -die (_ ("unsupported object type in the tree" )); - } + }else +die (_ ("BUG: unsupported object type in the tree" )); }return result;
@@ -1354,7 +1353,7 @@ static int process_renames(struct merge_options *o,const char *ren2_dst = ren2->pair->two->path;enum rename_type rename_type;if (strcmp (ren1_src, ren2_src) !=0 ) -die ("ren1_src != ren2_src" ); +die ("BUG: ren1_src != ren2_src" ); ren2->dst_entry->processed =1 ; ren2->processed =1 ;if (strcmp (ren1_dst, ren2_dst) !=0 ) {
@@ -1388,7 +1387,7 @@ static int process_renames(struct merge_options *o, ren2 = lookup->util; ren2_dst = ren2->pair->two->path;if (strcmp (ren1_dst, ren2_dst) !=0 ) -die ("ren1_dst != ren2_dst" ); +die ("BUG: ren1_dst != ren2_dst" ); clean_merge =0 ; ren2->processed =1 ;
@@ -1812,7 +1811,7 @@ static int process_entry(struct merge_options *o,*/ remove_file (o,1 , path, !a_mode); }else -die (_ ("Fatal merge failure, shouldn't happen." )); +die (_ ("BUG: fatal merge failure, shouldn't happen." ));return clean_merge; }
@@ -1870,7 +1869,7 @@ int merge_trees(struct merge_options *o,for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;if (!e->processed) -die (_ ("Unprocessed path??? %s" ), +die (_ ("BUG: unprocessed path??? %s" ), entries->items[i].string); }
sha1_file.c +2 -2
@@ -795,7 +795,7 @@ void close_all_packs(void)for (p = packed_git; p; p = p->next)if (p->do_not_close) -die ("BUG! Want to close pack marked 'do-not-close'" ); +die ("BUG: want to close pack marked 'do-not-close'" );else close_pack (p); }
@@ -2330,7 +2330,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,case OBJ_OFS_DELTA :case OBJ_REF_DELTA :if (data) -die ("BUG in unpack_entry: left loop at a valid delta" ); +die ("BUG: unpack_entry: left loop at a valid delta" );break ;case OBJ_COMMIT :case OBJ_TREE :
trailer.c +1 -1
@@ -562,7 +562,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)warning (_ ("unknown value '%s' for key '%s'" ), value, conf_key);break ;default : -die ("internal bug in trailer.c" ); +die ("BUG: trailer.c: unhandled type %d" , type); }return 0 ; }
transport.c +1 -1
@@ -566,7 +566,7 @@ void transport_take_over(struct transport *transport,struct git_transport_data *data;if (!transport->smart_options) -die ("Bug detected: Taking over transport requires non-NULL " +die ("BUG: taking over transport requires non-NULL " "smart_options field." ); data =xcalloc (1 ,sizeof (*data));
wt-status.c +2 -2
@@ -263,7 +263,7 @@ static const char *wt_status_unmerged_status_string(int stagemask)case 7 :return _ ("both modified:" );default : -die ("bug: unhandled unmerged status %x" , stagemask); +die ("BUG: unhandled unmerged status %x" , stagemask); } }
@@ -388,7 +388,7 @@ static void wt_status_print_change_data(struct wt_status *s,status_printf (s,color (WT_STATUS_HEADER , s),"\t" ); what =wt_status_diff_status_string (status);if (!what) -die ("bug: unhandled diff status %c" , status); +die ("BUG: unhandled diff status %c" , status); len = label_width -utf8_strwidth (what);assert (len >=0 );if (status ==DIFF_STATUS_COPIED || status ==DIFF_STATUS_RENAMED )
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 3/16 Avoid translating bug messages
In reply to Johannes SchindelinWhile working on the patch series that avoids die()ing in recursive merges, the issue came up that bug reports (i.e. die("BUG: ...") constructs) should never be translated, as the target audience is the Git developer community, not necessarily the current user, and hence a translated message would make it *harder* to address the problem.
So let's stop translating the obvious ones. As it is really, really outside the purview of this patch series to see whether there are more die() statements that report bugs and are currently translated, that task is left for another day and patch.
--- merge-recursive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
merge-recursive.c +3 -3
@@ -967,7 +967,7 @@ static struct merge_file_info merge_file_1(struct merge_options *o,if (!oid_eq (&a->oid, &b->oid)) result.clean =0 ; }else -die (_ ("BUG: unsupported object type in the tree" )); +die ("BUG: unsupported object type in the tree" ); }return result;
@@ -1811,7 +1811,7 @@ static int process_entry(struct merge_options *o,*/ remove_file (o,1 , path, !a_mode); }else -die (_ ("BUG: fatal merge failure, shouldn't happen." )); +die ("BUG: fatal merge failure, shouldn't happen." );return clean_merge; }
@@ -1869,7 +1869,7 @@ int merge_trees(struct merge_options *o,for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;if (!e->processed) -die (_ ("BUG: unprocessed path??? %s" ), +die ("BUG: unprocessed path??? %s" , entries->items[i].string); }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 4/16 merge-recursive: clarify code in was_tracked()
In reply to Johannes SchindelinIt can be puzzling to see that was_tracked() asks to get an index entry by name, but does not take a negative return value for an answer.
The reason we have to do this is that cache_name_pos() only looks for entries in stage 0, even if nobody asked for any stage in particular.
Let's rewrite the logic a little bit, to handle the easy case early: if cache_name_pos() returned a non-negative position, we know it is a match, and we do not even have to compare the name again (cache_name_pos() did that for us already). We can say right away: yes, this file was tracked.
Only if there was no exact match do we need to look harder for any matching entry in stage 2.
--- merge-recursive.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
merge-recursive.c +14 -16
@@ -667,23 +667,21 @@ static int was_tracked(const char *path) {int pos =cache_name_pos (path,strlen (path)); -if (pos <0 ) - pos =-1 - pos; -while (pos < active_nr && - !strcmp (path, active_cache[pos]->name)) { -/* -* If stage #0, it is definitely tracked. -* If it has stage #2 then it was tracked -* before this merge started. All other -* cases the path was not tracked. -*/ -switch (ce_stage (active_cache[pos])) { -case 0 : -case 2 : +if (0 <= pos) +/* we have been tracking this path */ +return 1 ; + +/* +* Look for an unmerged entry for the path, +* specifically stage #2, which would indicate +* that "our" side before the merge started +* had the path tracked (and resulted in a conflict). +*/ +for (pos =-1 - pos; + pos < active_nr && !strcmp (path, active_cache[pos]->name); + pos++) +if (ce_stage (active_cache[pos]) ==2 )return 1 ; - } - pos++; - }return 0 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 5/16 Prepare the builtins for a libified merge_recursive()
In reply to Johannes SchindelinPreviously, callers of merge_trees() or merge_recursive() expected that code to die() with an error message. This used to be okay because we called those commands from scripts, and had a chance to print out a message in case the command failed fatally (read: with exit code 128).
As scripting incurs its own set of problems (portability, speed, idiosynchracies of different shells, limited data structures leading to inefficient code), we are converting more and more of these scripts into builtins, using library functions directly.
We already tried to use merge_recursive() directly in the builtin git-am, for example. Unfortunately, we had to roll it back temporarily because some of the code in merge-recursive.c still deemed it okay to call die(), when the builtin am code really wanted to print out a useful advice after the merge failed fatally. In the next commits, we want to fix that.
The code touched by this commit expected merge_trees() to die() with some useful message when there is an error condition, but merge_trees() is going to be improved by converting all die() calls to return error() instead (i.e. return value -1 after printing out the message as before), so that the caller can react more flexibly.
This is a step to prepare for the version of merge_trees() that no longer dies, even if we just imitate the previous behavior by calling exit(128): this is what callers of e.g. git merge have come to expect.
Note that the callers of the sequencer (revert and cherry-pick) already fail fast even for the return value -1; The only difference is that they now get a chance to say "<command> failed".
A caller of merge_trees() might want handle error messages themselves (or even suppress them). As this patch is already complex enough, we leave that change for a later patch.
--- builtin/checkout.c | 4 +++- builtin/merge.c | 2 ++ sequencer.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
builtin/checkout.c +3 -1
@@ -567,8 +567,10 @@ static int merge_working_tree(const struct checkout_opts *opts, o.ancestor = old->name; o.branch1 = new->name; o.branch2 ="local" ; -merge_trees (&o, new->commit->tree, work, + ret =merge_trees (&o, new->commit->tree, work, old->commit->tree, &result); +if (ret <0 ) +exit (128 ); ret =reset_tree (new->commit->tree, opts,0 , writeout_error);if (ret)
builtin/merge.c +2 -0
@@ -673,6 +673,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,hold_locked_index (&lock,1 ); clean =merge_recursive (&o, head, remoteheads->item, reversed, &result); +if (clean <0 ) +exit (128 );if (active_cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))die (_ ("unable to write %s" ),get_index_file ());
sequencer.c +4 -0
@@ -293,6 +293,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean =merge_trees (&o, head_tree, next_tree, base_tree, &result); +if (clean <0 ) +return clean;if (active_cache_changed &&write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))
@@ -559,6 +561,8 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)if (!opts->strategy || !strcmp (opts->strategy,"recursive" ) || opts->action ==REPLAY_REVERT ) { res =do_recursive_merge (base, next, base_label, next_label, head, &msgbuf, opts); +if (res <0 ) +return res;write_message (&msgbuf,git_path_merge_msg ()); }else {struct commit_list *common =NULL ;
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 05/16] Prepare the builtins for a libified merge_recursive()
Quoted 7 lines · Johannes Schindelin
Previously, callers of
merge_trees()ormerge_recursive()expected that code todie()with an error message. This used to be okay because we called those commands from scripts, and had a chance to print out a message in case the command failed fatally (read: with exit code 128).As scripting incurs its own set of problems (portability, speed, idiosynchracies of different shells, limited data structures leading to
I think I typofixed this when I queued the previous one on 'pu' already, but s/synch/sync/;
Re: [PATCH v6 05/16] Prepare the builtins for a libified merge_recursive()
Hi Junio,
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin
Previously, callers of
merge_trees()ormerge_recursive()expected that code todie()with an error message. This used to be okay because we called those commands from scripts, and had a chance to print out a message in case the command failed fatally (read: with exit code 128).
Quoted 5 lines
Quoted 2 lines
As scripting incurs its own set of problems (portability, speed, idiosynchracies of different shells, limited data structures leading to
I think I typofixed this when I queued the previous one on 'pu' already, but s/synch/sync/;
Whoops. Fixed locally.
Ciao,
Dscho
PATCH v6 6/16 merge_recursive: abort properly upon errors
In reply to Johannes SchindelinThere are a couple of places where return values never indicated errors before, as wie simply died instead of returning.
But now negative return values mean that there was an error and we have to abort the operation. Let's do exactly that.
--- merge-recursive.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
merge-recursive.c +12 -5
@@ -1949,17 +1949,19 @@ int merge_recursive(struct merge_options *o,/* * When the merge fails, the result contains files * with conflict markers. The cleanness flag is -* ignored, it was never actually used, as result of -* merge_trees has always overwritten it: the committed -* "conflicts" were already resolved. +* ignored (unless indicating an error), it was never +* actually used, as result of merge_trees has always +* overwritten it: the committed "conflicts" were +* already resolved. */ discard_cache (); saved_b1 = o->branch1; saved_b2 = o->branch2; o->branch1 ="Temporary merge branch 1" ; o->branch2 ="Temporary merge branch 2" ; -merge_recursive (o, merged_common_ancestors, iter->item, -NULL , &merged_common_ancestors); +if (merge_recursive (o, merged_common_ancestors, iter->item, +NULL , &merged_common_ancestors) <0 ) +return -1 ; o->branch1 = saved_b1; o->branch2 = saved_b2; o->call_depth--;
@@ -1975,6 +1977,8 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); +if (clean <0 ) +return clean;if (o->call_depth) { *result =make_virtual_commit (mrtree,"merged tree" );
@@ -2031,6 +2035,9 @@ int merge_recursive_generic(struct merge_options *o,hold_locked_index (lock,1 ); clean =merge_recursive (o, head_commit, next_commit, ca, result); +if (clean <0 ) +return clean; +if (active_cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 1 line · Johannes Schindelin
Subject: Re: [PATCH v6 06/16]
merge_recursive: abort properly upon errors
s/merge_/merge-/; for this one alone.
Quoted 2 lines
There are a couple of places where return values never indicated errors before, as wie simply died instead of returning.
s/wie/we/;
Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Junio,
Quoted 5 lines · Junio C Hamano
Quoted 1 line · Johannes Schindelin
Subject: Re: [PATCH v6 06/16]
merge_recursive: abort properly upon errorss/merge_/merge-/; for this one alone.
I see that de8946de1694a8cf311daab7b2c416d76cb04d23 still shows it with an underscore instead of a dash, while you fixed my other tyops in this patch series.
I tend to think that the underscore is correct: this change is not so much about the builtin (which is written with a dash) but about the function (written with an underscore, used by more than just merge-recursive, e.g. cherry-pick).
Quoted 4 lines
Quoted 2 lines
There are a couple of places where return values never indicated errors before, as wie simply died instead of returning.
s/wie/we/;
Right. What can I say, I am surrounded by too many Germans.
I fixed this locally, in case another re-roll should be required. What you have in pu looks correct to me, though. Let me know if you want me to re-submit nevertheless.
BTW I should have said this earlier: I run all my rebases, all my merges, all my cherry-picks using a Git version with these patches for months (of course, the patches have changed, but not in the most critical parts I was concerned about, the parts where die() calls were replaced). If I would have found any regression, I would have notified you immediately, of course.
Ciao,
Dscho
Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 10 lines · Johannes Schindelin
Quoted 4 lines
Quoted 2 lines
There are a couple of places where return values never indicated errors before, as wie simply died instead of returning.
s/wie/we/;
Right. What can I say, I am surrounded by too many Germans.
I fixed this locally, in case another re-roll should be required. What you have in
pulooks correct to me, though. Let me know if you want me to re-submit nevertheless.
I usually do this kind of obvious typofix and consistency fix without even mentioning them in my review comments to reduce the noise levels. But that works better ONLY if the patch authors then fetch from 'pu' and replace their copies with what I fixed up already and base their reroll on top by amending and/or building on top (of course, that also requires my local fix must all be limited to uncontroversial ones).
So either I should change my workflow and mention any and all typofixes in my review comments (which consumes the review bandwidth), or I should force patch authors to do the "fetch from 'pu' and replace" somehow to avoid this kind of back-and-forth.
I am not sure which should be the way to go.
patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Junio,
Quoted 4 lines · Junio C Hamano
So either I should change my workflow and mention any and all typofixes in my review comments (which consumes the review bandwidth), or I should force patch authors to do the "fetch from 'pu' and replace" somehow to avoid this kind of back-and-forth.
It never occurred to me that I should replace any of my local branches with versions you have in pu. For several reasons:
- just as you do not pull from me, lest patches enter your repository that you have not reviewed, I do not simply pull from you,
- I thought the point of avoiding GitHub in the review process at all costs and require everybody to go via the mailing list instead was to keep the review process open? These silent changes fly in the face of that,
- I agree that the mail-based process is cumbersome and error-prone, but we won't fix it by asking contributors to dig through the pu of the day, somehow stay up-to-date with possibly more silent typofixes the next day, somehow manage to figure out what changes exactly were introduced to their patches, and replace their local work.
- even if we asked for all that trouble, the commits in pu are all signed off by you. These sign-offs would have to be stripped out tediously when making local changes.
In short, I agree that our patch submission process is a saber tooth tiger that still reflects pre-Git times. While we use Git's tools, the workflow really tries to cut out Git as much as possible, in favor of pure mails with non-corrupted, non-HTML patches in them, a charmingly anachronistic requirement until you try to use state-of-the-art mail clients to send them.
I disagree, however, with the suggestion to sift through your pu branch and to somehow replace local branches with the commits found there.
I guess it is time to revisit our patch submission process if it does not even work between the two of us.
Ideally, we would come up with a process that
- makes everything easier for maintainers and contributors alike,
- tracks the history of the patch iterations (answering the question "what changed between iterations?"),
- *actually* integrates with Git (to see what I mean, try to find the commit corresponding to a given mail containing a patch, and then try to find the previous iteration's version of the same commit, and weep),
- provides machine-readable metadata about the context, e.g. to jump back and forth between the full file contents and the patch, or to indicate the dependency on another branch,
- facilitates "back contributions", i.e. letting contributors accept changes suggested by reviewers *with minimal effort*.
- uses Git itself as much as possible, i.e. no additional tools written in "you must learn this new language, it's awesome, believe me, it's huge"
The biggest obstacles I see are 1) the integration with the mailing list (which is ironic because contributing via the list used to be a boon, not a burden) and 2) maintaining the integrity between what has been reviewed and what is actually in the branch.
This is nothing we will solve overnight, of course. But I think we will have to fix this.
Food for thought.
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 3 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.
To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
Leaving aside Dscho's questions of whether pulling patches from email is convenient for most submitters (it certainly is for me, but I recognize that it is not for many), I would much rather see incremental fixup patches from you than whole "here's what I queued" responses.
The reason is that your fixups may not be the only ones needed. There may be others on the list that come before or after, and I may even have already made fixes locally for "v2" that haven't been on the list. If I haven't made any changes yet, I can throw out my topic, start with what you queued, and then apply other changes incrementally. But if I have, then I need to convert yours to a diff, which requires checking out the same base, applying yours, and running diff. Much easier to get the diff in the first place. :)
That only covers changes to the code, though. It does not help with fixups to commit messages. It would be neat to have a microformat for specifying and applying patches to commit messages.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 14 lines · Jeff King
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
Quoted 4 lines
Leaving aside Dscho's questions of whether pulling patches from email is convenient for most submitters (it certainly is for me, but I recognize that it is not for many), I would much rather see incremental fixup patches from you than whole "here's what I queued" responses.
Ah, yes, I misspoke. It should be either an incremental diff or in-line comment to spell out what got changed as a response to the patch.
I find myself fixing the title the most often, which is part of the "log message" you pointed out that would not convey well with the "incremental diff" approach.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 5 lines · Junio C Hamano
Quoted 4 lines
Leaving aside Dscho's questions of whether pulling patches from email is convenient for most submitters (it certainly is for me, but I recognize that it is not for many), I would much rather see incremental fixup patches from you than whole "here's what I queued" responses.
Quoted 7 lines
Ah, yes, I misspoke. It should be either an incremental diff or in-line comment to spell out what got changed as a response to the patch.
I find myself fixing the title the most often, which is part of the "log message" you pointed out that would not convey well with the "incremental diff" approach.
I mentioned a micro-format elsewhere in my message. And it certainly is nice to have something that can be applied in an automatic way. But in practice, most review comments, for the commit message _or_ the text, are given in human-readable terms. And as a human, I read and apply them in sequence.
That pushes work onto the submitter, but saves work from the reviewers, who can quickly say "something like this..." without having to worry about making a full change, formatting it as a diff, etc.
I do think that's the right time-tradeoff to be making, as we have more submitters than reviewers.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Peff,
Quoted 11 lines · Jeff King
Quoted 9 lines · Junio C Hamano
Quoted 4 lines
Leaving aside Dscho's questions of whether pulling patches from email is convenient for most submitters (it certainly is for me, but I recognize that it is not for many), I would much rather see incremental fixup patches from you than whole "here's what I queued" responses.
Ah, yes, I misspoke. It should be either an incremental diff or in-line comment to spell out what got changed as a response to the patch.
Quoted 6 lines
Quoted 3 lines
I find myself fixing the title the most often, which is part of the "log message" you pointed out that would not convey well with the "incremental diff" approach.
I mentioned a micro-format elsewhere in my message. And it certainly is nice to have something that can be applied in an automatic way.
Indeed. This is what I meant by my (succinct to the point of being intelligible, admittedly) reword! suggestion.
Let's clarify this idea.
I find myself using fixup! and squash! commits a lot. Actually, let me pull out the Linux key for that. I use those commits A LOT.
I know, I opposed the introduction of this feature initially (and I think that my concerns were nicely addressed by Junio's suggestion to guard this feature behind the --autosquash option). Guess what: I was wrong.
And I am really missing the same functionality for the commit message munging. These days, I find myself using git commit --allow-empty --squash=$COMMIT -c $COMMIT very often, duplicating the first line, adding an empty line between them, deleting the "squash! " prefix from the now-third line, and then editing the commit message as I want to. When it comes to cleaning up the branch via rebase -ki, I simply jump to the empty line after the squash! line and delete everything before it.
This is as repetitive, tedious and un-fun to me as having to transmogrify patches from the nice and cozy Git universe into the not-at-all compatible universe of mails (I congratulate you personally, Peff, for finding a mail client that works for you. I am still looking for one that does not suck, Alpine being the least sucky I settled for).
So my idea was to introduce a new --reword=<commit> option to git commit that would commit an empty patch and let the user edit the commit message, later replacing the original one with the new one. This is not *quite* as nice as I want it, because it makes the changes unobvious. On the other hand, I would not find a series of sed commands more obvious, in particular because that limits you in the ways of sed. And, you know, regexp. I like them, but I know many people cannot really work with them.
Quoted 3 lines
But in practice, most review comments, for the commit message _or_ the text, are given in human-readable terms. And as a human, I read and apply them in sequence.
So true. I do the very same.
Quoted 6 lines
That pushes work onto the submitter, but saves work from the reviewers, who can quickly say "something like this..." without having to worry about making a full change, formatting it as a diff, etc.
I do think that's the right time-tradeoff to be making, as we have more submitters than reviewers.
I agree that it is the right trade-off. TBH I was shocked when I learned how much effort Junio puts into applying my patches. I do not want that. I want my branch to reflect pretty precisely (modulo sign-off, of course) what is going to be integrated into Git's source code.
I'd much prefer to resubmit a cleaned-up version, even if it was just the commit subjects, and be certain that pu and my branch are on the same page.
Instead, Junio puts in a tremendous amount of work, and it does not help anybody, because the local branches *still* do not have his fixups, and as a consequence subsequent iterations of the patch series will have to be fixed up *again*.
Just compare https://github.com/git/git/compare/1fd7e78...6999bc7 to
https://github.com/dscho/git/compare/f8f7adc...3b4494c (the onelines are enough to show you just how different things are).
I'd much prefer the contributor (me, in this case) to put in a little more work, and have things consistent. And avoid unnecessary work on both sides.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Johannes Schindelin
So my idea was to introduce a new --reword=<commit> option to
git committhat would commit an empty patch and let the user edit the commit message, later replacing the original one with the new one. This is not *quite* as nice as I want it, because it makes the changes unobvious. On the other hand, I would not find a series of sed commands more obvious, in particular because that limits you in the ways of sed. And, you know, regexp. I like them, but I know many people cannot really work with them.
I don't have a real opinion on this. I probably wouldn't use it, but I have no problem with it existing. I think it's somewhat orthogonal to the idea of _transmitting_ those reword operations to somebody else.
Quoted 11 lines
Quoted 6 lines
That pushes work onto the submitter, but saves work from the reviewers, who can quickly say "something like this..." without having to worry about making a full change, formatting it as a diff, etc.
I do think that's the right time-tradeoff to be making, as we have more submitters than reviewers.
I agree that it is the right trade-off. TBH I was shocked when I learned how much effort Junio puts into applying my patches. I do not want that. I want my branch to reflect pretty precisely (modulo sign-off, of course) what is going to be integrated into Git's source code.
Like you, I have occasionally been bitten by Junio doing a fixup, and then I end up re-rolling, and lose that fixup (or have to deal with porting it forward with awkward tools).
But I think such fixups are a calculated risk. Sometimes they save a lot of time, both for the maintainer and the contributor, when they manage to prevent another round-trip of the patch series to the list.
IOW, if the flow is something like:
1. Contributor sends patches. People review.
2. Minor fixups noticed by maintainer, fixed while applying.
3. Only one small fixup needed from review. Contributor sends squashable patch. Maintainer squashes.
then I think that is a net win over sending the whole series again, for the contributor (who does not bother sending), reviewers (who really only need to look at the interdiff, which is what that squash is in the first place), and the maintainer (who can squash just as easily as re-applying the whole series).
It does mean the "final" version of the series is never on the list. It has to be pieced together from the squash (and sometimes step 2 is not even mentioned on-list).
So I think it is really a judgement call for step (3) on what is a "small" fixup, and whether it is easier for everybody to look at the squash interdiff and say "yep, that's right", versus re-reviewing the whole series.
Quoted 8 lines
I'd much prefer to resubmit a cleaned-up version, even if it was just the commit subjects, and be certain that
puand my branch are on the same page.Instead, Junio puts in a tremendous amount of work, and it does not help anybody, because the local branches *still* do not have his fixups, and as a consequence subsequent iterations of the patch series will have to be fixed up *again*.
And that is the flip side. If the flow above does not happen, then step 2 just becomes a pain.
I don't have a silver bullet or anything. I'm mostly just musing.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 2 lines · Jeff King
Like you, I have occasionally been bitten by Junio doing a fixup, and then I end up re-rolling, and lose that fixup.
... which usually is caught when I receive the reroll, as I try to apply to the same base and compare the result with the previous round.
Quoted 3 lines
But I think such fixups are a calculated risk. Sometimes they save a lot of time, both for the maintainer and the contributor, when they manage to prevent another round-trip of the patch series to the list.
Yes.
Quoted 5 lines
IOW, if the flow is something like:
1. Contributor sends patches. People review.
2. Minor fixups noticed by maintainer, fixed while applying.
This includes different kinds of things:
a) Trivially correct fixes given in other people's review.
b) Minor fixups by the maintainer, to code.
c) Minor fixups by the maintainer, to proposed log message.
d) "apply --whitespace=fix" whose result I do not even actively keep track of.
Quoted 11 lines
3. Only one small fixup needed from review. Contributor sends squashable patch. Maintainer squashes.
then I think that is a net win over sending the whole series again, for the contributor (who does not bother sending), reviewers (who really only need to look at the interdiff, which is what that squash is in the first place), and the maintainer (who can squash just as easily as re-applying the whole series).
And that is the flip side. If the flow above does not happen, then step 2 just becomes a pain.
I think I can
* stop taking 2-a). This is less work for me, but some contributors are leaky and can lose obviously good suggestions, so I am not sure if that is an overall win for the quality of the end product;
* do a separate "SQUASH???" commit and send them out for 2-b). This is a lot more work for a large series, but about the same amount of work (except for "remembering to send them out" part) for a small-ish topic. A contributor needs to realize that I deal with _all_ the incoming topics, not just from topics from one contributor, and small additional work tends to add up.
to reduce #2. Essentially, doing these two are about moving more responsibility of keeping track of good suggestions in the review discussion to the contributor, but a bad thing is that it does not mean that the maintainer can stop keeping track of them. We need a way to make sure leaky contributors do not repeat the same issue in their reroll that has already been pointed out and whose solutions presented in the previous review. Fetching from 'pu' and compare has been one way to do so (that is why I publish 'pu' in the first place, not to "build on", but to "view"), but apparently not many contributors are comfortable with that idea.
There is no good way to reduce 2-c) and 2-d), but on the other hand, there is no strong need for a special channel to propagate these back. 2-c) can be a regular review comment (but again that risks "the leaky contributor" problem) and 2-d) will happen automatically when applying the rerolled version.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 13 lines · Junio C Hamano
Quoted 1 line
2. Minor fixups noticed by maintainer, fixed while applying.
This includes different kinds of things:
a) Trivially correct fixes given in other people's review.
b) Minor fixups by the maintainer, to code.
c) Minor fixups by the maintainer, to proposed log message.
d) "apply --whitespace=fix" whose result I do not even actively keep track of.
Quoted 8 lines
[...]
I think I can
* stop taking 2-a). This is less work for me, but some contributors are leaky and can lose obviously good suggestions, so I am not sure if that is an overall win for the quality of the end product;
Actually, I think the 2-a class is what often saves a re-roll. Somebody points out a typo in a commit message or a comment, and it quite often gets picked up by you without having another round-trip to the list.
If you want to save work by not doing so, that's fine with me. But this is the gamble I was talking about. I think it's actually often less work to do the fixup than to look at another re-roll (especially with the "leaky contributor" thing where you have to make sure all fixes were applied). So it's a win if it saves the re-roll, but sometimes you end up having to look at the re-roll anyway.
Quoted 6 lines
* do a separate "SQUASH???" commit and send them out for 2-b). This is a lot more work for a large series, but about the same amount of work (except for "remembering to send them out" part) for a small-ish topic. A contributor needs to realize that I deal with _all_ the incoming topics, not just from topics from one contributor, and small additional work tends to add up.
I think these are largely the same as 2-a. You are just wearing two hats, reviewer and maintainer. Which I guess lets you take a shortcut sometimes (and just fix without mentioning it), but fundamentally the "gamble" aspect is the same, I think.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Junio C HamanoHi Junio,
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Jeff King
Like you, I have occasionally been bitten by Junio doing a fixup, and then I end up re-rolling, and lose that fixup.
... which usually is caught when I receive the reroll, as I try to apply to the same base and compare the result with the previous round.
I find it incredibly nice of you to do those fix-ups, sorry to state that as clearly only now. It's just that I hate to see your time wasted, in particular when *I* waste it because I missed the fix-ups in pu.
Quoted 5 lines
Quoted 3 lines
But I think such fixups are a calculated risk. Sometimes they save a lot of time, both for the maintainer and the contributor, when they manage to prevent another round-trip of the patch series to the list.
Yes.
FWIW I am more than just willing to spend a little more time on applying fix-ups and re-rolling patch series (and dual-publishing them via my public repository), if it helps lighten your burden.
Quoted 29 lines
Quoted 5 lines
IOW, if the flow is something like:
1. Contributor sends patches. People review.
2. Minor fixups noticed by maintainer, fixed while applying.
This includes different kinds of things:
a) Trivially correct fixes given in other people's review.
b) Minor fixups by the maintainer, to code.
c) Minor fixups by the maintainer, to proposed log message.
d) "apply --whitespace=fix" whose result I do not even actively keep track of.
Quoted 11 lines
3. Only one small fixup needed from review. Contributor sends squashable patch. Maintainer squashes.
then I think that is a net win over sending the whole series again, for the contributor (who does not bother sending), reviewers (who really only need to look at the interdiff, which is what that squash is in the first place), and the maintainer (who can squash just as easily as re-applying the whole series).
And that is the flip side. If the flow above does not happen, then step 2 just becomes a pain.
Quoted 6 lines
I think I can
* stop taking 2-a). This is less work for me, but some contributors are leaky and can lose obviously good suggestions, so I am not sure if that is an overall win for the quality of the end product;
If you had a git commit --reword command to touch up commit messages, would that help you, together with the git commit --fixup command for code changes? The branches in pu would have your fix-ups as strictly separate commits on top of the contributed patches, and the branches would need to be sent through rebase -i before merging to next, of course.
The idea would be to not forget your fixups in subsequent iterations, but simply rebase them on top of the new iteration.
It would still not solve my problem that there is no convenient way to jump from your commits in pu to the corresponding ones in my local branch. But that is my problem, not yours.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Junio C HamanoHi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
You seem to assume that it isn't cumbersome for people like me to extract patches out of mails and to replace existing commits using those patches.
So it probably comes as a huge surprise to you to learn that this *is* cumbersome for me.
I got too used to the ease of git push, git pull with or without --rebase, and many other Git commands. Having to transmogrify code changes from commits in Git into a completely different universe: plain text patches in my mailbox, and back, losing all kinds of data in the process, is just not at all that easy. And it costs a lot of time.
In short: if you start "submitting patches" back to me via mail, it does not help me. It makes things harder for me. In particular when you add your sign-off to every patch and I have to strip it.
If you change your workflow, I would humbly request that you do it in a way that makes things easier on both sides, not harder.
It would be a totally different matter, of course, if you used the branches I publish via my GitHub repository, added fixup! and squash! commits, published the result to a public repository and then told me to pull from there, that would make things easier. We could even introduce a reword! construct, to make the review of the suggested edits of the commit message easier. I could easily verify that my branch head agrees with the base commit of your branch, I could build proper tooling around this workflow, and it would lighten my load.
I guess what I am saying is that we might just as well start using this awesome tool to work with code, that tool named "Git".
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 16 lines · Johannes Schindelin
Hi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
Quoted 5 lines
You seem to assume that it isn't cumbersome for people like me to extract patches out of mails and to replace existing commits using those patches.
So it probably comes as a huge surprise to you to learn that this *is* cumbersome for me.
It is also cumbersome for me, because I never had the need to setup a proper mail client that has the strength to apply patches. The need was not there as I tend to apply only rarely patches by email, so I can go the painful way each time.
But if we as a community decide that we bounce emails back and forth, I (and you)
may have to find a proper email client that is easy to work with, e.g. one key shortcut
to apply a patch series to the HEAD of your local repository.
Quoted 10 lines
I got too used to the ease of git push, git pull with or without --rebase, and many other Git commands. Having to transmogrify code changes from commits in Git into a completely different universe: plain text patches in my mailbox, and back, losing all kinds of data in the process, is just not at all that easy. And it costs a lot of time.
In short: if you start "submitting patches" back to me via mail, it does not help me. It makes things harder for me. In particular when you add your sign-off to every patch and I have to strip it.
You don't have to strip the sign off, as it shows the flow of the patch, e.g.
may indicate you proposed a patch, Junio picked it up (and fixed a typo optionally),
I obtained the patch (via mail, via Git?) improved it, you improved it further and then Junio took it and merged it upstream.
Quoted 3 lines
If you change your workflow, I would humbly request that you do it in a way that makes things easier on both sides, not harder.
When attending the Git Merge conference in May, gregkh said roughtly:
"We deliberately waste developers time, because it is not scarce. Maintainers time is scarce however " and it stuck with me. (and I am a developer, not a maintainer ;( so at least the kernel community deems it ok to waste my time).
While that is true for the kernel community, I guess it is also true for the Git community, unless Junio (and the community) want to appoint a bunch of maintainer lieutenants, such that they outnumber the number of developers, e.g. divided by areas of the code:
a refs backend maintainer, a submodule maintainer, ...
or rather by area of usage: a porcelain UI maintainer, a git-on-server maintainer.
Though Git is not as diverse and large as the kernel, so the horde of maintainers would step onto each feet quite frequently IMHO.
Quoted 10 lines
It would be a totally different matter, of course, if you used the branches I publish via my GitHub repository, added fixup! and squash! commits, published the result to a public repository and then told me to pull from there, that would make things easier. We could even introduce a reword! construct, to make the review of the suggested edits of the commit message easier. I could easily verify that my branch head agrees with the base commit of your branch, I could build proper tooling around this workflow, and it would lighten my load.
Quoted 2 lines
I guess what I am saying is that we might just as well start using this awesome tool to work with code, that tool named "Git".
I think Git itself is for the tracking the code and managing it, e.g. merging, moving, keeping it. That doesn't quite include modifying and creating code (e.g. there is no "git edit" command)
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series, which defines a common review format, such that we have a "protocol" how to store the review data and how to store the progress of potential collaboration and then we can develop tools against that protocol. Some people want to have a web UI, whereas others want to have a text only thing as they are faster keyboard only.
[1] http://git.661346.n2.nabble.com/Working-towards-a-common-review-format-for-git-td7645242.html
Thanks for starting this discussion,
Stefan
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Stefan,
Quoted 23 lines · Stefan Beller
Quoted 21 lines · Johannes Schindelin
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
I disagree, however, with the suggestion to sift through your
pubranch and to somehow replace local branches with the commits found there.Quoted 6 lines
To be more in line with the "e-mailed patch" workflow, I think what I should do is to send the version I queued with fixups back to the list as follow-up. Just like reviewers review, the maintainer reviews and queues, the original author should be able to work in the same workflow, i.e. reading and applying an improved version of the patch from her mailbox.
You seem to assume that it isn't cumbersome for people like me to extract patches out of mails and to replace existing commits using those patches.
Quoted 7 lines
Quoted 2 lines
So it probably comes as a huge surprise to you to learn that this *is* cumbersome for me.
It is also cumbersome for me, because I never had the need to setup a proper mail client that has the strength to apply patches. The need was not there as I tend to apply only rarely patches by email, so I can go the painful way each time.
The reason is clear, too. Mail clients serve humans. That is their purpose. Humans do not care all that much whether the text was preserved exactly as the sender wrote it, except rich text (read: HTML), of course.
Quoted 20 lines
Quoted 10 lines
I got too used to the ease of git push, git pull with or without --rebase, and many other Git commands. Having to transmogrify code changes from commits in Git into a completely different universe:
plain text patches in my mailbox, and back, losing all kinds of data in the process, is just not at all that easy. And it costs a lot of time.In short: if you start "submitting patches" back to me via mail, it does not help me. It makes things harder for me. In particular when you add your sign-off to every patch and I have to strip it.
You don't have to strip the sign off, as it shows the flow of the patch, e.g.
Signed-off-by Johannes Schindelin <[email protected]>Signed-off-by Junio C Hamano <[email protected]>Signed-off-by Stefan Beller <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>Signed-off-by Junio C Hamano <[email protected]>
Quoted 3 lines
may indicate you proposed a patch, Junio picked it up (and fixed a typo optionally), I obtained the patch (via mail, via Git?) improved it, you improved it further and then Junio took it and merged it upstream.
Recently, I got yelled at because I took one of Junio's patches, made a couple of changes, and *added* my sign-off.
Before that incident, I agreed with you that it may make for a nice record of the back-and-forth that eventually resulted in the patch in question. Now, I am not so sure anymore.
Quoted 8 lines
Quoted 2 lines
If you change your workflow, I would humbly request that you do it in a way that makes things easier on both sides, not harder.
When attending the Git Merge conference in May, gregkh said roughtly:
"We deliberately waste developers time, because it is not scarce. Maintainers time is scarce however " and it stuck with me. (and I am a developer, not a maintainer ;( so at least the kernel community deems it ok to waste my time).
Yeah. It was not the only thing I disagreed with in his talk. To be a little bit blunt (by my standards, not by LKML's standards, that is): the Linux kernel mailing list is not necessarily anything I would want to use as a role model.
I agree that maintainers' time is scarce.
I am one.
So of course I agree with that statement. What I disagree with is that it is okay to *waste* contributors' time. That's just inconsiderate. And I say that also because I am a contributor *in addition* to being a maintainer.
As a consequence, I commend Greg for recognizing that the patch submission process must be light on the maintainer. And I would have commended him even further if he had realized that proper tooling should waste nothing, and no one's time.
Quoted 6 lines
While that is true for the kernel community, I guess it is also true for the Git community, unless Junio (and the community) want to appoint a bunch of maintainer lieutenants, such that they outnumber the number of developers, e.g. divided by areas of the code: a refs backend maintainer, a submodule maintainer, ... or rather by area of usage: a porcelain UI maintainer, a git-on-server maintainer.
As I mentioned earlier, I do not care much about following LKML's example.
What I see on this here list is that many a potential contributor is scared away, that we waste precious time (also the maintainer's) pointing out in what way certain contributions do not follow the guide lines, and that even old-timers sometimes submit patches that are white-space corrupted.
That is a *huge* waste of time. In my opinion, the culprit is that we do not use appropriate tools. To a mail client, everything looks like a nail. Wrong metaphor, but you get the point.
Quoted 9 lines
Quoted 9 lines
It would be a totally different matter, of course, if you used the branches I publish via my GitHub repository, added fixup! and squash! commits, published the result to a public repository and then told me to pull from there, that would make things easier. We could even introduce a reword! construct, to make the review of the suggested edits of the commit message easier. I could easily verify that my branch head agrees with the base commit of your branch, I could build proper tooling around this workflow, and it would lighten my load.
Quoted 6 lines
Quoted 2 lines
I guess what I am saying is that we might just as well start using this awesome tool to work with code, that tool named "Git".
I think Git itself is for the tracking the code and managing it, e.g. merging, moving, keeping it. That doesn't quite include modifying and creating code (e.g. there is no "git edit" command)
Git is not only for tracking the code. It knows about editors (core.editor), it can export .zip files (git-archive), it can show human-readable (not machine-readable) word diffs, etc.
Whenever we needed a certain functionality, we added it.
Quoted 2 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
And when I said I have zero interest in tools that use the "latest and greatest language", I was hinting at git-series. Rust may be a fine and wonderful language. Implementing git-series in Rust, however, immediately limited the potential engagement with developers dramatically.
Additionally, I would like to point out that defining a way to store reviews in Git is not necessarily improving the way our code contribution process works. If you want to record the discussions revolving around the code, I think public-inbox already does a pretty good job at that.
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
I did not propose to use Gerrit or git-series or git appraise.
However whenever I see these projects talking to each other, the talk focuses on a "unified review storage format" pretty often, which would make them compatible with each other. So then I could choose git-series, while you could go with git appraise (although that is written in go, so maybe too fancy already ;) Or there could be another new program written in C that follows the "review format".
Quoted 9 lines
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
And when I said I have zero interest in tools that use the "latest and greatest language", I was hinting at git-series. Rust may be a fine and wonderful language. Implementing git-series in Rust, however, immediately limited the potential engagement with developers dramatically.
Quoted 4 lines
Additionally, I would like to point out that defining a way to store reviews in Git is not necessarily improving the way our code contribution process works. If you want to record the discussions revolving around the code, I think public-inbox already does a pretty good job at that.
Yeah recording is great, but we want to talk about replying and modifying a series? So if I see a patch flying by on the mailing list, ideally I could attach a "!fixup, signed off by Stefan" thing to that patch. (I said "thing" as I do not necessarily mean email here.
Quoted 4 lines
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Does it have to be email? Transmitting text could be solved differently as well.
With git push/fetch we can interact with a git remote and pertain the state (commits, ancestor graph) at a full level even including notes that comment on commits.
git send-email/format-patch recently learned to include a base commit (xy/format-patch-base), maybe we need a counter part to git send-email that downloads a series from your mailbox, such that a local branch can be transmitted to via
"git send-email --base=origin/master --include-notes --name=sb/new-series"
and completely reconstructed (i.e. the commit sha1s even match) including notes via:
git fetch-email --name=sb/new-series
That way would ensure we have a "simple" way to transmit patches back and forth and adding potential fixups.
Quoted 6 lines · You
In short, I agree that our patch submission process is a saber tooth tiger that still reflects pre-Git times. While we use Git's tools, the workflow really tries to cut out Git as much as possible, in favor of pure mails with non-corrupted, non-HTML patches in them, a charmingly anachronistic requirement until you try to use state-of-the-art mail clients to send them.
And there are two ways out:
* either we teach git how to deal with emails (completely, i.e. sending+receiving)
* or we change the development model (e.g. no emails any more)
There is no golden third way IMHO.
Thanks,
Stefan
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 8 lines · Stefan Beller
Quoted 3 lines · Johannes Schindelin
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Does it have to be email? Transmitting text could be solved differently as well.
I've thought a lot about this over the years still think email is the least bad.
Anti-spam tools for other messaging systems are far behind, proprietary, or non-existent. bugzilla.kernel.org has been hit hard lately and I see plenty of bug-tracker-to-mail spam as a result from projects that use web-based bug trackers.
And email spam filtering isn't even that great
(and I think it needs to be better for IPv6 and .onion adoption
since much of it is still IPv4-oriented blacklisting).
I guess a blockchain (*coin) implementation might work (like hashcash is used for email anti-spam), but the ones I've glanced at all look like a bigger waste of electricity than email filters.
Of course, centralized systems are unacceptable to me; and with that I'll never claim any network service I run will be reliable :)
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Eric,
Quoted 7 lines · Eric Wong
Quoted 6 lines · Stefan Beller
Quoted 3 lines · Johannes Schindelin
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Quoted 5 lines
Quoted 2 lines
Does it have to be email? Transmitting text could be solved differently as well.
I've thought a lot about this over the years still think email is the least bad.
Not only that: people are *familiar* with it. And they have *access* to it.
Quoted 4 lines
Anti-spam tools for other messaging systems are far behind, proprietary, or non-existent. bugzilla.kernel.org has been hit hard lately and I see plenty of bug-tracker-to-mail spam as a result from projects that use web-based bug trackers.
Plus, they are all centralized. Do you want to *require* contibutors to register with a new service?
Quoted 4 lines
I guess a blockchain (*coin) implementation might work (like hashcash is used for email anti-spam), but the ones I've glanced at all look like a bigger waste of electricity than email filters.
I am not even so much concerned with ecological considerations here. Just the price of entry would be prohibitive.
Quoted 3 lines
Of course, centralized systems are unacceptable to me; and with that I'll never claim any network service I run will be reliable :)
Hehehe. I guess that's why the public-inbox is backed by a Git repository... BTW is it auto-mirrored anywhere?
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Johannes Schindelin <[email protected]> wrote:
Agreed on all above points :>
Quoted 7 lines · Eric Wong
Quoted 3 lines
Of course, centralized systems are unacceptable to me; and with that I'll never claim any network service I run will be reliable :)
Hehehe. I guess that's why the public-inbox is backed by a Git repository... BTW is it auto-mirrored anywhere?
Yep, and the code is AGPL so others can always replicate it.
I just have the onions mentioned at the bottom of the HTML pages running something like:
torsocks git fetch && public-inbox-index && sleep 30
in a loop[1].
http://hjrcffqmbrq6wope.onion/git
http://czquwvybam4bgbro.onion/git
I do encourage anybody who is able to, to run their own mirrors (off their existing email subscription) so my MX doesn't become an SPOF, either. I sorta documented it in my original announcement:
https://public-inbox.org/git/[email protected]/
https://public-inbox.org/INSTALL
Feel free to ask me (+ [email protected]) for install/running questions related to public-inbox (haven't gotten to making it work outside of Debian stable, though).
[1] one of my far-off goals for git be: "git fetch --wait-for-update" to avoid needless wakeups
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Stefan BellerHi Stefan,
Quoted 10 lines · Stefan Beller
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
Quoted 5 lines
I did not propose to use Gerrit or git-series or git appraise.
However whenever I see these projects talking to each other, the talk focuses on a "unified review storage format" pretty often, which would make them compatible with each other.
Unless you have a splendid idea how to integrate that unified format with our review process on the mailing list, I think this makes for a fine discussion elsewhere. I'd really like to focus on the Git project and its patch contribution process in this here thread.
Quoted 2 lines
So then I could choose git-series, while you could go with git appraise (although that is written in go, so maybe too fancy already ;)
I think you misunderstood me in a big way.
New languages are awesome. I play with new toys whenever I find the time (and streamlining the contribution process would give me more time for that). You are talking to a person who implemented the Householder transformation in Postscript, a 6502 assembler in Forth, and a music composing system in Emacs Lisp. No language is to fancy for me. "me", as in "me, personally".
Now let's think about Git for a moment, and its language choices, and the rationale behind them. The majority of the critically important code is written in C. Is C a good language? Decent, yes, but of course also limiting, Resource leaks are very easy to overlook, and we have a share of them. No object orientation, so when we need to "subclass", we have no compile time safety. The pre-processor constructs make static analysis nigh impossible. Plenty of downsides. So why was it chosen? Developers are *familiar* with it, that's why. Similar considerations apply to the use of shell scripts, and to Perl, to a certain extent.
I am not talking about contrib/ of course. That's fair game, it contains only non-critical/fringe stuff.
Note that the same rationale goes for choosing to accept patch submissions via mail to a list that is not subscribers-only.
When it comes to inviting developers to contribute to your project, personal preferences become irrelevant, the deciding factor becomes how easy it is to join. Is the language popular, many developers already familiar with it? Is the build system readily available? Are the maintainers responsive?
I vividly remember my reaction to Darcs, for example. It's written in Haskell. I am a mathematician originally, so Haskell appeals to me. Did the choice of language appear to be designed to keep contributors out? To me, it looked that way.
Other example: submitGit. I really like what its intention. For a while, I even hoped to move my *own* patch submissions to submitGit. I planned to help get the kinks out of the code by contributing to it. It is written in Scala, using a web application and testing framework I have not encountered elsewhere. I struggled with installing it locally and wrapping my head around the coding paradigms, for 1.5 days (which was all I could afford at that time). Then I had to give up. Which made me very sad. I would not have written my mail-path-series.sh tool if submitGit had been written in node.js, for example, with which I am familiar enough to jump right in.
So I hope you understand better now why I find Rust a poor choice for something like git-series, because it should not waste contributors' time by insisting that their price of entry is learning a new language they are unfamiliar with, using a new packaging system, installing a new build setup. I would find Clojure, Crystal or Swift just as poor a choice. Even node.js. It is just too much of a "Keep Out" sign for busy developers. And all the developers worth their salt are busy.
Quoted 10 lines
Quoted 5 lines
Additionally, I would like to point out that defining a way to store reviews in Git is not necessarily improving the way our code contribution process works. If you want to record the discussions revolving around the code, I think public-inbox already does a pretty good job at that.
Yeah recording is great, but we want to talk about replying and modifying a series? So if I see a patch flying by on the mailing list, ideally I could attach a "!fixup, signed off by Stefan" thing to that patch. (I said "thing" as I do not necessarily mean email here.
Right. I briefly considered suggesting a new tool that would operate on attachments, integrating tightly with the local git.git checkout. Briefly. I had to reject this idea because I do not think that requiring new tools just to contribute to Git would fly well.
Quoted 6 lines
Quoted 3 lines
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Does it have to be email? Transmitting text could be solved differently as well.
Well, you can only convince old-timers like Junio and Peff incrementally, by showing them something that makes their life easier, and that they do not *have* to use.
Additionally, keep in mind that the single thing *all* potential contributors have in common is access to email.
So yes, I think that any improvement would have to happen incrementally, opt-in. Meaning: on top of the current process.
Quoted 3 lines
With git push/fetch we can interact with a git remote and pertain the state (commits, ancestor graph) at a full level even including notes that comment on commits.
Including much more, in fact: *any* kind of data.
But how to build on top of the current process, where some reviewers jump in via NNTP, for crying out loud? How to ensure the integrity between what is flying around as mails and what is present in the Git repository?
Quoted 1 line
git send-email/format-patch recently learned to include a base commit
You may have noticed that my mail-patch-series.sh-generated code submissions contain that base commit. But they still do not contain the SHA-1s of my local commits corresponding to the patches, and even if they did, the replies with suggested edits would most likely have lost said information.
I also hate to break it to you that git-send-email is not going to be part of any solution.
Quoted 8 lines
Quoted 6 lines · You
In short, I agree that our patch submission process is a saber tooth tiger that still reflects pre-Git times. While we use Git's tools, the workflow really tries to cut out Git as much as possible, in favor of pure mails with non-corrupted, non-HTML patches in them, a charmingly anachronistic requirement until you try to use state-of-the-art mail clients to send them.
Quoted 6 lines
And there are two ways out:
* either we teach git how to deal with emails (completely, i.e. sending+receiving)
* or we change the development model (e.g. no emails any more)There is no golden third way IMHO.
There are plenty more options.
In Git for Windows, I would accept patches via mail (curiously, nobody tried that in the past 12 months, not that I recall). I accept Pull Requests. I try to use patches mentioned in issue comments (!) and apply them.
The point is: you do not *have* to limit yourself to accepting patches *only* in one way.
Another option would be to come up with a non-opinionated tool that helps with submitting *and accepting* patches via mail. Non-opinionated, as in:
it does not expect to write an entire raw mail and have that entire raw mail transmitted intact. It could, for example, generate human-consumable plain text and *also* an attachment that the tool understands. This tool could then even show a GUI to help with inspecting the relevant code/patches.
Yet another option would be to have a tool that integrates with the Git repository of the Git mailing list represented by public-inbox.
Plenty more options.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Johannes,
Quoted 37 lines · Johannes Schindelin
Hi Stefan,
Quoted 10 lines · Stefan Beller
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
Quoted 5 lines
I did not propose to use Gerrit or git-series or git appraise.
However whenever I see these projects talking to each other, the talk focuses on a "unified review storage format" pretty often, which would make them compatible with each other.
Unless you have a splendid idea how to integrate that unified format with our review process on the mailing list, I think this makes for a fine discussion elsewhere. I'd really like to focus on the Git project and its patch contribution process in this here thread.
Quoted 2 lines
So then I could choose git-series, while you could go with git appraise (although that is written in go, so maybe too fancy already ;)
I think you misunderstood me in a big way.
New languages are awesome. I play with new toys whenever I find the time (and streamlining the contribution process would give me more time for that). You are talking to a person who implemented the Householder transformation in Postscript, a 6502 assembler in Forth, and a music composing system in Emacs Lisp. No language is to fancy for me. "me", as in "me, personally".
Quoted 9 lines
Now let's think about Git for a moment, and its language choices, and the rationale behind them. The majority of the critically important code is written in C. Is C a good language? Decent, yes, but of course also limiting, Resource leaks are very easy to overlook, and we have a share of them. No object orientation, so when we need to "subclass", we have no compile time safety. The pre-processor constructs make static analysis nigh impossible. Plenty of downsides. So why was it chosen? Developers are *familiar* with it, that's why. Similar considerations apply to the use of shell scripts, and to Perl, to a certain extent.
Which is changing slowly over time IMHO. The "new generation" of developers may not have in-depth knowledge of shelll or perl any more, but rather python or java maybe.
Quoted 4 lines
I am not talking about contrib/ of course. That's fair game, it contains only non-critical/fringe stuff.
Quoted 8 lines
Note that the same rationale goes for choosing to accept patch submissions via mail to a list that is not subscribers-only.
When it comes to inviting developers to contribute to your project, personal preferences become irrelevant, the deciding factor becomes how easy it is to join. Is the language popular, many developers already familiar with it? Is the build system readily available? Are the maintainers responsive?
I agree. I really do.
I had some discussion at lunch yesterday about different attitudes of open source projects towards new contributions. An example was the Eclipse projects that scare off potential new contributors (specially these fly by single patch submissions) as you need to interact through their instance of Gerrit after signing a CLA.
Git on the other hand doesn't do
a bad job, e.g. I started with a patch that ought to be a single shot drive by patch. About 780 others wrote one patch and were never seen again:
$ git shortlog -sne |grep 1 |wc -l
788So our process is not too bad for the time. However email is as a communication tool is dying [1] eventually?
Let's examine if we get less one time contributions over time:
for i in $(seq 11 -1 1) ; do
x_1=$(git shortlog -sne --since $i.years --until
$(($i-1)).years |grep 1 |wc -l)
printf "$i\t$x_1\n"
done11 81 10 94 9 175 8 148 7 139 6 118 5 108 4 149 3 109 2 106 1 99
Looking at these numbers the number of one time patch contributions spiked 9 years ago and declined since then (4 years ago seems to be an outlier)
And I do not think the decline of one off contributions is because Git as a project is in decline, but has other reasons. Maybe the project is in better shape now that there are less one-off worthy contributions? Or the contribution process is not appealing to a lot of new comers?
[1] I could not find a scientific paper that evaluates communcation habits of people, but these may give a feel for it:
https://www.quora.com/Why-are-young-people-abandoning-email
https://news.ycombinator.com/item?id=3554466
http://www.twistimage.com/blog/archives/nobody-uses-email-anymore/
http://www.emailisnotdead.com/
Quoted 6 lines
I vividly remember my reaction to Darcs, for example. It's written in Haskell. I am a mathematician originally, so Haskell appeals to me. Did the choice of language appear to be designed to keep contributors out? To me, it looked that way.
Quoted 10 lines
Other example: submitGit. I really like what its intention. For a while, I even hoped to move my *own* patch submissions to submitGit. I planned to help get the kinks out of the code by contributing to it. It is written in Scala, using a web application and testing framework I have not encountered elsewhere. I struggled with installing it locally and wrapping my head around the coding paradigms, for 1.5 days (which was all I could afford at that time). Then I had to give up. Which made me very sad. I would not have written my
mail-path-series.shtool if submitGit had been written in node.js, for example, with which I am familiar enough to jump right in.
Why did you desire to set it up yourself and not just use it? (I'd guess one of the underlying reasons could be sticking to FOSS principles, i.e. you want to be in control of what you use; But there I would argue to just approach it pragmatically. When it ceases to exist, there is time to look for an alternative.)
Quoted 8 lines
So I hope you understand better now why I find Rust a poor choice for something like git-series, because it should not waste contributors' time by insisting that their price of entry is learning a new language they are unfamiliar with, using a new packaging system, installing a new build setup. I would find Clojure, Crystal or Swift just as poor a choice. Even node.js. It is just too much of a "Keep Out" sign for busy developers. And all the developers worth their salt are busy.
Ideally you would not need to touch the internals of said tool, hence no need to learn Rust? Of course no tool is perfect, so eventually you'd want to look at the internals.
You can take the same argument for our current contribution process. Is it easier to learn a new language or setup a proper mail client that doesn't screw up your emails?
Depending on the language, it is really easy to get started and have some results out in a day or two.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Additionally, I would like to point out that defining a way to store reviews in Git is not necessarily improving the way our code contribution process works. If you want to record the discussions revolving around the code, I think public-inbox already does a pretty good job at that.
Yeah recording is great, but we want to talk about replying and modifying a series? So if I see a patch flying by on the mailing list, ideally I could attach a "!fixup, signed off by Stefan" thing to that patch. (I said "thing" as I do not necessarily mean email here.
Quoted 4 lines
Right. I briefly considered suggesting a new tool that would operate on attachments, integrating tightly with the local git.git checkout. Briefly. I had to reject this idea because I do not think that requiring new tools just to contribute to Git would fly well.
Well it would be part of Git?
I consider Git a toolbox that has all kinds of useful tools to deal with code, i.e. transporting, diffing, storing. And transporting is a broad
category: we have push/pull with various protocols,
bundles for sneaker net and send-email for "pushing over email".
So we can have another transport tool that helps our own workflow?
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
I guess I have no really good idea yet, either, how to retain the ease of access of sending mails to the list, yet somehow keep a strong tie with the original data stored in Git.
Does it have to be email? Transmitting text could be solved differently as well.
Quoted 6 lines
Well, you can only convince old-timers like Junio and Peff incrementally, by showing them something that makes their life easier, and that they do not *have* to use.
Additionally, keep in mind that the single thing *all* potential contributors have in common is access to email.
As I said above, this may not be true any more in the far future. However I guess email is still a good base layer.
Quoted 3 lines
So yes, I think that any improvement would have to happen incrementally, opt-in. Meaning: on top of the current process.
The current process is free text on a mailing list for replies, so developing a tool on top of this "data format" is really hard.
Quoted 10 lines
Quoted 4 lines
With git push/fetch we can interact with a git remote and pertain the state (commits, ancestor graph) at a full level even including notes that comment on commits.
Including much more, in fact: *any* kind of data.
But how to build on top of the current process, where some reviewers jump in via NNTP, for crying out loud? How to ensure the integrity between what is flying around as mails and what is present in the Git repository?
Currently we don't. It breaks all the time. (C.f. Junio: "This is whitespace broken,; no need to resend I'll fix it up locally")
Quoted 11 lines
Quoted 2 lines
git send-email/format-patch recently learned to include a base commit
You may have noticed that my mail-patch-series.sh-generated code submissions contain that base commit. But they still do not contain the SHA-1s of my local commits corresponding to the patches, and even if they did, the replies with suggested edits would most likely have lost said information.
I also hate to break it to you that git-send-email is not going to be part of any solution.
It's written in perl, so it's not one of the core parts of Git that you mentioned above. I do use it though for my submission process.
But both send-email as well as mail-patch-series as well as git-series are all about the *sending* part. Not about the back and forth part, i.e. these don't deal with: "here is a fixup on top". And by that I mean receiving mails and applying them. git-am is there as a front-end once you obtained the mail, but from what I get, your original problem is to get up to date with the latest state, that is either in pu or a proposed fixup mail on top of your series?
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines · You
In short, I agree that our patch submission process is a saber tooth tiger that still reflects pre-Git times. While we use Git's tools, the workflow really tries to cut out Git as much as possible, in favor of pure mails with non-corrupted, non-HTML patches in them, a charmingly anachronistic requirement until you try to use state-of-the-art mail clients to send them.
And there are two ways out:
* either we teach git how to deal with emails (completely, i.e. sending+receiving)
* or we change the development model (e.g. no emails any more)
Quoted 8 lines
Quoted 1 line
There is no golden third way IMHO.
There are plenty more options.
In Git for Windows, I would accept patches via mail (curiously, nobody tried that in the past 12 months, not that I recall). I accept Pull Requests. I try to use patches mentioned in issue comments (!) and apply them.
That is great!
Quoted 3 lines
The point is: you do not *have* to limit yourself to accepting patches *only* in one way.
I am not sure who the "you" is here.
Quoted 3 lines · You
Well, you can only convince old-timers like Junio and Peff incrementally, by showing them something that makes their life easier, and that they do not *have* to use.
They like email and it works for them. Are you suggesting Junio and Jeff should accept pull request like you do?
For me as a contributor, I'll just use email for now for exactly this reason. I have it setup and know the quirks (which I occasionally forget, so it breaks again), but it is working "good enough".
Quoted 8 lines
Another option would be to come up with a non-opinionated tool that helps with submitting *and accepting* patches via mail. Non-opinionated, as in:
it does not expect to write an entire raw mail and have that entire raw mail transmitted intact. It could, for example, generate human-consumable plain text and *also* an attachment that the tool understands. This tool could then even show a GUI to help with inspecting the relevant code/patches.
So a new email client that is specially adapted to the needs of the Git workflow?
Quoted 3 lines
Yet another option would be to have a tool that integrates with the Git repository of the Git mailing list represented by public-inbox.
So my first reaction to that would be: you could push you patches to that public inbox and it is translated to emails sent on your behalf.
Which is reinventing submitGit just in a more accessible language?
Quoted 5 lines
Plenty more options.
Ciao,
Dscho
Thanks for writing such a long email, I missed some of the more subtle points before indeed.
Thanks,
Stefan
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Stefan Beller
But both send-email as well as mail-patch-series as well as git-series are all about the *sending* part. Not about the back and forth part, i.e. these don't deal with: "here is a fixup on top". And by that I mean receiving mails and applying them. git-am is there as a front-end once you obtained the mail, but from what I get, your original problem is to get up to date with the latest state, that is either in pu or a proposed fixup mail on top of your series?
git-series, at least, is intended to handle the back-and-forth: if you actually publish the series and not just the final result, someone could pull the series, make a (non-fast-forwarding) change to that, make a new series commit, and publish their modified version of your series. You could then incorporate that change. One of the use cases I developed it for was collaborative development of a patch series.
(That workflow still needs a lot more tool assistance to become fully usable, not least of which to assist with the process of merging changes to the series. Working on that.)
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Stefan BellerQuoted 9 lines · Stefan Beller
Quoted 2 lines · Johannes Schindelin
Yet another option would be to have a tool that integrates with the Git repository of the Git mailing list represented by public-inbox.
So my first reaction to that would be: you could push you patches to that public inbox and it is translated to emails sent on your behalf.
Which is reinventing submitGit just in a more accessible language?
Maybe vger.kernel.org could open its submission (587) port like
Debian does. Unfortunately, this hurts the ability to Cc:
folks directly and makes vger even more of an SPOF
(I guess submitGit also has this problem)
Fwiw, I have a public-inbox for my miscellaneous patch barf at [email protected] - https://80x24.org/spew/
http://ou63pmih66umazou.onion/spew/
I will throw up my untested/half-tested patches for various projects so I can still access it across various NATs and firewalls.
Using Tor for send-email often works (depending on which blacklists the exit node is on), but is totally optional (you'd expose your IP).
==> ~/bin/spew <==
#!/bin/sh
exec torsocks git send-email \
--smtp-domain=80x24.org \
--smtp-debug=1 \
--smtp-server-port=submission \
--smtp-server=80x24.org \
--to ${[email protected]} \
--suppress-cc=all \
"$@"All: Feel free to use it for any Free Software projects, too; or better yet, host your own :)
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Stefan BellerHi Stefan,
just quickly (i.e. addressing only one point, will try to address more at a later date) because I want to be mostly offline this weekend:
Quoted 8 lines · Stefan Beller
Quoted 3 lines · Johannes Schindelin
I also hate to break it to you that git-send-email is not going to be part of any solution.
It's written in perl, so it's not one of the core parts of Git that you mentioned above. I do use it though for my submission process.
The problem is not Perl, but how fiddly it is to set up. And that you lose all the niceties of an email client (e.g. when you want to add a comment before the diff stat that is not intended to become a part of the commit message).
But I had an apostrophe last night. I might have been a bit overzealous to claim that git-send-email won't be a part of the solution. It cannot be a *user-visible* part of any solution, that still holds true.
So here is the apostrophe: why not implement a bot that listens to the PRs on GitHub, and accepts commands such as "@<whatever>bot please send this upstream" via comments on the PR. It would then send the patches to the list, from its own email address, on behalf of the contributor.
Lots of things to kink out, such as: does it need to be moderated? Record what was submitted in its own git.git fork? Accept replies and attach them to the correct PR? Maybe annotate those replies with the commits whose patches were discussed? Maybe send out replies on the PR as emails? Maybe try to auto-apply suggested patches? Cc: people who commented on earlier iterations of the patch series? Maybe make interaction smarter using an AI bot framework?
If only I had lots of time on my hand, I'd start by prototyping a node.js server and hooking it up via webhooks, then show it off so others can tinker with it.
This is not completely unlike submitGit, which was a good first attempt, but I never used it because I needed it to do so much more than it already did, *and* it complicated everything by requiring users to register with an extra step to allow submitGit to send email on their behalf. It also made contributing to it harder by choosing some non-standard web app framework. Also, I really do not like having to go to a different website just to send a GitHub PR to the list.
Anyway, that was my brain fart for the day.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 4 lines · Johannes Schindelin
The problem is not Perl, but how fiddly it is to set up. And that you lose all the niceties of an email client (e.g. when you want to add a comment before the diff stat that is not intended to become a part of the commit message).
Just this part. I do not think that is fair to send-email. You are blaming its "feature" that allows it to drive format-patch, which I do not consider is the proper part of the command and to which I kept saying from the early days of its introduction that I'd never use it and I think we should discourage its use exactly because it encourages a bad workflow (i.e. you skip the final proof-reading before sending out, and you cannot add footnote comments).
Treat it like an MSA just like Thunderbird, just designed to be more suited to send out patches without corruption, and you will be OK. You work, commit and write your message with your favourite editor, do format-patch, reword or add footnote with your favourite editor, and then send it out. You can avoid letting other MSAs that may corrupt whitespaces touch what you will send out if you used send-email, but that is not mandatory. As long as your favourite MSA does not corrupt your message, you can use it.
Somebody mentioned "configuring it is hard--why does the user have to know SMTP subtleties", and that may be a valid complaint against the primary part of send-email. The solution for that is not to discard it with bathwater, but make it just as easy as other MSAs, say, Thunderbird, to configure for an average user who can configure these other MUAs.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 6 lines · Junio C Hamano
Somebody mentioned "configuring it is hard--why does the user have to know SMTP subtleties", and that may be a valid complaint against the primary part of send-email. The solution for that is not to discard it with bathwater, but make it just as easy as other MSAs, say, Thunderbird, to configure for an average user who can configure these other MUAs.
Sadly, the average user does not use an MUA, SMTP or IMAP, anymore. It's all webmail or apps using proprietary protocols. Embrace, extend, extinguish :<
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi,
Quoted 11 lines · Eric Wong
Quoted 6 lines · Junio C Hamano
Somebody mentioned "configuring it is hard--why does the user have to know SMTP subtleties", and that may be a valid complaint against the primary part of send-email. The solution for that is not to discard it with bathwater, but make it just as easy as other MSAs, say, Thunderbird, to configure for an average user who can configure these other MUAs.
Sadly, the average user does not use an MUA, SMTP or IMAP, anymore. It's all webmail or apps using proprietary protocols. Embrace, extend, extinguish :<
I think you both got it wrong. The original citizens were the mail clients that allowed you to communicate with other human beings. Webmail is just a new generation of the same commodity. It is our usage to transport machine-readable content (and not as an attachment!) that is the intruder.
It's not making things better if we require users to use a second mail client for sending out patches, and, oh, it does nothing to help with reintegrating patches back into Git, were they had been before taking that perilous and lossy journey through that medium called email.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 4 lines · Johannes Schindelin
I think you both got it wrong. The original citizens were the mail clients that allowed you to communicate with other human beings. ... It is our usage to transport machine-readable content (and not as an attachment!) that is the intruder.
It is not "its is our usage".
You are too young to remember or too old to remember the history, or you are knowingly distorting it. The original users of "patch" and "diff" expected that e-mail to be a medium to safely exchange changes to programs among themselves.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Junio,
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
I think you both got it wrong. The original citizens were the mail clients that allowed you to communicate with other human beings. ... It is our usage to transport machine-readable content (and not as an attachment!) that is the intruder.
Quoted 6 lines
It is not "its is our usage".
You are too young to remember or too old to remember the history, or you are knowingly distorting it. The original users of "patch" and "diff" expected that e-mail to be a medium to safely exchange changes to programs among themselves.
If you are saying that transporting patches via email was the original purpose of email, then it is not exactly I who is misremembering history.
But that is not what you meant, I believe. You probably wanted to point out that the Git developers are not the first ones to abuse the medium known as email that way. And you are correct, of course. And I never claimed anything else. I just said that the problem is our usage of emails as a means to transport byte-exact content intended primarily to be consumed by a program instead of a human. It does not matter whether others did that before us. It is the problem we face right now, that is the important part of my message.
And even if it seems as if you are eagerly defending this system, I do not believe even a microsecond that you think it is a good system. I believe that you, too, would welcome a better review/contribution system that is easier to use, more welcoming to new users, less error-prone and less time-wasting than the current, email-based one, just like you jumped on Git as a better SCM when it came around, from whatever inadequate system you came from.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Johannes SchindelinQuoted 53 lines · Johannes Schindelin
Hi Stefan,
just quickly (i.e. addressing only one point, will try to address more at a later date) because I want to be mostly offline this weekend:
Quoted 8 lines · Stefan Beller
Quoted 3 lines · Johannes Schindelin
I also hate to break it to you that git-send-email is not going to be part of any solution.
It's written in perl, so it's not one of the core parts of Git that you mentioned above. I do use it though for my submission process.
The problem is not Perl, but how fiddly it is to set up. And that you lose all the niceties of an email client (e.g. when you want to add a comment before the diff stat that is not intended to become a part of the commit message).
But I had an apostrophe last night. I might have been a bit overzealous to claim that git-send-email won't be a part of the solution. It cannot be a *user-visible* part of any solution, that still holds true.
So here is the apostrophe: why not implement a bot that listens to the PRs on GitHub, and accepts commands such as "@<whatever>bot please send this upstream" via comments on the PR. It would then send the patches to the list, from its own email address, on behalf of the contributor.
Lots of things to kink out, such as: does it need to be moderated? Record what was submitted in its own git.git fork? Accept replies and attach them to the correct PR? Maybe annotate those replies with the commits whose patches were discussed? Maybe send out replies on the PR as emails? Maybe try to auto-apply suggested patches? Cc: people who commented on earlier iterations of the patch series? Maybe make interaction smarter using an AI bot framework?
If only I had lots of time on my hand, I'd start by prototyping a node.js server and hooking it up via webhooks, then show it off so others can tinker with it.
This is not completely unlike submitGit, which was a good first attempt, but I never used it because I needed it to do so much more than it already did, *and* it complicated everything by requiring users to register with an extra step to allow submitGit to send email on their behalf. It also made contributing to it harder by choosing some non-standard web app framework. Also, I really do not like having to go to a different website just to send a GitHub PR to the list.
Quoted 1 line
Anyway, that was my brain fart for the day.
Great discussion! I would like to share my perspective a someone who is a (relatively speaking) new Git contributor and who has never interacted on mailing lists before Git:
1.) "git format-patch" and "git send-email" work great for me. It took some
time to learn how they work but now I have my own "submit.sh" based on those tools and posting a new series is a piece of cake.
2.) Initially it was hard for me to ensure that my patches don't break build or
tests on Linux and OS X. Travis CI helps me a lot. I just wished we could get Windows support, too.
3.) I noticed that I get two types of reviews. The first kind points out things
in my patch that are obviously wrong. The second kind are things that require a discussion. When I get feedback of the first kind, then I am always super eager to send out a new roll just because I don't want any other reviewer to waste time on obviously wrong patches. However, I have the impression that frequent re-rolls are frowned upon. If we would use Git for the patches instead of email, then I could add "squash" patches to indicate changes in the current roll that will be squashed in the next roll (I know I could send squash patches as email, too... but for me that gets confusing quickly).
4.) Reviewing patches is super hard for me because my email client does not
support patch color highlighting and I can't easily expand context or look at the history of code touched by the patch (e.g via git blame). I tried to setup Alpine but I wasn't happy with the interface either. I like patches with a GitHub URL for review but then I need to find the right line in the original email to write a comment.
Again, this is just my point of view as a "newbie" and I definitively don't expect the Git community to change their established workflows.
Cheers,
Lars
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 4 lines · Lars Schneider
... then I am always super
eager to send out a new roll just because I don't want any other reviewer to waste time on obviously wrong patches. However, I have the impression that frequent re-rolls are frowned upon.
Correct. A good middle-ground is to just reply with "Yes, thanks for your suggestion, will fix in the next round", while receiving review comments. Good reviewers who value their time will not to waste their time by responding on a point that has already been pointed out and acknowledged.
Quoted 6 lines
4.) Reviewing patches is super hard for me because my email client does not
support patch color highlighting and I can't easily expand context or look at the history of code touched by the patch (e.g via git blame). I tried to setup Alpine but I wasn't happy with the interface either. I like patches with a GitHub URL for review but then I need to find the right line in the original email to write a comment.
Unless a patch is about an area you are super familiar with so that you know what is beyond the context of the patch to be able to judge if the change is good in the context of the file being touched, it is always hard to review from inside a mail reader.
Running "git am" is a good first step to review such a patch, as that lets you view the resulting code with the full power of Git. As you gain experience on the codebase, you'll be able to spot more problems while in your mail reader.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 7 lines · Lars Schneider
4.) Reviewing patches is super hard for me because my email client does not support patch color highlighting and I can't easily expand context or look at the history of code touched by the patch (e.g via git blame). I tried to setup Alpine but I wasn't happy with the interface either. I like patches with a GitHub URL for review but then I need to find the right line in the original email to write a comment.
Unless a patch is about an area you are super familiar with so that you know what is beyond the context of the patch to be able to judge if the change is good in the context of the file being touched, it is always hard to review from inside a mail reader.
Quoted 4 lines
Running "git am" is a good first step to review such a patch, as that lets you view the resulting code with the full power of Git. As you gain experience on the codebase, you'll be able to spot more problems while in your mail reader.
I am glad that you agree that the requirement to manually transform the patches back into Git (where they had been originally to begin with) is cumbersome. This is the first time that I see you admit it ;-)
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Johannes Schindelin
Quoted 5 lines · Junio C Hamano
Unless a patch is about an area you are super familiar with so that you know what is beyond the context of the patch to be able to judge if the change is good in the context of the file being touched, it is always hard to review from inside a mail reader.
Quoted 8 lines
Quoted 4 lines
Running "git am" is a good first step to review such a patch, as that lets you view the resulting code with the full power of Git. As you gain experience on the codebase, you'll be able to spot more problems while in your mail reader.
I am glad that you agree that the requirement to manually transform the patches back into Git (where they had been originally to begin with) is cumbersome. This is the first time that I see you admit it ;-)
I was about to apologize for writing a statement that can be misread, but I do not think what I wrote can be misinterpreted, even if a reader deliberately tries to twist the words s/he reads, to lead to such a conclusion, so I won't.
I merely said that reviewing a change in an unfamiliar area is harder (not "cumbersome", but "needs understanding first") with a patch, and it is easier to see changes in context by applying (which is an easy, not "cumbersome", process).
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Johannes SchindelinQuoted 11 lines · Johannes Schindelin
Quoted 1 line · Stefan Beller
git send-email/format-patch recently learned to include a base commit
You may have noticed that my mail-patch-series.sh-generated code submissions contain that base commit. But they still do not contain the SHA-1s of my local commits corresponding to the patches, and even if they did, the replies with suggested edits would most likely have lost said information.
I also hate to break it to you that git-send-email is not going to be part of any solution.
I think it ought to be. Some reasons I like emailing patches are:
* there's no taking it back once it's sent
* it's backed up within seconds by thousands of subscribers :)
* doesn't require the reader to have an active connection to fetch out-of-band
* doesn't require the reader to be on the same machine capable of cloning/building the project
There are times when I've been on a slow machine, or offline when I wanted to read some patches.
However, I do like including a pull request in cover letters of a patch series (not necessary for one-offs).
But on a side note, I also find it depressing that SMTP is uncompressed and TLS compression is (still?) unsafe. At least I use ssh tunnels w/ compression for IMAP/SMTP to my own server.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Eric,
Quoted 10 lines · Eric Wong
Quoted 9 lines · Johannes Schindelin
Quoted 1 line · Stefan Beller
git send-email/format-patch recently learned to include a base commit
You may have noticed that my mail-patch-series.sh-generated code submissions contain that base commit. But they still do not contain the SHA-1s of my local commits corresponding to the patches, and even if they did, the replies with suggested edits would most likely have lost said information.
Quoted 6 lines
Quoted 2 lines
I also hate to break it to you that git-send-email is not going to be part of any solution.
I think it ought to be. Some reasons I like emailing patches are:
[...]
What I said is that *git-send-email* is not going to be part of any solution.
Note that I said *git-send-email*, not "emailing patches".
What many people on this list forget is that few email users *ever* touch their email configuration. Asking them to figure out their SMTP settings and then to make git-send-email work is, uhm, quite a bit unrealistic.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Stefan BellerQuoted 10 lines · Stefan Beller
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
Quoted 8 lines
I did not propose to use Gerrit or git-series or git appraise.
However whenever I see these projects talking to each other, the talk focuses on a "unified review storage format" pretty often, which would make them compatible with each other. So then I could choose git-series, while you could go with git appraise (although that is written in go, so maybe too fancy already ;) Or there could be another new program written in C that follows the "review format".
This "unified review storage format" really does seem to be the missing piece. The tool I've been working on for the past year (git-candidate) was initially aimed at contrib[1], and was written in perl solely to satisfy contrib rules. It would have been python otherwise.
The feedback from that thread[1], was that while git-candidate itself seemed interesting it would be unreasonable to bless a particular tool's format. So it seems to me that even if git-series had been written in perl rather than rust it could have expected a similar response to that of git-candidate, possibly.
As Stefan says, if we're able to establish a standard for storing review data in git then it doesn't really matter what the tools are written in.
For what it's worth my possibly quite shoddy attempt at a library implementing a possible review format for git[2] is written in perl, mostly to satisfy contrib requirements.
Quoted 8 lines
Quoted 8 lines
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
And when I said I have zero interest in tools that use the "latest and greatest language", I was hinting at git-series. Rust may be a fine and wonderful language. Implementing git-series in Rust, however, immediately limited the potential engagement with developers dramatically.
Ironically contrib's language requirements actually raised the bar for me because it meant that I had to learn perl.
Quoted 5 lines
Quoted 5 lines
Additionally, I would like to point out that defining a way to store reviews in Git is not necessarily improving the way our code contribution process works. If you want to record the discussions revolving around the code, I think public-inbox already does a pretty good job at that.
I agree, and must apologise if this response has been too off topic, in any case I hope at least some of it was useful to someone.
Hope this helps,
Richard Ipsum
[1]: http://www.mail-archive.com/git%40vger.kernel.org/msg80972.html
[2]: https://bitbucket.org/richardipsum/perl-notedb
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Richard,
Quoted 20 lines · Richard Ipsum
Quoted 10 lines · Stefan Beller
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines
If we were to change our workflows drastically, I'd propose to go a way[1] similar to notedb in Gerrit, or git-series,
Gerrit is a huge, non-distributed system. Complex, too. If we change the patch submission process, we should make things *easier*, not *harder*. So I think Gerrit is pretty much out of the question.
Quoted 8 lines
I did not propose to use Gerrit or git-series or git appraise.
However whenever I see these projects talking to each other, the talk focuses on a "unified review storage format" pretty often, which would make them compatible with each other. So then I could choose git-series, while you could go with git appraise (although that is written in go, so maybe too fancy already ;) Or there could be another new program written in C that follows the "review format".
Quoted 2 lines
This "unified review storage format" really does seem to be the missing piece.
FWIW I do not think so. The real trick will be to come up with an improvement to the process that lets Junio and Peff continue to work as before, because It Works For Them, while at the same time letting other people (such as myself) use easy-to-configure tools that add substantial convenience.
Which, to me, means that the missing piece is a clever idea how to integrate with the mail-based process, without requiring everybody and her dog to switch to a specific mail client.
Quoted 3 lines
The tool I've been working on for the past year (git-candidate) was initially aimed at contrib[1], and was written in perl solely to satisfy contrib rules. It would have been python otherwise.
Oh...?
$ git ls-files contrib/\*.py | wc -l 4
And for that matter:
$ git ls-files contrib/\*.go | wc -l 4
In fact, there are even PHP scripts:
$ git ls-files contrib | sed -n 's/.*\.//p' | sort | grep -v '.....' | uniq | tr '\n' ' ' bash c el Git go perl php pl pm py rst sh tcsh txt zsh
But again, I do not think that it makes sense to focus too much on a language, or on a file format, before we came up with a strategy how to *not* require everybody to change their current ways.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
On Fri, Aug 05, 2016 at 05:24:14PM +0200, Johannes Schindelin wrote:
[snip]
Quoted 10 lines
Quoted 3 lines
This "unified review storage format" really does seem to be the missing piece.
FWIW I do not think so. The real trick will be to come up with an improvement to the process that lets Junio and Peff continue to work as before, because It Works For Them, while at the same time letting other people (such as myself) use easy-to-configure tools that add substantial convenience.
Quoted 3 lines
Which, to me, means that the missing piece is a clever idea how to integrate with the mail-based process, without requiring everybody and her dog to switch to a specific mail client.
Fair enough, yes it seems to me that git's own review process is probably a separate discussion.
As far as review tools such as git-appraise, git-series and git-candidate are concerned, the review storage format really is the missing piece though, in my opinion,
at least if we want to live in a world with compatible review tooling.
Quoted 7 lines
Quoted 4 lines
The tool I've been working on for the past year (git-candidate) was initially aimed at contrib[1], and was written in perl solely to satisfy contrib rules. It would have been python otherwise.
Oh...?
Quoted 7 lines
$ git ls-files contrib/\*.py | wc -l 4And for that matter:
$ git ls-files contrib/\*.go | wc -l 4
I read this guide[1] before I started, and wanted to be on the safe side. Maybe that was a mistake... :/
Quoted 10 lines
In fact, there are even PHP scripts:
$ git ls-files contrib | sed -n 's/.*\.//p' | sort | grep -v '.....' | uniq | tr '\n' ' ' bash c el Git go perl php pl pm py rst sh tcsh txt zshBut again, I do not think that it makes sense to focus too much on a language, or on a file format, before we came up with a strategy how to *not* require everybody to change their current ways.
Fair enough. :)
Thanks,
Richard Ipsum
[1]: https://www.kernel.org/pub/software/scm/git/docs/howto/new-command.html
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Johannes SchindelinQuoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]
Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
* Many, MANY of the most prominent open-source projects are already using GitHub. Many potential contributors already know how to use it and already have accounts. Casual observers (e.g., people who only want to clone the repo and/or read issues and PRs) don't even need an account.
* Even if you don't already have a GitHub account, it is vastly easier to create one than to set up our current contribution workflow: figure out the correct SMTP settings for your email provider, configure git-send-email, test it and work out the kinks, figure out how to use git-am (and even then, actually using git-am is a tedious chore for people who don't use an email client that can run it automatically) [1]. We've seen how difficult our current workflow is by observing GSoC candidates attempting to send their first patch. What we haven't seen is the invisible GSoC candidates and other potential contributors who never even get as far as attempting to send a patch.
* Interactions that involve code are done using Git commands directly, via exchanging bona fide Git commits. Which means that...
* Commits have unambiguous SHA-1s, which we can use when discussing them, linking to them, merging them, etc. It will no longer be a matter of detective work to find out whether a discussion is about v1 or v3 of a patch series, let alone v3 with some cleanups that were silently added by Junio.
* Discussion of pull requests can be done either
* via the website (super easy for beginners but powerful for
experienced users),
* by setting up email notifications for your account and replying to
those emails, or
* via an API.
Such discussion is all in markdown, which supports light formatting,
hyperlinks, and @-mentions.
* GitHub creates permalink URLs for all of the important artifacts:
commits, pull requests, pull request comments, etc. These all can be referenced easily from any discussion. This web of cross-links accumulates over time and adds a lot of context to discussions.
* GitHub keeps spam under control.
I admit that if we move to GitHub we would be vulnerable if the company turns evil or goes bankrupt. But is that really a bigger risk than we accepted by relying on Gmane (a one-person hobbyist operation) for many of our historical permalinks, which are now broken? In any case, each of us has a mirror of the code, and there are utilities for backing up other GitHub metadata. *If* GitHub becomes evil, there will be a lot of other open-source projects in the same boat, so I am confident that the tooling for salvaging such information will quickly become excellent.
Currently we force potential Git contributors to learn an email-based workflow that is almost unique to this project, rather than steering them towards a workflow (Git plus, potentially, GitHub) that they probably already know, or if not is worth learning because the knowledge will carry across to most other open-source projects, not to mention their professional careers.
We would want to set down guidelines for how we use GitHub. For example, we might insist that each version of a patch series (v1, v2, etc.) be submitted as a fresh pull request with references to the previous version(s) (which also automatically creates forwards links from the previous versions to the new version). We might want to set up some robots to help with repetitive activities, like style review, pinging the right people, etc.
Junio, I'm very sensitive to the need not to decrease your efficiency. But isn't there a chance that this could *increase* your efficiency? Is it worth an experiment?
Is the Git project really such a unique snowflake that we need to use a workflow (and force it on our contributors) that is different than the workflows used by most other open-source projects?
Disclaimer: I work for GitHub, but in this email I'm speaking for myself.
Michael
[1] I concede that people who refuse on ideological grounds to use proprietary software will find this step insurmountable. Perhaps we could come up with a workaround for such people.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 2 lines · Michael Haggerty
Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
I only know how "pull requests" and "issues" discussion in GitHub Web interface _currently_ looks like, so if you have even more wonderful thing in the works, I _might_ be swayed otherwise, but I do not think it is sane to expect that the same quality and quantity of reviews as we do here can be maintained with that thing.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Michael Haggerty
Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
I only know how "pull requests" and "issues" discussion in GitHub Web interface _currently_ looks like, so if you have even more wonderful thing in the works, I _might_ be swayed otherwise,
If I did I couldn't say anyway, so let's assume that current GitHub is what's on the table [1].
There are a couple of recent code-review improvements that you might have missed:
* You can now get email updates about your own activity [2]. (Previously you would only get emails about the activity of other people, which would leave holes in the email record of the conversation.)
* There is also now better visibility of code review comments regarding lines that are no longer part of a PR [3].
Quoted 3 lines
but I
do not think it is sane to expect that the same quality and quantity of reviews as we do here can be maintained with that thing.
Could you elaborate why you would expect quality and/or quantity of reviews to suffer? I'm really curious, and I'd be happy to pass your feedback along to my colleagues.
Here are some factors that I think will *improve* reviews:
* While you are reviewing patches, you can "zoom out" to see code beyond the usual diff context. Currently a reviewer who wants more context has to transition from reading the diff in email to applying the patch and viewing it in another tool. Then the reviewer has to go back to email to leave the comment.
* If you want to compile/run/edit/profile the code, you just need to "git fetch" rather than messing around with "git am". For more involved suggestions, it is possible to propose a PR against the original PR.
* It is easy to summon somebody else into the review conversation by @-mentioning them. That person immediately can see the whole history of the PR. (This is an improvement on the status quo, where a new entrant to a conversation might have to dig through the email trash or an email archive to see emails that they overlooked before they were added to the CC list.)
* It is easy to subscribe/unsubscribe from particular discussions [4]. This makes it easier to follow the discussions you are interested in without getting swamped with emails about other discussions. You can unsubscribe from a discussion permanently, or in such a way that a new @-mention brings you back in.
* It is easy to mention other PRs/commits/issues in a discussion, and those mentions become clickable links (no jumping back and forth between email client and web browser). Of course you can also link to arbitrary URLs (e.g., mailing list archives).
* It is possible to search old issues and PRs for additional context. (Granted, the history of the project from its ML era would have to be searched separately.)
Given that I work for GitHub, I'm uncomfortable doing any more advocacy here. If people have concrete questions, I'd be happy to answer them, on the list or in private.
Michael
[1] In general, GitHub *does* get better over time, and we would benefit from any future improvements.
[2] https://github.com/blog/2203-email-updates-about-your-own-activity
[3] https://github.com/blog/2123-more-code-review-tools
[4] https://github.com/blog/2183-improvements-to-notification-emails
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Michael Haggerty venit, vidit, dixit 09.08.2016 01:20:
Quoted 3 lines
Given that I work for GitHub, I'm uncomfortable doing any more advocacy here. If people have concrete questions, I'd be happy to answer them, on the list or in private.
You're doing a great job differentiating between your roles as a member of the Git devel community and as a GitHub employee, so please keep the discussion here.
Maybe two more points of input for the discussion:
off-line capabilities
=====================
The current workflow here seems to work best when you are subscribed to the git-ml and have your own (local, maybe selective) copy of git-ml in your (text-based) MUA (mutt, (al)pine, emacs, ...) that can jump right into git-am and such directly. I'm not sure how important the "off-line" aspect of that is for some of us, and how that could be replicated on GitHub - while PRs and such may be Git based behind the scenes there seems to be no way to clone that info and work from a local clone. (Don't know if GitLab is more open.)
My own setup
============
My usual MUA is Thunderbird because of its integration with calendars and address books. I usually read and post to mailing lists via nntp/gmane, that works best for me for several reasons (e.g. archive available when I need it).
For git-ml, I had to learn early on to answer by e-mail to git-ml rather than by nntp-reply because proper nntp-replies somehow didn't meet the expectations of the e-mail users (double copies because of the cc-policy or such, I don't remember).
I use git sendemail even for small throw-in patches because the git-ml does not allow attachments but wants patches (files) as in-line text, and Thunderbird possibly reformats text (because it's text, you know).
When I want to try out a proposed patch I have to "save message" and run git-am because patches don't come as file attachments on the git-ml (can't use "save/open attachment"+ git-apply) nor a PR (can't use git fetch nor view in browser). If it's a series, I have to do that for each invididual patch, which usually means I simply don't (or rely on Junio doing it and fetch his xy/topic branch).
And more often than not, patches from series do not appear in sequence, not threaded on top of the cover letter (in the gmane nntp version of git-ml), and it usually happens for the same people again and again, which tells me it's a git sendemail config issue and not gmane.
So really, everytime I interact with the git-ml I think about switching to mutt or such just for git-ml, even though over time I have gotten used to the number of hoops that I have to jump through if I want to interact with git-ml.
Suggestion
==========
Maybe the current gmane woes are a good reason to try out something different for a month or two, with copies to the git-ml, and with the default being to revert back to git-ml after that and discuss what we've learned. As a result we may improve our workflow here, get GitHub to improve, and maybe switch or not. Either way we could profit from that.
Michael
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 5 lines · Michael J Gruber
Maybe two more points of input for the discussion:
off-line capabilities
=====================
Quoted 8 lines
The current workflow here seems to work best when you are subscribed to the git-ml and have your own (local, maybe selective) copy of git-ml in your (text-based) MUA (mutt, (al)pine, emacs, ...) that can jump right into git-am and such directly. I'm not sure how important the "off-line" aspect of that is for some of us, and how that could be replicated on GitHub - while PRs and such may be Git based behind the scenes there seems to be no way to clone that info and work from a local clone. (Don't know if GitLab is more open.)
You can pull it all out via GitHub's HTTP API, but the question is what format you would use to store it locally (and which tools you would then use to play with it).
I haven't really tried this lately, though, so I don't know if there is information that the API would be missing.
I do have a dream of writing a tool that sucks in GitHub PRs to a fake email thread, lets me make my responses inline in an editor, and then pushes it back up as PR comments (finding the right positions based on the quoted context).
Quoted 4 lines
For git-ml, I had to learn early on to answer by e-mail to git-ml rather than by nntp-reply because proper nntp-replies somehow didn't meet the expectations of the e-mail users (double copies because of the cc-policy or such, I don't remember).
At least some people's workflows seem to send two copies to the list. For instance, Jakub's <[email protected]> got delivered to me via the list twice. Once directly from gmail with:
To: Oleg Taranenko <[email protected]>,
Junio C Hamano <[email protected]>
Cc: [email protected]
and once via gmane with:
To: [email protected]
Cc: [email protected]
It's like this with all of his messages (sorry I can't point to the duplicates in an archive; they have the same message-id, so public-inbox treats them as a single unit).
Replying to the second one breaks the usual "cc-everybody" rule. Sending duplicates means everybody sees it twice (3 times if they're on the cc list!), and the second copy still has the bogus headers (so people replying need to pick the right one).
Quoted 3 lines
I use git sendemail even for small throw-in patches because the git-ml does not allow attachments but wants patches (files) as in-line text, and Thunderbird possibly reformats text (because it's text, you know).
I wonder if this is something we could change. I do not personally have any problem with attached patches. "git am" knows how to apply them, and mutt is smart enough to show text/* by default, and to include it in quoted text on reply. So the output of "git format-patch --attach" works fine for me. But it may not be as nice in other MUAs, and we have to care about all of the other reviewers.
Quoted 6 lines
When I want to try out a proposed patch I have to "save message" and run git-am because patches don't come as file attachments on the git-ml (can't use "save/open attachment"+ git-apply) nor a PR (can't use git fetch nor view in browser). If it's a series, I have to do that for each invididual patch, which usually means I simply don't (or rely on Junio doing it and fetch his xy/topic branch).
So you would like the opposite of my dream tool, I think: something that takes mailing list conversations and turns them into PRs.
(My real dream is actually to have a bidirectional version of the tool, so that everybody can use whatever interface they like, and nobody has to care about somebody else's preferences).
Quoted 4 lines
And more often than not, patches from series do not appear in sequence, not threaded on top of the cover letter (in the gmane nntp version of git-ml), and it usually happens for the same people again and again, which tells me it's a git sendemail config issue and not gmane.
Just a guess, but I suspect this is caused by people who use "rebase -i" to rearrange patches. When format-patch writes out the patches, it uses the author date as the "Date" field, which means it may be out of order. I think send-email will always write out a new, monotonically increasing date. But I suspect other workflows (e.g., imap-send and then mailing from a MUA) blindly re-use that date.
Quoted 8 lines
Suggestion
==========Maybe the current gmane woes are a good reason to try out something different for a month or two, with copies to the git-ml, and with the default being to revert back to git-ml after that and discuss what we've learned. As a result we may improve our workflow here, get GitHub to improve, and maybe switch or not. Either way we could profit from that.
I think public-inbox is a nice step forward on the reading side (it's a lot easier to get raw patches out of it, for example). But it doesn't help much with sending (and sending is a tricky subject; anytime you promise to send mail on behalf of somebody, you're going to attract spammers).
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 20 lines · Jeff King
Quoted 5 lines · Michael J Gruber
Maybe two more points of input for the discussion:
off-line capabilities
=====================Quoted 8 lines
The current workflow here seems to work best when you are subscribed to the git-ml and have your own (local, maybe selective) copy of git-ml in your (text-based) MUA (mutt, (al)pine, emacs, ...) that can jump right into git-am and such directly. I'm not sure how important the "off-line" aspect of that is for some of us, and how that could be replicated on GitHub - while PRs and such may be Git based behind the scenes there seems to be no way to clone that info and work from a local clone. (Don't know if GitLab is more open.)
You can pull it all out via GitHub's HTTP API, but the question is what format you would use to store it locally (and which tools you would then use to play with it).
Quoted 7 lines
I haven't really tried this lately, though, so I don't know if there is information that the API would be missing.
I do have a dream of writing a tool that sucks in GitHub PRs to a fake email thread, lets me make my responses inline in an editor, and then pushes it back up as PR comments (finding the right positions based on the quoted context).
You might try https://github.com/joeyh/github-backup
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Michael HaggertyQuoted 7 lines · Michael Haggerty
Quoted 3 lines
but I
do not think it is sane to expect that the same quality and quantity of reviews as we do here can be maintained with that thing.Could you elaborate why you would expect quality and/or quantity of reviews to suffer? I'm really curious, and I'd be happy to pass your feedback along to my colleagues.
Having done a lot of review here on the mailing list, as well as in GitHub PRs, I vastly prefer the mailing list.
Here's a random list of things that I think I would miss:
- I really like the flow of having the commit message and diff dumped in my editor. I'm very efficient at slicing and dicing text, omitting uninteresting quoted bits, etc.
Web text boxes feel like a straitjacket. I do have a browser plugin that opens them in vim. That helps, but it breaks the flow (I make a comment, save the file, click "comment", then read to the next place, click "+", then start a new vim instance for that comment). Besides the tedium of clicking around, it loses the "unit" size of a single email, where I may make many comments, go back and revise earlier comments after reading more of the patch, etc.
- I really like the flow of having conversations next to patches. I can look at the index of the mailing list folder and see what people are talking about, how big the threads are, etc, at a glance. Moving between messages and threads involve single keystrokes.
Similarly, having local storage is _fast_. I think GitHub is fine for a web app. But when I'm reading a high-volume mailing list, I really want to flip around quickly. If there's even 500ms to get to the next message or thread, it feels clunky and slow to me. Obviously I spend more than 500ms _reading_ most messages (though for some I see the first paragraph and immediately jump away). It's just the latency when I've decided I'm done with one thing and want to move to the next.
- For that matter, GitHub doesn't really have a good tool for random conversations. There are issues, which you can vaguely use like a thread, but it doesn't quite feel the same.
I think part of it is that I can view the mailing list both as a series of threads _and_ as a stream of messages. So sometimes I mark a thread as "read", and then see the next day that there are a ton of new messages on it. Maybe those are uninteresting (and it's a single keystroke to mark the thread again), but maybe that's a hint that there's interesting discussion going on.
The threading in GitHub comments and pull requests is also not great. Each PR or issue is its own thread, but it's totally flat inside. There are no sub-threads to organize discussion, and it's sometimes hard to see what people are replying to.
- When I move between a discussion and patches on the list and my local git checkout, it's important to do so with minimal fuss. Which means I want to use _context_ in my workflow. If I'm reading a thread, I want there to be a keystroke for "jump to this thread in my checkout". That's (relatively) easy for me to script via mutt (grab these patches, apply them). It's a bit harder in the browser (the best I've got is to copy-paste the URL to a script that pulls out the PR number, then fetches and checks it out).
- A sort-of feature: the mailing list is actually fairly decentralized, because of the "reply-to-all" convention. I don't know if anybody else noticed, but vger seemed to be down Friday evening and Saturday morning (at least my messages to the list got 400 SMTP codes, and no new messages were delivered to me). But I still had some conversations going with people, because our messages were mailed directly (and the list eventually caught up).
Now that probably doesn't matter for GitHub, which seems to have fairly reasonable uptime. It would matter if we picked a centralized tool that didn't.
There are probably more, but I've run out of ranting steam for now. :)
Quoted 1 line
Here are some factors that I think will *improve* reviews:
I was going to respond point-by-point to a few of these, but I think I covered most of it above. In short, I agree with many of the benefits you list. In most cases, I've already reaped those benefits for my own workflow (e.g., my "git am" workflow is pretty efficient now). But not everybody has done so, and it's a lot to ask of casual contributors.
Quoted 3 lines
Given that I work for GitHub, I'm uncomfortable doing any more advocacy here. If people have concrete questions, I'd be happy to answer them, on the list or in private.
Hopefully I provided some counterpoint. ;)
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Jeff King <[email protected]> writes all what I wanted to say, and a lot more, so I don't have to say much ;-)
Quoted 5 lines
- I really like the flow of having conversations next to patches. I can look at the index of the mailing list folder and see what people are talking about, how big the threads are, etc, at a glance. Moving between messages and threads involve single keystrokes.
Quoted 8 lines
Similarly, having local storage is _fast_. I think GitHub is fine for a web app. But when I'm reading a high-volume mailing list, I really want to flip around quickly. If there's even 500ms to get to the next message or thread, it feels clunky and slow to me. Obviously I spend more than 500ms _reading_ most messages (though for some I see the first paragraph and immediately jump away). It's just the latency when I've decided I'm done with one thing and want to move to the next.
Viewing threads in a threaded mail client to help prioritizing various topics being discussed is what I value the most and I am not sure how I can be as efficient with the pull-request page.
Quoted 4 lines
The threading in GitHub comments and pull requests is also not great. Each PR or issue is its own thread, but it's totally flat inside. There are no sub-threads to organize discussion, and it's sometimes hard to see what people are replying to.
It may be a good UI that is optimized for drive-by contributors. It is just that it is not very well suited (compared to mailing list discussions) to conduct high-volume exchange of ideas and changes efficiently.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 9 lines · Junio C Hamano
Quoted 4 lines
The threading in GitHub comments and pull requests is also not great. Each PR or issue is its own thread, but it's totally flat inside. There are no sub-threads to organize discussion, and it's sometimes hard to see what people are replying to.
It may be a good UI that is optimized for drive-by contributors. It is just that it is not very well suited (compared to mailing list discussions) to conduct high-volume exchange of ideas and changes efficiently.
I think that's something to ponder; can we have a workflow where drive-by contributors can use something that has a lower learning/setup curve, but long-term contributors might opt for something more powerful?
I think SubmitGit is a step in that direction. It does still require switching to the mailing list for subsequent conversation, though. It would be interesting to see something like SubmitGit that puts its own email in the "From", and that processes email replies into PR comments, and then subsequent PR comments into emails (i.e., part of my "dream tool" from earlier). It's not clear to me whether the result would just end up being irritating for both sides to use (because it doesn't _quite_ conform to the norms of each format). But it would be fun to find out.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Jeff King
Quoted 4 lines · Junio C Hamano
It may be a good UI that is optimized for drive-by contributors. It is just that it is not very well suited (compared to mailing list discussions) to conduct high-volume exchange of ideas and changes efficiently.
Quoted 5 lines
I think that's something to ponder; can we have a workflow where drive-by contributors can use something that has a lower learning/setup curve, but long-term contributors might opt for something more powerful?
I think SubmitGit is a step in that direction.
Yes, agreed 100% with that. The author of the tool must be praised by getting added to the Cc: line in this discussion ;-)
Quoted 8 lines
It does still require
switching to the mailing list for subsequent conversation, though. It would be interesting to see something like SubmitGit that puts its own email in the "From", and that processes email replies into PR comments, and then subsequent PR comments into emails (i.e., part of my "dream tool" from earlier). It's not clear to me whether the result would just end up being irritating for both sides to use (because it doesn't _quite_ conform to the norms of each format). But it would be fun to find out.
Perhaps. I do not know if I like that second and subsequent steps for SubmitGit, but its first step as currently deployed I am very happy with.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Jeff KingQuoted 2 lines · Jeff King
That's (relatively) easy for me to script via mutt (grab these patches, apply them).
Could you share your mutt set up pleaaase? I've been wanting this for a long time, but never used mutt long enough to bother with a proper setup like this (I blame gmail).
Signature · 1 line
Duy
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Duy Nguyen
Quoted 2 lines · Jeff King
That's (relatively) easy for me to script via mutt (grab these patches, apply them).
Could you share your mutt set up pleaaase? I've been wanting this for a long time, but never used mutt long enough to bother with a proper setup like this (I blame gmail).
That is my complaint^H^H^H^H position, too.
I always wanted to switch to a more powerful
setup than git-send-email for sending /gmail for reading, but I could not convince myself the steep learning/setup curve is worth it eventually as it is "not broken enough" to do the change right now.
My experiments with mutts, have left these lines in my ~/.muttrc
Quoted 5 lines
# use shift + A to apply a patch in the working dir # macro index A ":unset pipe_decode\n|git am -3\n:set pipe_decode\n" # macro pager A ":unset pipe_decode\n|git am -3\n:set pipe_decode\n"macro index A ":set folder='.'\n:copy-message\n"
(IIRC they were broken for many patches, but I got applying one patch to work. Which sucks for long email series.)
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 11 lines · Stefan Beller
Quoted 3 lines
Could you share your mutt set up pleaaase? I've been wanting this for a long time, but never used mutt long enough to bother with a proper setup like this (I blame gmail).
That is my complaint^H^H^H^H position, too.
I always wanted to switch to a more powerful
setup than git-send-email for sending /gmail for reading, but I could not convince myself the steep learning/setup curve is worth it eventually as it is "not broken enough" to do the change right now.
I think I may have shared it before, but here is the script I use to send emails. It dumps you in mutt, and then I have:
macro index,pager b ":set edit_headers=yes<enter><resend-message>:set edit_headers=no<enter>"
to send the message ("b" is for "bounce", which I think may be another Pine-ism).
-- >8 --
#!/bin/sh
upstream_branch() {
current=git symbolic-ref HEAD
upstream=git for-each-ref --format='%(upstream)' "$current" if test -n "$upstream"; then
echo $upstream
else
echo origin
fi
}
get_reply_headers() {
perl -ne '
if (defined $opt) {
if (/^\s+(.*)/) {
$val .= " $1";
next;
}
print "--$opt=", quotemeta($val), " ";
$opt = $val = undef;
}
if (/^(cc|to):\s*(.*)/i) {
$opt = lc($1);
$val = $2;
}
elsif (/^message-id:\s*(.*)/i) {
$opt = "in-reply-to";
$val = $1;
}
elsif (/^subject:\s*\[PATCH v(\d+)/i) {
print "-v$1 ";
}
elsif (/^$/) {
last;
} '
}
has_nonoption=
for i in "$@"; do
case "$i" in
-[0-9]) has_nonoption=yes ;;
-*) ;;
*) has_nonoption=yes esac
done
git rev-parse || exit 1
: ${REPLY:=$HOME/patch}
test -e "$REPLY" && eval "set -- get_reply_headers <\"$REPLY\" \"\$@\"" test "$has_nonoption" = "yes" || set -- "$@" upstream_branch
git format-patch -s --stdout --from "$@" >.mbox
if test -t 1; then
mutt -e 'set sort=mailbox-order' -f .mbox
else
perl -lne '
if (/^Subject: (.*)/) {
$subject = $1;
}
elsif ($subject && /^\s+(.*)/) {
$subject .= " $1";
}
elsif ($subject) {
print $subject;
$subject = undef;
}
' .mbox |
sed -e 's/\[PATCH /[/' \
-e 's/]/]:/' \
-e 's/^/ /'fi
rm -f .mbox
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Duy NguyenQuoted 7 lines · Duy Nguyen
Quoted 2 lines · Jeff King
That's (relatively) easy for me to script via mutt (grab these patches, apply them).
Could you share your mutt set up pleaaase? I've been wanting this for a long time, but never used mutt long enough to bother with a proper setup like this (I blame gmail).
It's actually pretty simple. The relevant config from my .muttrc is:
macro pager,index D '<shell-escape>rm -f $HOME/patch<enter>' macro pager,index A '<copy-message>~/patch<enter><enter>'
I use "~/patch" as a rendezvous point, and then "git am ~/patch" from my other terminal. That avoids mutt having to know which repo to apply to, and keeps the "am" process in its own terminal (which is handy if it runs into conflicts, for example).
So generally I would "D" to clear out the contents of ~/patch, and then "A" whichever patches I want to apply. I often use mutt's aggregate selection for that. My bindings are:
bind index \; tag-pattern
bind index a tag-prefix
which I think come from pine (which I used for many years before switching to mutt probably 15 years ago). I don't recall the default keybindings.
Anyway, you can either tag using a pattern (with ";"), or tag mails individually (using "t", the default), and then "a-A" to apply the "A" to all of them (if you are in the habit of tagging all of them and then doing "A" in one swoop, you could also get rid of the separate "D" command and just make "A" imply it).
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Michael HaggertyQuoted 3 lines · Michael Haggerty
Could you elaborate why you would expect quality and/or quantity of reviews to suffer? I'm really curious, and I'd be happy to pass your feedback along to my colleagues.
Since I have been using github at work for a couple months, I do have a few complaints if it will ever become the way of reviewing things in git. Some of these may be covered by other people already (I haven't read all new mails in this thread yet)
- Github PRs seem to encourage seeing changes as a whole, not a
separate commits. Or at least it's not so convenient to view separate commits (e.g. not easy to go to the next commit)
- The ability to show all outdated comments, in case I want to search
through them.
- I have a feeling that commits in PRs are sorted by authordate, not
in topological order. The order of commits being committed is important sometimes.
- Not showing leading spaces mixing with TABs, or trailing spaces
- I would love to have all patches numbered so can refer to them as
1/7, 2/5... instead of just short sha1 (and I think you have the ability to refer to "1/7 of iteration 2", see next bullet point)
-I guess you can manage multiple iterations of a topic with one
iteration per PR, then linking them together. It would be nicer to somehow bake the iteration concept directly to a PR so we can switch between them, or do interdiff. I know, this is more of a improvement request than complaint because ML is not really better.
- Offline support would be very nice. I'm only most of the time, but
sometimes I do work on git stuff offline.
- We lose the integration with ML, I think. Sometimes the user
reports a bug here, then we reply back with a patch. With github, I guess we reply back with a PR number, then further discussion may go there, some discussion may still be on ML.
Quoted 6 lines
* It is easy to summon somebody else into the review conversation by @-mentioning them. That person immediately can see the whole history of the PR. (This is an improvement on the status quo, where a new entrant to a conversation might have to dig through the email trash or an email archive to see emails that they overlooked before they were added to the CC list.)
On the other hand, we can't just CC anybody anymore because we don't know if they have a github account (or the account name for that matter). Or does github allow @-ing email addresses too? We record people's email address, not github account names.
Quoted 3 lines
* It is possible to search old issues and PRs for additional context. (Granted, the history of the project from its ML era would have to be searched separately.)
To me searching in email is still better. Maybe I haven't fully explored github search capabilities
Signature · 1 line
Duy
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 9 lines · Duy Nguyen
Quoted 3 lines · Michael Haggerty
Could you elaborate why you would expect quality and/or quantity of reviews to suffer? I'm really curious, and I'd be happy to pass your feedback along to my colleagues.
Since I have been using github at work for a couple months, I do have a few complaints if it will ever become the way of reviewing things in git. Some of these may be covered by other people already (I haven't read all new mails in this thread yet)
Another super nit thing: use monospace font for commit messages, or at least have an option for that.
Signature · 1 line
Duy
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Michael HaggertyQuoted 8 lines · Michael Haggerty
Quoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
In the very unlikely event that github is shut down, how do we get all review comments out of it, assuming that we will use pull requests for review?
Signature · 1 line
Duy
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 7 lines · Duy Nguyen
Quoted 6 lines · Michael Haggerty
Quoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]
Quoted 6 lines
Quoted 2 lines
Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
In the very unlikely event that github is shut down, how do we get all review comments out of it, assuming that we will use pull requests for review?
For what it's worth this is exactly why I think it would be worthwhile for git to establish a common review format, services like Github/Gitlab could then start storing reviews and comments in the git repo rather than in a separate sql database.
Gerrit is already doing this with notedb, which literally gives you a git log of a review. Admittedly with Gerrit the change metadata sits in a separate git repo, still,
this is much better than the current situation with
Github and Gitlab in my opinion.
I apologise once again if my comments here are somewhat unrelated, but I feel there is at least some overlap, since the existence of a common review format for git could potentially make Github/Gitlab a more attractive option, if Github/Gitlab chose to adopt such a format.
Really I think that reviews shouldn't be stored on mailing lists, and they shouldn't be stored in sql databases,
they should be stored in git.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 8 lines · Richard Ipsum
Quoted 3 lines
In the very unlikely event that github is shut down, how do we get all review comments out of it, assuming that we will use pull requests for review?
For what it's worth this is exactly why I think it would be worthwhile for git to establish a common review format, services like Github/Gitlab could then start storing reviews and comments in the git repo rather than in a separate sql database.
I doubt that the "rather than" part will ever happen. Git does not make a very good database, and certainly not when you want to do things that cut across repositories (like, say, efficiently get all review comments made by one user).
It would be nice to have a common interchange format, though. In theory that could feed into (and out of) a more efficient representation on the backend of the site. It doesn't _have_ to be git-based, but it would be nice if it was.
Somebody asked elsewhere "what happens if GitHub goes away?". And the answer is that you can already get all of that data out in a programmatic way, via the API. But since there's no common interchange format, you'd be stuck writing a conversion to whatever format your new destination uses.
-Peff
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Duy NguyenQuoted 7 lines · Duy Nguyen
Quoted 6 lines · Michael Haggerty
Quoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]
Quoted 6 lines
Quoted 2 lines
Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
In the very unlikely event that github is shut down, how do we get all review comments out of it, assuming that we will use pull requests for review?
I don't have any experience with these tools, but a quick search turns up the following possibilities (among others):
* github-backup (by Joey Hess): https://github.com/joeyh/github-backup
* python-github-backup: https://github.com/josegonzalez/python-github-backup
* BackHub (commercial service): https://backhub.co/
* Import GitHub project into GitLab:
http://docs.gitlab.com/ce/workflow/importing/import_projects_from_github.html
Michael
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Michael HaggertyHi Michael,
Quoted 8 lines · Michael Haggerty
Quoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]Is it *really* so insane to consider moving collaboration on the Git project to GitHub or some other similar platform?
Speaking for myself, I do prefer GitHub's UI to mail, by a lot. Not only because it is more focused on the code, but because it integrates so nicely with Git, which email distinctly does not.
So I personally would not have the least bit of a problem to switch to GitHub (that's indeed what Git for Windows did, getting substantially more contributions than we would otherwise have).
And of course I use the email notifications quite a bit. They are really
convenient: I get my updates via my mail program, still, and the discussion I want to participate in is just one click away.
The reason why I stated that GitHub is out of the question is that I expected resistance against it. But you are right: I should not have ruled it out so categorically, it is not at all my call to make.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Michael HaggertyQuoted 14 lines · Michael Haggerty
Quoted 4 lines · Johannes Schindelin
[...]
Even requiring every contributor to register with GitHub would be too much of a limitation, I would wager.
[...]* Discussion of pull requests can be done either
* via the website (super easy for beginners but powerful for
experienced users),
* by setting up email notifications for your account and replying to
those emails, or
* via an API.
Such discussion is all in markdown, which supports light formatting,
hyperlinks, and @-mentions.
<snip>
Quoted 7 lines
Disclaimer: I work for GitHub, but in this email I'm speaking for myself.
Michael
[1] I concede that people who refuse on ideological grounds to use proprietary software will find this step insurmountable. Perhaps we could come up with a workaround for such people.
I'm one of those ideological people and I don't see an acceptable workaround. GitHub already has misfeatures designed to lock people in into centralized messaging:
* pull request feature doesn't work for self-hosted repos (this disincentivizes people from running and improving git-daemon/git-http-backend/etc...)
* "noreply" email addresses
* @-mentions you wrote about
* custom email notifications
This is a problem with Gitlab, Redmine, etc, too:
they cannot interoperate with each other.
At least for now, large proprietary mail providers like Gmail still interoperate with whatever Free Software SMTP software I run. I dread the day when that is no longer true.
Some of these problems I hope public-inbox (or something like it) can fix and turn the tide towards email, again. In contrast, public-inbox is designed to push decentralization:
* "reply" links are instructions for "git send-email" which encourage reply-to-all (this applies to what Jeff said about vger going down, I noticed it, too)
* anybody can clone the code + repo, replicate the instances, and tweak it to their needs.
* public-inbox.org/git/$MESSAGE_ID/t.atom allows subscriptions to Atom feeds without any registration or user-tracking
* Message-IDs are exposed for proper threading and interop
* low-bandwidth, Tor-friendly design to encourage deployments even behind NATs and firewalls.
Anyways, my optimistic side might interpret your advocacy as GitHub already feeling threatened by public-inbox. I certainly wouldn't expect it at this stage, but I certainly hope it will be the case one day :)
Disclaimer: I've always been willing to risk a lifetime of unemployment for ideology.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 2 lines · Eric Wong
Some of these problems I hope public-inbox (or something like it) can fix and turn the tide towards email, again.
This really seems like the dichotomy that drives people towards central services like GitHub or GitLab. We need an alternative that doesn't involve email, or at the very least, doesn't require people to use email directly. Half of the pain in the process comes from coaxing email clients that don't treat mail text as sacrosanct to leave it alone and not mangle it. (Some of that would go away if we accepted attachments with inline disposition, but not all of it. All of it would go away if the submission process just involved "git push" to an appropriate location.)
- Josh Triplett
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 4 lines · Josh Triplett
Quoted 2 lines · Eric Wong
Some of these problems I hope public-inbox (or something like it) can fix and turn the tide towards email, again.
Quoted 9 lines
This really seems like the dichotomy that drives people towards central services like GitHub or GitLab. We need an alternative that doesn't involve email, or at the very least, doesn't require people to use email directly. Half of the pain in the process comes from coaxing email clients that don't treat mail text as sacrosanct to leave it alone and not mangle it. (Some of that would go away if we accepted attachments with inline disposition, but not all of it. All of it would go away if the submission process just involved "git push" to an appropriate location.)
I don't mind patches as attachments and did some work a few months ago to ensure they're individually downloadable in the public-inbox WWW interface (along with full mboxrd messages)[1].
Fwiw, attachments are preferred in perl5-porters, and it might be acceptable on LKML, even. Not my call, though.
Having a push/pull-only workflow would still require some sort of messaging system to notify others. Ideally that message would have the output of "git request-pull" to ensure people are on the same page; but I'd prefer patches (either attachments or inline) continue to be sent anyways in case the server is down or the reader is offline or on a machine without git.
[1] see Brian's (who is new, here) initial email for diff-highlight:
https://public-inbox.org/git/[email protected]/
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Josh TriplettQuoted 4 lines · Josh Triplett
Quoted 2 lines · Eric Wong
Some of these problems I hope public-inbox (or something like it) can fix and turn the tide towards email, again.
Quoted 9 lines
This really seems like the dichotomy that drives people towards central services like GitHub or GitLab. We need an alternative that doesn't involve email, or at the very least, doesn't require people to use email directly. Half of the pain in the process comes from coaxing email clients that don't treat mail text as sacrosanct to leave it alone and not mangle it. (Some of that would go away if we accepted attachments with inline disposition, but not all of it. All of it would go away if the submission process just involved "git push" to an appropriate location.)
But submission is less important than review. And for review it is usually better (except gigantic series) to have patch text for review with the review. And threading. And (meta)-versioning of series. And place for proof-of-concept / weather-balon patches...
Signature · 1 line
Jakub Narebski
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 15 lines · Jakub Narębski
Quoted 4 lines · Josh Triplett
Quoted 2 lines · Eric Wong
Some of these problems I hope public-inbox (or something like it) can fix and turn the tide towards email, again.
Quoted 9 lines
This really seems like the dichotomy that drives people towards central services like GitHub or GitLab. We need an alternative that doesn't involve email, or at the very least, doesn't require people to use email directly. Half of the pain in the process comes from coaxing email clients that don't treat mail text as sacrosanct to leave it alone and not mangle it. (Some of that would go away if we accepted attachments with inline disposition, but not all of it. All of it would go away if the submission process just involved "git push" to an appropriate location.)
Quoted 3 lines
But submission is less important than review. And for review it is usually better (except gigantic series) to have patch text for review with the review.
Agreed. However, submission typically requires more work than review, because the patch text must remain applicable. For review, as long as the email client you use to respond doesn't do something horrible like *re-wrap* the quoted patch text, the result will work as a review.
Ideally, I'd love to see 1) a review UI that stores line-by-line reviews into a common format and can translate those to email, and 2) a mechanism to translate reviews written by email and quoting into the review format and store them with the repository.
Quoted 1 line
And (meta)-versioning of series.
I've got a documented format for that. :)
Quoted 1 line
And place for proof-of-concept / weather-balon patches...
Same place as all other patches, just with an "RFC" tag on them.
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Quoted 8 lines · Josh Triplett
Quoted 3 lines
But submission is less important than review. And for review it is usually better (except gigantic series) to have patch text for review with the review.
Agreed. However, submission typically requires more work than review, because the patch text must remain applicable. For review, as long as the email client you use to respond doesn't do something horrible like *re-wrap* the quoted patch text, the result will work as a review.
Yup. That is why we say "please send patch inline; when asked to send it as an attachment, please do so".
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Johannes SchindelinQuoted 6 lines · Johannes Schindelin
It would be a totally different matter, of course, if you used the branches I publish via my GitHub repository, added fixup! and squash! commits, published the result to a public repository and then told me to pull from there, that would make things easier. We could even introduce a reword! construct, to make the review of the suggested edits of the commit message easier.
On the topic of fixup and squash and everything. Is anyone else annoyed that the commit title is taken for fixup!, squash! instructions? After you have added a few of them, "git log --oneline" becomes useless. All you see is "fixup! A", "fixup! A", "fixup! B", "fixup! A".
Would it be better to let the user control the title? We still need the cue "fixup!", "squash!"... at the beginning of the title, but the original commit reference is appended at the end, like s-o-b lines.
Signature · 1 line
Duy
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Duy,
Quoted 3 lines · Duy Nguyen
On the topic of fixup and squash and everything. Is anyone else annoyed that the commit title is taken for fixup!, squash! instructions?
I do not know about others, but I am not annoyed by those commit titles. I think they make tons of sense.
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Duy NguyenFrom: "Duy Nguyen" <[email protected]>
Quoted 15 lines
Quoted 6 lines · Johannes Schindelin
It would be a totally different matter, of course, if you used the branches I publish via my GitHub repository, added fixup! and squash! commits, published the result to a public repository and then told me to pull from there, that would make things easier. We could even introduce a reword! construct, to make the review of the suggested edits of the commit message easier.
On the topic of fixup and squash and everything. Is anyone else annoyed that the commit title is taken for fixup!, squash! instructions? After you have added a few of them, "git log --oneline" becomes useless. All you see is "fixup! A", "fixup! A", "fixup! B", "fixup! A".
Quoted 3 lines
Would it be better to let the user control the title? We still need the cue "fixup!", "squash!"... at the beginning of the title, but the original commit reference is appended at the end, like s-o-b lines.
In the same vein, I always want,with my workflow, to use "fixup! <short_sha1>".
This would be to save trying to retype the title correctly, and simply use the abbreviated sha1, which would nicely allow an extra short summaty of what the fixup is about.
Philip
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
Hi Philip,
Quoted 2 lines · Philip Oakley
In the same vein, I always want,with my workflow, to use "fixup! <
short_sha1>".
Good news for you: this is already supported. See here:
https://github.com/git/git/blob/v2.9.2/git-rebase--interactive.sh#L786-L796
Ciao,
Dscho
Re: patch submission process, was Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
From: "Johannes Schindelin" <[email protected]>
Quoted 11 lines
Hi Philip,
Quoted 2 lines · Philip Oakley
In the same vein, I always want,with my workflow, to use "fixup! <
short_sha1>".Good news for you: this is already supported. See here:
https://github.com/git/git/blob/v2.9.2/git-rebase--interactive.sh#L786-L796
That's odd <knowing look>, I never saw any of that in the documentation...
Blame says it was 68d5d03 (rebase: teach --autosquash to match on sha1 in addition to message, 2010-11-04) which was before I discovered Git. Maybe another documentation fixup needed ;-)
Mind you I'm not sure about 22c5b13 (rebase -i: handle fixup! fixup! in --autosquash, 2013-06-27) which looks to only allow one fixup, but maybe I'm misreading. [e.g. recieve multiple fixups from the list, or need extra fixups as code of documentation is tested]
The capability is still good to know.
Philip
Re: [PATCH v6 06/16] merge_recursive: abort properly upon errors
In reply to Johannes SchindelinQuoted 4 lines · Johannes Schindelin
I tend to think that the underscore is correct: this change is not so much about the builtin (which is written with a dash) but about the function (written with an underscore, used by more than just merge-recursive, e.g. cherry-pick).
Yes, I agree. "merge-recursive:" prefix is about either the built-in command, or the machinery as a whole to support that built-in command. It is preferrable to use "merge_recursive():" if we are talking about a single function.
Thanks.
PATCH v6 7/16 merge-recursive: avoid returning a wholesale struct
In reply to Johannes SchindelinIt is technically allowed, as per C89, for functions' return type to be complete structs (i.e. *not* just pointers to structs).
However, it was just an oversight of this developer when converting Python code to C code in 6d297f8 (Status update on merge-recursive in C, 2006-07-08) which introduced such a return type.
Besides, by converting this construct to pass in the struct, we can now start returning a value that can indicate errors in future patches. This will help the current effort to libify merge-recursive.c.
--- merge-recursive.c | 106 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 50 deletions(-)
merge-recursive.c +56 -50
@@ -894,47 +894,47 @@ static int merge_3way(struct merge_options *o,return merge_status; } -static struct merge_file_info merge_file_1 (struct merge_options *o, +static int merge_file_1 (struct merge_options *o,const struct diff_filespec *one,const struct diff_filespec *a,const struct diff_filespec *b,const char *branch1, -const char *branch2) +const char *branch2, +struct merge_file_info *result) { -struct merge_file_info result; - result.merge =0 ; - result.clean =1 ; + result->merge =0 ; + result->clean =1 ;if ((S_IFMT & a->mode) != (S_IFMT & b->mode)) { - result.clean =0 ; + result->clean =0 ;if (S_ISREG (a->mode)) { - result.mode = a->mode; -oidcpy (&result.oid, &a->oid); + result->mode = a->mode; +oidcpy (&result->oid, &a->oid); }else { - result.mode = b->mode; -oidcpy (&result.oid, &b->oid); + result->mode = b->mode; +oidcpy (&result->oid, &b->oid); } }else {if (!oid_eq (&a->oid, &one->oid) && !oid_eq (&b->oid, &one->oid)) - result.merge =1 ; + result->merge =1 ;/* * Merge modes */ if (a->mode == b->mode || a->mode == one->mode) - result.mode = b->mode; + result->mode = b->mode;else { - result.mode = a->mode; + result->mode = a->mode;if (b->mode != one->mode) { - result.clean =0 ; - result.merge =1 ; + result->clean =0 ; + result->merge =1 ; } }if (oid_eq (&a->oid, &b->oid) ||oid_eq (&a->oid, &one->oid)) -oidcpy (&result.oid, &b->oid); +oidcpy (&result->oid, &b->oid);else if (oid_eq (&b->oid, &one->oid)) -oidcpy (&result.oid, &a->oid); +oidcpy (&result->oid, &a->oid);else if (S_ISREG (a->mode)) {mmbuffer_t result_buf;int merge_status;
@@ -946,64 +946,66 @@ static struct merge_file_info merge_file_1(struct merge_options *o,die (_ ("Failed to execute internal merge" ));if (write_sha1_file (result_buf.ptr, result_buf.size, - blob_type, result.oid.hash)) + blob_type, result->oid.hash))die (_ ("Unable to add %s to database" ), a->path);free (result_buf.ptr); - result.clean = (merge_status ==0 ); + result->clean = (merge_status ==0 ); }else if (S_ISGITLINK (a->mode)) { - result.clean =merge_submodule (result.oid.hash, + result->clean =merge_submodule (result->oid.hash, one->path, one->oid.hash, a->oid.hash, b->oid.hash, !o->call_depth); }else if (S_ISLNK (a->mode)) { -oidcpy (&result.oid, &a->oid); +oidcpy (&result->oid, &a->oid);if (!oid_eq (&a->oid, &b->oid)) - result.clean =0 ; + result->clean =0 ; }else die ("BUG: unsupported object type in the tree" ); } -return result; +return 0 ; } -static struct merge_file_info -merge_file_special_markers (struct merge_options *o, +static int merge_file_special_markers (struct merge_options *o,const struct diff_filespec *one,const struct diff_filespec *a,const struct diff_filespec *b,const char *branch1,const char *filename1,const char *branch2, -const char *filename2) +const char *filename2, +struct merge_file_info *mfi) {char *side1 =NULL ;char *side2 =NULL ; -struct merge_file_info mfi; +int ret;if (filename1) side1 =xstrfmt ("%s:%s" , branch1, filename1);if (filename2) side2 =xstrfmt ("%s:%s" , branch2, filename2); - mfi =merge_file_1 (o, one, a, b, - side1 ? side1 : branch1, side2 ? side2 : branch2); + ret =merge_file_1 (o, one, a, b, + side1 ? side1 : branch1, + side2 ? side2 : branch2, mfi);free (side1);free (side2); -return mfi; +return ret; } -static struct merge_file_info merge_file_one (struct merge_options *o, +static int merge_file_one (struct merge_options *o,const char *path,const struct object_id *o_oid,int o_mode,const struct object_id *a_oid,int a_mode,const struct object_id *b_oid,int b_mode,const char *branch1, -const char *branch2) +const char *branch2, +struct merge_file_info *mfi) {struct diff_filespec one, a, b;
@@ -1014,7 +1016,7 @@ static struct merge_file_info merge_file_one(struct merge_options *o, a.mode = a_mode;oidcpy (&b.oid, b_oid); b.mode = b_mode; -return merge_file_1 (o, &one, &a, &b, branch1, branch2); +return merge_file_1 (o, &one, &a, &b, branch1, branch2, mfi); } static void handle_change_delete(struct merge_options *o,
@@ -1187,11 +1189,12 @@ static void conflict_rename_rename_1to2(struct merge_options *o,struct merge_file_info mfi;struct diff_filespec other;struct diff_filespec *add; - mfi =merge_file_one (o, one->path, +if (merge_file_one (o, one->path, &one->oid, one->mode, &a->oid, a->mode, &b->oid, b->mode, - ci->branch1, ci->branch2); + ci->branch1, ci->branch2, &mfi)) +return ;/* * FIXME: For rename/add-source conflicts (if we could detect * such), this is wrong. We should instead find a unique
@@ -1245,12 +1248,13 @@ static void conflict_rename_rename_2to1(struct merge_options *o,remove_file (o,1 , a->path, o->call_depth ||would_lose_untracked (a->path));remove_file (o,1 , b->path, o->call_depth ||would_lose_untracked (b->path)); - mfi_c1 =merge_file_special_markers (o, a, c1, &ci->ren1_other, - o->branch1, c1->path, - o->branch2, ci->ren1_other.path); - mfi_c2 =merge_file_special_markers (o, b, &ci->ren2_other, c2, - o->branch1, ci->ren2_other.path, - o->branch2, c2->path); +if (merge_file_special_markers (o, a, c1, &ci->ren1_other, + o->branch1, c1->path, + o->branch2, ci->ren1_other.path, &mfi_c1) || +merge_file_special_markers (o, b, &ci->ren2_other, c2, + o->branch1, ci->ren2_other.path, + o->branch2, c2->path, &mfi_c2)) +return ;if (o->call_depth) {/*
@@ -1473,12 +1477,13 @@ static int process_renames(struct merge_options *o, ren1_dst, branch2);if (o->call_depth) {struct merge_file_info mfi; - mfi =merge_file_one (o, ren1_dst, &null_oid,0 , - &ren1->pair->two->oid, - ren1->pair->two->mode, - &dst_other.oid, - dst_other.mode, - branch1, branch2); +if (merge_file_one (o, ren1_dst, &null_oid,0 , + &ren1->pair->two->oid, + ren1->pair->two->mode, + &dst_other.oid, + dst_other.mode, + branch1, branch2, &mfi)) +return -1 ;output (o,1 ,_ ("Adding merged %s" ), ren1_dst);update_file (o,0 , &mfi.oid, mfi.mode, ren1_dst);
@@ -1636,9 +1641,10 @@ static int merge_content(struct merge_options *o,if (dir_in_way (path, !o->call_depth)) df_conflict_remains =1 ; } - mfi =merge_file_special_markers (o, &one, &a, &b, - o->branch1, path1, - o->branch2, path2); +if (merge_file_special_markers (o, &one, &a, &b, + o->branch1, path1, + o->branch2, path2, &mfi)) +return -1 ;if (mfi.clean && !df_conflict_remains &&oid_eq (&mfi.oid, a_oid) && mfi.mode == a_mode) {
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 07/16] merge-recursive: avoid returning a wholesale struct
Quoted 10 lines · Johannes Schindelin
It is technically allowed, as per C89, for functions' return type to be complete structs (i.e. *not* just pointers to structs).
However, it was just an oversight of this developer when converting Python code to C code in 6d297f8 (Status update on merge-recursive in C, 2006-07-08) which introduced such a return type.
Besides, by converting this construct to pass in the struct, we can now start returning a value that can indicate errors in future patches. This will help the current effort to libify
merge-recursive.c.
I do not think returning a small struct by value is unconditionally a bad thing, but I do agree with you that this change makes the resulting code much easier to read, especially once this starts returning errors.
Good.
PATCH v6 8/16 merge-recursive: allow write_tree_from_memory() to error out
In reply to Johannes SchindelinIt is possible that a tree cannot be written (think: disk full). We will want to give the caller a chance to clean up instead of letting the program die() in such a case.
--- merge-recursive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
merge-recursive.c +2 -2
@@ -1888,8 +1888,8 @@ int merge_trees(struct merge_options *o,else clean =1 ; -if (o->call_depth) - *result =write_tree_from_memory (o); +if (o->call_depth && !(*result =write_tree_from_memory (o))) +return -1 ;return clean; }
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 08/16] merge-recursive: allow write_tree_from_memory() to error out
Quoted 14 lines · Johannes Schindelin
It is possible that a tree cannot be written (think: disk full). We will want to give the caller a chance to clean up instead of letting the program
die()in such a case.Signed-off-by Johannes Schindelin <[email protected]>--- merge-recursive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)merge-recursive.c +0
-0
merge-recursive.c int merge_trees(struct merge_options *o, · line 1892
Quoted 7 lines
merge-recursive.c +2
-2@@ -1888,8 +1888,8 @@ int merge_trees(struct merge_options *o,else clean =1 ; -if (o->call_depth) - *result =write_tree_from_memory (o); +if (o->call_depth && !(*result =write_tree_from_memory (o))) +return -1 ;
I'll let it pass, but we avoid assignment in a conditional part for a good reason: it can become unreadable pretty quickly. Writing it in a long-hand, e.g.
if (o->call_depth) {
*result = write_tree_from_memory(o);
if (!*result)
return -1;
}future-proofs against the "o->call_depth" condition part and "write_tree_from_memory(o)" operation part becoming longer, possibly needing multiple statements.
The change itself is correct.
PATCH v6 9/16 merge-recursive: handle return values indicating errors
In reply to Johannes SchindelinWe are about to libify the recursive merge machinery, where we only die() in case of a bug or memory contention. To that end, we must heed negative return values as indicating errors.
This requires our functions to be careful to pass through error conditions in call chains, and for quite a few functions this means that they have to return values to begin with.
The next step will be to convert the places where we currently die() to return negative values (read: -1) instead.
Note that we ignore errors reported by make_room_for_path(), consistent with the previous behavior (update_file_flags() used the return value of make_room_for_path() only to indicate an early return, but not a fatal error): if the error is really a fatal error, we will notice later; If not, it was not that serious a problem to begin with. (Witnesses in favor of this reasoning are t4151-am-abort and t7610-mergetool, which would start failing if we stopped on errors reported by make_room_for_path()).
Also note: while this patch makes the code slightly less readable in update_file_flags() (we introduce a new "goto free_buf;" instead of an explicit "free(buf); return;"), it is a preparatory change for the next patch where we will convert all of the die() calls in the same function to go through the free_buf return path instead.
--- merge-recursive.c | 252 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 150 insertions(+), 102 deletions(-)
merge-recursive.c +150 -102
@@ -742,12 +742,12 @@ static int make_room_for_path(struct merge_options *o, const char *path)return error (msg, path,_ (": perhaps a D/F conflict?" )); } -static void update_file_flags (struct merge_options *o, -const struct object_id *oid, -unsigned mode, -const char *path, -int update_cache, -int update_wd) +static int update_file_flags (struct merge_options *o, +const struct object_id *oid, +unsigned mode, +const char *path, +int update_cache, +int update_wd) {if (o->call_depth) update_wd =0 ;
@@ -783,8 +783,7 @@ static void update_file_flags(struct merge_options *o,if (make_room_for_path (o, path) <0 ) { update_wd =0 ; -free (buf); - goto update_index; + goto free_buf; }if (S_ISREG (mode) || (!has_symlinks &&S_ISLNK (mode))) {int fd;
@@ -807,20 +806,22 @@ static void update_file_flags(struct merge_options *o, }else die (_ ("do not know what to do with %06o %s '%s'" ), mode,oid_to_hex (oid), path); + free_buf:free (buf); } update_index:if (update_cache)add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); +return 0 ; } -static void update_file (struct merge_options *o, -int clean, -const struct object_id *oid, -unsigned mode, -const char *path) +static int update_file (struct merge_options *o, +int clean, +const struct object_id *oid, +unsigned mode, +const char *path) { -update_file_flags (o, oid, mode, path, o->call_depth || clean, !o->call_depth); +return update_file_flags (o, oid, mode, path, o->call_depth || clean, !o->call_depth); }/* Low level file merging, update and removal */
@@ -1019,7 +1020,7 @@ static int merge_file_one(struct merge_options *o,return merge_file_1 (o, &one, &a, &b, branch1, branch2, mfi); } -static void handle_change_delete(struct merge_options *o, +static int handle_change_delete(struct merge_options *o, const char *path, const struct object_id *o_oid, int o_mode, const struct object_id *a_oid, int a_mode,
@@ -1027,6 +1028,7 @@ static void handle_change_delete(struct merge_options *o, const char *change, const char *change_past) { char *renamed = NULL; +int ret =0 ;if (dir_in_way (path, !o->call_depth)) { renamed =unique_path (o, path, a_oid ? o->branch1 : o->branch2); }
@@ -1037,21 +1039,23 @@ static void handle_change_delete(struct merge_options *o,* correct; since there is no true "middle point" between * them, simply reuse the base version for virtual merge base. */ -remove_file_from_cache (path); -update_file (o,0 , o_oid, o_mode, renamed ? renamed : path); + ret =remove_file_from_cache (path); +if (!ret) + ret =update_file (o,0 , o_oid, o_mode, + renamed ? renamed : path); }else if (!a_oid) {if (!renamed) {output (o,1 ,_ ("CONFLICT (%s/delete): %s deleted in %s " "and %s in %s. Version %s of %s left in tree." ), change, path, o->branch1, change_past, o->branch2, o->branch2, path); -update_file (o,0 , b_oid, b_mode, path); + ret =update_file (o,0 , b_oid, b_mode, path); }else {output (o,1 ,_ ("CONFLICT (%s/delete): %s deleted in %s " "and %s in %s. Version %s of %s left in tree at %s." ), change, path, o->branch1, change_past, o->branch2, o->branch2, path, renamed); -update_file (o,0 , b_oid, b_mode, renamed); + ret =update_file (o,0 , b_oid, b_mode, renamed); } }else {if (!renamed) {
@@ -1064,7 +1068,7 @@ static void handle_change_delete(struct merge_options *o, "and %s in %s. Version %s of %s left in tree at %s."), change, path, o->branch2, change_past, o->branch1, o->branch1, path, renamed); -update_file (o,0 , a_oid, a_mode, renamed); + ret =update_file (o,0 , a_oid, a_mode, renamed); }/* * No need to call update_file() on path when !renamed, since
@@ -1074,9 +1078,11 @@ static void handle_change_delete(struct merge_options *o,*/ }free (renamed); + +return ret; } -static void conflict_rename_delete (struct merge_options *o, +static int conflict_rename_delete (struct merge_options *o,struct diff_filepair *pair,const char *rename_branch,const char *other_branch)
@@ -1096,21 +1102,20 @@ static void conflict_rename_delete(struct merge_options *o, b_mode = dest->mode; } -handle_change_delete (o, - o->call_depth ? orig->path : dest->path, - &orig->oid, orig->mode, - a_oid, a_mode, - b_oid, b_mode, -_ ("rename" ),_ ("renamed" )); - -if (o->call_depth) { -remove_file_from_cache (dest->path); - }else { -update_stages (dest->path,NULL , - rename_branch == o->branch1 ? dest :NULL , - rename_branch == o->branch1 ?NULL : dest); - } +if (handle_change_delete (o, + o->call_depth ? orig->path : dest->path, + &orig->oid, orig->mode, + a_oid, a_mode, + b_oid, b_mode, +_ ("rename" ),_ ("renamed" ))) +return -1 ; +if (o->call_depth) +return remove_file_from_cache (dest->path); +else +return update_stages (dest->path,NULL , + rename_branch == o->branch1 ? dest :NULL , + rename_branch == o->branch1 ?NULL : dest); } static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
@@ -1126,7 +1131,7 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,return target; } -static void handle_file (struct merge_options *o, +static int handle_file (struct merge_options *o,struct diff_filespec *rename,int stage,struct rename_conflict_info *ci)
@@ -1136,6 +1141,7 @@ static void handle_file(struct merge_options *o,const char *cur_branch, *other_branch;struct diff_filespec other;struct diff_filespec *add; +int ret;if (stage ==2 ) { dst_entry = ci->dst_entry1;
@@ -1150,7 +1156,8 @@ static void handle_file(struct merge_options *o, add =filespec_from_entry (&other, dst_entry, stage ^1 );if (add) {char *add_name =unique_path (o, rename->path, other_branch); -update_file (o,0 , &add->oid, add->mode, add_name); +if (update_file (o,0 , &add->oid, add->mode, add_name)) +return -1 ;remove_file (o,0 , rename->path,0 ); dst_name =unique_path (o, rename->path, cur_branch);
@@ -1161,17 +1168,20 @@ static void handle_file(struct merge_options *o, rename->path, other_branch, dst_name); } } -update_file (o,0 , &rename->oid, rename->mode, dst_name); -if (stage ==2 ) -update_stages (rename->path,NULL , rename, add); +if ((ret =update_file (o,0 , &rename->oid, rename->mode, dst_name))) + ;/* fall through, do allow dst_name to be released */ +else if (stage ==2 ) + ret =update_stages (rename->path,NULL , rename, add);else -update_stages (rename->path,NULL , add, rename); + ret =update_stages (rename->path,NULL , add, rename);if (dst_name != rename->path)free (dst_name); + +return ret; } -static void conflict_rename_rename_1to2 (struct merge_options *o, +static int conflict_rename_rename_1to2 (struct merge_options *o,struct rename_conflict_info *ci) {/* One file was renamed in both branches, but to different names. */
@@ -1194,14 +1204,16 @@ static void conflict_rename_rename_1to2(struct merge_options *o, &a->oid, a->mode, &b->oid, b->mode, ci->branch1, ci->branch2, &mfi)) - return; +return -1 ; +/* * FIXME: For rename/add-source conflicts (if we could detect * such), this is wrong. We should instead find a unique * pathname and then either rename the add-source file to that * unique path, or use that unique path instead of src here. */ -update_file (o,0 , &mfi.oid, mfi.mode, one->path); +if (update_file (o,0 , &mfi.oid, mfi.mode, one->path)) +return -1 ;/* * Above, we put the merged content at the merge-base's
@@ -1212,22 +1224,26 @@ static void conflict_rename_rename_1to2(struct merge_options *o,* resolving the conflict at that path in its favor. */ add =filespec_from_entry (&other, ci->dst_entry1,2 ^1 ); -if (add) -update_file (o,0 , &add->oid, add->mode, a->path); +if (add) { +if (update_file (o,0 , &add->oid, add->mode, a->path)) +return -1 ; + }else remove_file_from_cache (a->path); add =filespec_from_entry (&other, ci->dst_entry2,3 ^1 ); -if (add) -update_file (o,0 , &add->oid, add->mode, b->path); +if (add) { +if (update_file (o,0 , &add->oid, add->mode, b->path)) +return -1 ; + }else remove_file_from_cache (b->path); - }else { -handle_file (o, a,2 , ci); -handle_file (o, b,3 , ci); - } + }else if (handle_file (o, a,2 , ci) ||handle_file (o, b,3 , ci)) +return -1 ; + +return 0 ; } -static void conflict_rename_rename_2to1 (struct merge_options *o, +static int conflict_rename_rename_2to1 (struct merge_options *o,struct rename_conflict_info *ci) {/* Two files, a & b, were renamed to the same thing, c. */
@@ -1238,6 +1254,7 @@ static void conflict_rename_rename_2to1(struct merge_options *o,char *path = c1->path;/* == c2->path */ struct merge_file_info mfi_c1;struct merge_file_info mfi_c2; +int ret; output(o, 1, _("CONFLICT (rename/rename): " "Rename %s->%s in %s. "
@@ -1254,7 +1271,7 @@ static void conflict_rename_rename_2to1(struct merge_options *o,merge_file_special_markers (o, b, &ci->ren2_other, c2, o->branch1, ci->ren2_other.path, o->branch2, c2->path, &mfi_c2)) - return; + return -1;if (o->call_depth) {/*
@@ -1265,19 +1282,25 @@ static void conflict_rename_rename_2to1(struct merge_options *o,* again later for the non-recursive merge. */ remove_file (o,0 , path,0 ); -update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, a->path); -update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, b->path); + ret =update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, a->path); +if (!ret) + ret =update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, + b->path); }else {char *new_path1 =unique_path (o, path, ci->branch1);char *new_path2 =unique_path (o, path, ci->branch2);output (o,1 ,_ ("Renaming %s to %s and %s to %s instead" ), a->path, new_path1, b->path, new_path2);remove_file (o,0 , path,0 ); -update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, new_path1); -update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, new_path2); + ret =update_file (o,0 , &mfi_c1.oid, mfi_c1.mode, new_path1); +if (!ret) + ret =update_file (o,0 , &mfi_c2.oid, mfi_c2.mode, + new_path2);free (new_path2);free (new_path1); } + +return ret; } static int process_renames(struct merge_options *o,
@@ -1462,12 +1485,13 @@ static int process_renames(struct merge_options *o,* update_file_flags() instead of * update_file(). */ -update_file_flags (o, - &ren1->pair->two->oid, - ren1->pair->two->mode, - ren1_dst, -1 ,/* update_cache */ -0 /* update_wd */ ); +if (update_file_flags (o, + &ren1->pair->two->oid, + ren1->pair->two->mode, + ren1_dst, +1 ,/* update_cache */ +0 /* update_wd */ )) + clean_merge =-1 ; }else if (!oid_eq (&dst_other.oid, &null_oid)) { clean_merge =0 ; try_merge =1 ;
@@ -1482,22 +1506,28 @@ static int process_renames(struct merge_options *o, ren1->pair->two->mode, &dst_other.oid, dst_other.mode, - branch1, branch2, &mfi)) - return -1; + branch1, branch2, &mfi)) { + clean_merge =-1 ; + goto cleanup_and_return; + }output (o,1 ,_ ("Adding merged %s" ), ren1_dst); -update_file (o,0 , &mfi.oid, - mfi.mode, ren1_dst); +if (update_file (o,0 , &mfi.oid, + mfi.mode, ren1_dst)) + clean_merge =-1 ; try_merge =0 ; }else {char *new_path =unique_path (o, ren1_dst, branch2);output (o,1 ,_ ("Adding as %s instead" ), new_path); -update_file (o,0 , &dst_other.oid, - dst_other.mode, new_path); +if (update_file (o,0 , &dst_other.oid, + dst_other.mode, new_path)) + clean_merge =-1 ;free (new_path); } }else try_merge =1 ; +if (clean_merge <0 ) + goto cleanup_and_return;if (try_merge) {struct diff_filespec *one, *a, *b; src_other.path = (char *)ren1_src;
@@ -1524,6 +1554,7 @@ static int process_renames(struct merge_options *o, } } } +cleanup_and_return:string_list_clear (&a_by_dst,0 );string_list_clear (&b_by_dst,0 );
@@ -1586,18 +1617,18 @@ static int blob_unchanged(const struct object_id *o_oid,return ret; } -static void handle_modify_delete (struct merge_options *o, +static int handle_modify_delete (struct merge_options *o,const char *path,struct object_id *o_oid,int o_mode,struct object_id *a_oid,int a_mode,struct object_id *b_oid,int b_mode) { -handle_change_delete (o, - path, - o_oid, o_mode, - a_oid, a_mode, - b_oid, b_mode, -_ ("modify" ),_ ("modified" )); +return handle_change_delete (o, + path, + o_oid, o_mode, + a_oid, a_mode, + b_oid, b_mode, +_ ("modify" ),_ ("modified" )); } static int merge_content(struct merge_options *o,
@@ -1671,7 +1702,8 @@ static int merge_content(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): Merge conflict in %s" ), reason, path);if (rename_conflict_info && !df_conflict_remains) -update_stages (path, &one, &a, &b); +if (update_stages (path, &one, &a, &b)) +return -1 ; }if (df_conflict_remains) {
@@ -1679,30 +1711,33 @@ static int merge_content(struct merge_options *o,if (o->call_depth) {remove_file_from_cache (path); }else { -if (!mfi.clean) -update_stages (path, &one, &a, &b); -else { +if (!mfi.clean) { +if (update_stages (path, &one, &a, &b)) +return -1 ; + }else {int file_from_stage2 =was_tracked (path);struct diff_filespec merged;oidcpy (&merged.oid, &mfi.oid); merged.mode = mfi.mode; -update_stages (path,NULL , - file_from_stage2 ? &merged :NULL , - file_from_stage2 ?NULL : &merged); +if (update_stages (path,NULL , + file_from_stage2 ? &merged :NULL , + file_from_stage2 ?NULL : &merged)) +return -1 ; } } new_path =unique_path (o, path, rename_conflict_info->branch1);output (o,1 ,_ ("Adding as %s instead" ), new_path); -update_file (o,0 , &mfi.oid, mfi.mode, new_path); +if (update_file (o,0 , &mfi.oid, mfi.mode, new_path)) { +free (new_path); +return -1 ; + }free (new_path); mfi.clean =0 ; - }else { -update_file (o, mfi.clean, &mfi.oid, mfi.mode, path); - } + }else if (update_file (o, mfi.clean, &mfi.oid, mfi.mode, path)) +return -1 ;return mfi.clean; - }/* Per entry merge function */
@@ -1730,17 +1765,21 @@ static int process_entry(struct merge_options *o,break ;case RENAME_DELETE : clean_merge =0 ; -conflict_rename_delete (o, conflict_info->pair1, - conflict_info->branch1, - conflict_info->branch2); +if (conflict_rename_delete (o, + conflict_info->pair1, + conflict_info->branch1, + conflict_info->branch2)) + clean_merge =-1 ;break ;case RENAME_ONE_FILE_TO_TWO : clean_merge =0 ; -conflict_rename_rename_1to2 (o, conflict_info); +if (conflict_rename_rename_1to2 (o, conflict_info)) + clean_merge =-1 ;break ;case RENAME_TWO_FILES_TO_ONE : clean_merge =0 ; -conflict_rename_rename_2to1 (o, conflict_info); +if (conflict_rename_rename_2to1 (o, conflict_info)) + clean_merge =-1 ;break ;default : entry->processed =0 ;
@@ -1760,8 +1799,9 @@ static int process_entry(struct merge_options *o, }else {/* Modify/delete; deleted side may have put a directory in the way */ clean_merge =0 ; -handle_modify_delete (o, path, o_oid, o_mode, - a_oid, a_mode, b_oid, b_mode); +if (handle_modify_delete (o, path, o_oid, o_mode, + a_oid, a_mode, b_oid, b_mode)) + clean_merge =-1 ; } }else if ((!o_oid && a_oid && !b_oid) || (!o_oid && !a_oid && b_oid)) {
@@ -1793,14 +1833,16 @@ static int process_entry(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): There is a directory with name %s in %s. " "Adding %s as %s" ), conf, path, other_branch, path, new_path); -update_file (o,0 , oid, mode, new_path); -if (o->call_depth) +if (update_file (o,0 , oid, mode, new_path)) + clean_merge =-1 ; +else if (o->call_depth)remove_file_from_cache (path);free (new_path); }else {output (o,2 ,_ ("Adding %s" ), path);/* do not overwrite file if already present */ -update_file_flags (o, oid, mode, path,1 , !a_oid); +if (update_file_flags (o, oid, mode, path,1 , !a_oid)) + clean_merge =-1 ; } }else if (a_oid && b_oid) {/* Case C: Added in both (check for same permissions) and */
@@ -1863,12 +1905,18 @@ int merge_trees(struct merge_options *o, re_head =get_renames (o, head, common, head, merge, entries); re_merge =get_renames (o, merge, common, head, merge, entries); clean =process_renames (o, re_head, re_merge); +if (clean <0 ) +return clean;for (i = entries->nr-1 ;0 <= i; i--) {const char *path = entries->items[i].string;struct stage_data *e = entries->items[i].util; -if (!e->processed - && !process_entry (o, path, e)) - clean =0 ; +if (!e->processed) { +int ret =process_entry (o, path, e); +if (!ret) + clean =0 ; +else if (ret <0 ) +return ret; + } }for (i =0 ; i < entries->nr; i++) {struct stage_data *e = entries->items[i].util;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 10/16 merge-recursive: switch to returning errors instead of dying
In reply to Johannes SchindelinThe recursive merge machinery is supposed to be a library function, i.e. it should return an error when it fails. Originally the functions were part of the builtin "merge-recursive", though, where it was simpler to call die() and be done with error handling.
The existing callers were already prepared to detect negative return values to indicate errors and to behave as previously: exit with code 128 (which is the same thing that die() does, after printing the message).
--- merge-recursive.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-)
merge-recursive.c +35 -27
@@ -275,8 +275,10 @@ struct tree *write_tree_from_memory(struct merge_options *o) active_cache_tree =cache_tree ();if (!cache_tree_fully_valid (active_cache_tree) && -cache_tree_update (&the_index,0 ) <0 ) -die (_ ("error building trees" )); +cache_tree_update (&the_index,0 ) <0 ) { +error (_ ("error building trees" )); +return NULL ; + } result =lookup_tree (active_cache_tree->sha1);
@@ -716,12 +718,10 @@ static int make_room_for_path(struct merge_options *o, const char *path)/* Make sure leading directories are created */ status =safe_create_leading_directories_const (path);if (status) { -if (status ==SCLD_EXISTS ) { +if (status ==SCLD_EXISTS )/* something else exists */ -error (msg, path,_ (": perhaps a D/F conflict?" )); -return -1 ; - } -die (msg, path,"" ); +return error (msg, path,_ (": perhaps a D/F conflict?" )); +return error (msg, path,"" ); }/*
@@ -749,6 +749,8 @@ static int update_file_flags(struct merge_options *o,int update_cache, int update_wd) { + int ret = 0; +if (o->call_depth) update_wd =0 ;
@@ -769,9 +771,11 @@ static int update_file_flags(struct merge_options *o, buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -die (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); -if (type !=OBJ_BLOB ) -die (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); +return error (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); +if (type !=OBJ_BLOB ) { + ret =error (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); + goto free_buf; + }if (S_ISREG (mode)) {struct strbuf strbuf =STRBUF_INIT ;if (convert_to_working_tree (path, buf, size, &strbuf)) {
@@ -792,8 +796,11 @@ static int update_file_flags(struct merge_options *o,else mode =0666 ; fd =open (path,O_WRONLY |O_TRUNC |O_CREAT , mode); -if (fd <0 ) -die_errno (_ ("failed to open '%s'" ), path); +if (fd <0 ) { + ret =error_errno (_ ("failed to open '%s'" ), + path); + goto free_buf; + }write_in_full (fd, buf, size);close (fd); }else if (S_ISLNK (mode)) {
@@ -801,18 +808,18 @@ static int update_file_flags(struct merge_options *o,safe_create_leading_directories_const (path);unlink (path);if (symlink (lnk, path)) -die_errno (_ ("failed to symlink '%s'" ), path); + ret =error_errno (_ ("failed to symlink '%s'" ), path);free (lnk); }else -die (_ ("do not know what to do with %06o %s '%s'" ), - mode,oid_to_hex (oid), path); + ret =error (_ ("do not know what to do with %06o %s '%s'" ), + mode,oid_to_hex (oid), path); free_buf:free (buf); } update_index: -if (update_cache) +if (!ret && update_cache)add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); -return 0 ; +return ret; } static int update_file(struct merge_options *o,
@@ -938,20 +945,22 @@ static int merge_file_1(struct merge_options *o,oidcpy (&result->oid, &a->oid); else if (S_ISREG(a->mode)) {mmbuffer_t result_buf; -int merge_status; +int ret =0 , merge_status; merge_status =merge_3way (o, &result_buf, one, a, b, branch1, branch2);if ((merge_status <0 ) || !result_buf.ptr) -die (_ ("Failed to execute internal merge" )); + ret =error (_ ("Failed to execute internal merge" )); -if (write_sha1_file (result_buf.ptr, result_buf.size, - blob_type, result->oid.hash)) -die (_ ("Unable to add %s to database" ), - a->path); +if (!ret &&write_sha1_file (result_buf.ptr, result_buf.size, + blob_type, result->oid.hash)) + ret =error (_ ("Unable to add %s to database" ), + a->path);free (result_buf.ptr); +if (ret) +return ret; result->clean = (merge_status ==0 ); } else if (S_ISGITLINK(a->mode)) { result->clean = merge_submodule(result->oid.hash,
@@ -1885,11 +1894,10 @@ int merge_trees(struct merge_options *o,if (code !=0 ) {if (show (o,4 ) || o->call_depth) -die (_ ("merging of trees %s and %s failed" ), +error (_ ("merging of trees %s and %s failed" ),oid_to_hex (&head->object.oid),oid_to_hex (&merge->object.oid)); -else -exit (128 ); +return -1 ; }if (unmerged_cache ()) {
@@ -2021,7 +2029,7 @@ int merge_recursive(struct merge_options *o, o->call_depth--;if (!merged_common_ancestors) -die (_ ("merge returned no commit" )); +return error (_ ("merge returned no commit" )); }discard_cache ();
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 11/16 am -3: use merge_recursive() directly again
In reply to Johannes SchindelinLast October, we had to change this code to run git merge-recursive in a child process: git-am wants to print some helpful advice when the merge failed, but the code in question was not prepared to return, it die()d instead.
We are finally at a point when the code *is* prepared to return errors, and can avoid the child process again.
This reverts commit c63d4b2 (am -3: do not let failed merge from completing the error codepath, 2015-10-09), with the necessary changes to adjust for the fact that Git's source code changed in the meantime (such as: using OIDs instead of hashes in the recursive merge, and a removed gender bias).
Note: the code now calls merge_recursive_generic() again. Unlike merge_trees() and merge_recursive(), this function returns 0 upon success, as most of Git's functions. Therefore, the error value -1 naturally is handled correctly, and we do not have to take care of it specifically.
--- builtin/am.c | 62 +++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 40 deletions(-)
builtin/am.c +22 -40
@@ -1579,47 +1579,18 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f }/** -* Do the three-way merge using fake ancestor, their tree constructed -* from the fake ancestor and the postimage of the patch, and our -* state. -*/ -static int run_fallback_merge_recursive (const struct am_state *state, -unsigned char *orig_tree, -unsigned char *our_tree, -unsigned char *their_tree) -{ -struct child_process cp =CHILD_PROCESS_INIT ; -int status; - - cp.git_cmd =1 ; - -argv_array_pushf (&cp.env_array,"GITHEAD_%s=%.*s" , -sha1_to_hex (their_tree),linelen (state->msg), state->msg); -if (state->quiet) -argv_array_push (&cp.env_array,"GIT_MERGE_VERBOSITY=0" ); - -argv_array_push (&cp.args,"merge-recursive" ); -argv_array_push (&cp.args,sha1_to_hex (orig_tree)); -argv_array_push (&cp.args,"--" ); -argv_array_push (&cp.args,sha1_to_hex (our_tree)); -argv_array_push (&cp.args,sha1_to_hex (their_tree)); - - status =run_command (&cp) ? (-1 ) :0 ; -discard_cache (); -read_cache (); -return status; -} - -/** * Attempt a threeway merge, using index_path as the temporary index. */ static int fall_back_threeway (const struct am_state *state,const char *index_path) { -unsigned char orig_tree[GIT_SHA1_RAWSZ ], their_tree[GIT_SHA1_RAWSZ ], - our_tree[GIT_SHA1_RAWSZ ]; +struct object_id orig_tree, their_tree, our_tree; +const struct object_id *bases[1 ] = { &orig_tree }; +struct merge_options o; +struct commit *result; +char *their_tree_name; -if (get_sha1 ("HEAD" , our_tree) <0 ) -hashcpy (our_tree,EMPTY_TREE_SHA1_BIN ); +if (get_oid ("HEAD" , &our_tree) <0 ) +hashcpy (our_tree.hash,EMPTY_TREE_SHA1_BIN );if (build_fake_ancestor (state, index_path))return error ("could not build fake ancestor" );
@@ -1627,7 +1598,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_padiscard_cache ();read_cache_from (index_path); -if (write_index_as_tree (orig_tree, &the_index, index_path,0 ,NULL )) +if (write_index_as_tree (orig_tree.hash, &the_index, index_path,0 ,NULL ))return error (_ ("Repository lacks necessary blobs to fall back on 3-way merge." ));say (state, stdout,_ ("Using index info to reconstruct a base tree..." ));
@@ -1643,7 +1614,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_painit_revisions (&rev_info,NULL ); rev_info.diffopt.output_format =DIFF_FORMAT_NAME_STATUS ;diff_opt_parse (&rev_info.diffopt, &diff_filter_str,1 , rev_info.prefix); -add_pending_sha1 (&rev_info,"HEAD" , our_tree,0 ); +add_pending_sha1 (&rev_info,"HEAD" , our_tree.hash,0 );diff_setup_done (&rev_info.diffopt);run_diff_index (&rev_info,1 ); }
@@ -1652,7 +1623,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pareturn error (_ ("Did you hand edit your patch?\n" "It does not apply to blobs recorded in its index." )); -if (write_index_as_tree (their_tree, &the_index, index_path,0 ,NULL )) +if (write_index_as_tree (their_tree.hash, &the_index, index_path,0 ,NULL ))return error ("could not write tree" );say (state, stdout,_ ("Falling back to patching base and 3-way merge..." ));
@@ -1668,11 +1639,22 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa* changes. */ -if (run_fallback_merge_recursive (state, orig_tree, our_tree, their_tree)) { +init_merge_options (&o); + + o.branch1 ="HEAD" ; + their_tree_name =xstrfmt ("%.*s" ,linelen (state->msg), state->msg); + o.branch2 = their_tree_name; + +if (state->quiet) + o.verbosity =0 ; + +if (merge_recursive_generic (&o, &our_tree, &their_tree,1 , bases, &result)) {rerere (state->allow_rerere_autoupdate); +free (their_tree_name);return error (_ ("Failed to merge in the changes." )); } +free (their_tree_name);return 0 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 12/16 merge-recursive: flush output buffer before printing error messages
In reply to Johannes SchindelinThe data structure passed to the recursive merge machinery has a feature where the caller can ask for the output to be buffered into a strbuf, by setting the field 'buffer_output'.
Previously, we died without flushing, losing accumulated output. With this patch, we show the output first, and only then print the error message.
Currently, the only user of that buffering is merge_recursive() itself, to avoid the progress output to interfere.
In the next patches, we will introduce a new buffer_output mode that forces merge_recursive() to retain the output buffer for further processing by the caller. If the caller asked for that, we will then also write the error messages into the output buffer. This is necessary to give the caller more control not only how to react in case of errors but also control how/if to display the error messages.
--- merge-recursive.c | 116 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 48 deletions(-)
merge-recursive.c +68 -48
@@ -23,6 +23,28 @@#include "dir.h" #include "submodule.h" +static void flush_output (struct merge_options *o) +{ +if (o->obuf.len) { +fputs (o->obuf.buf, stdout); +strbuf_reset (&o->obuf); + } +} + +static int err (struct merge_options *o,const char *err, ...) +{ +va_list params; + +flush_output (o); +va_start (params, err); +strbuf_vaddf (&o->obuf, err, params); +va_end (params); +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); + +return -1 ; +} +static struct tree *shift_tree_object (struct tree *one,struct tree *two,const char *subtree_shift) {
@@ -148,14 +170,6 @@ static int show(struct merge_options *o, int v)return (!o->call_depth && o->verbosity >= v) || o->verbosity >=5 ; } -static void flush_output (struct merge_options *o) -{ -if (o->obuf.len) { -fputs (o->obuf.buf, stdout); -strbuf_reset (&o->obuf); - } -} - __attribute__((format (printf,3 ,4 )))static void output (struct merge_options *o,int v,const char *fmt, ...) {
@@ -198,7 +212,8 @@ static void output_commit_title(struct merge_options *o, struct commit *commit) } } -static int add_cacheinfo (unsigned int mode,const struct object_id *oid, +static int add_cacheinfo (struct merge_options *o, +unsigned int mode,const struct object_id *oid,const char *path,int stage,int refresh,int options) {struct cache_entry *ce;
@@ -206,7 +221,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, ce =make_cache_entry (mode, oid ? oid->hash : null_sha1, path, stage,0 );if (!ce) -return error (_ ("addinfo_cache failed for path '%s'" ), path); +return err (o,_ ("addinfo_cache failed for path '%s'" ), path); ret =add_cache_entry (ce, options);if (refresh) {
@@ -276,7 +291,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)if (!cache_tree_fully_valid (active_cache_tree) &&cache_tree_update (&the_index,0 ) <0 ) { -error (_ ("error building trees" )); +err (o,_ ("error building trees" ));return NULL ; }
@@ -544,7 +559,8 @@ static struct string_list *get_renames(struct merge_options *o,return renames; } -static int update_stages (const char *path,const struct diff_filespec *o, +static int update_stages (struct merge_options *opt,const char *path, +const struct diff_filespec *o,const struct diff_filespec *a,const struct diff_filespec *b) {
@@ -563,13 +579,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,if (remove_file_from_cache (path))return -1 ;if (o) -if (add_cacheinfo (o->mode, &o->oid, path,1 ,0 , options)) +if (add_cacheinfo (opt, o->mode, &o->oid, path,1 ,0 , options))return -1 ;if (a) -if (add_cacheinfo (a->mode, &a->oid, path,2 ,0 , options)) +if (add_cacheinfo (opt, a->mode, &a->oid, path,2 ,0 , options))return -1 ;if (b) -if (add_cacheinfo (b->mode, &b->oid, path,3 ,0 , options)) +if (add_cacheinfo (opt, b->mode, &b->oid, path,3 ,0 , options))return -1 ;return 0 ; }
@@ -720,8 +736,8 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (status) {if (status ==SCLD_EXISTS )/* something else exists */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); -return error (msg, path,"" ); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,"" ); }/*
@@ -729,7 +745,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)* tracking it. */ if (would_lose_untracked (path)) -return error (_ ("refusing to lose untracked file at '%s'" ), +return err (o,_ ("refusing to lose untracked file at '%s'" ), path);/* Successful unlink is good.. */
@@ -739,7 +755,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)if (errno ==ENOENT )return 0 ;/* .. but not some other error (who really cares what?) */ -return error (msg, path,_ (": perhaps a D/F conflict?" )); +return err (o, msg, path,_ (": perhaps a D/F conflict?" )); } static int update_file_flags(struct merge_options *o,
@@ -771,9 +787,9 @@ static int update_file_flags(struct merge_options *o, buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path); +return err (o,_ ("cannot read object %s '%s'" ),oid_to_hex (oid), path);if (type !=OBJ_BLOB ) { - ret =error (_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); + ret =err (o,_ ("blob expected for %s '%s'" ),oid_to_hex (oid), path); goto free_buf; }if (S_ISREG (mode)) {
@@ -797,8 +813,8 @@ static int update_file_flags(struct merge_options *o, mode =0666 ; fd =open (path,O_WRONLY |O_TRUNC |O_CREAT , mode);if (fd <0 ) { - ret =error_errno (_ ("failed to open '%s'" ), - path); + ret =err (o,_ ("failed to open '%s': %s" ), + path,strerror (errno)); goto free_buf; }write_in_full (fd, buf, size);
@@ -808,17 +824,19 @@ static int update_file_flags(struct merge_options *o,safe_create_leading_directories_const (path);unlink (path);if (symlink (lnk, path)) - ret =error_errno (_ ("failed to symlink '%s'" ), path); + ret =err (o,_ ("failed to symlink '%s': %s" ), + path,strerror (errno));free (lnk); }else - ret =error (_ ("do not know what to do with %06o %s '%s'" ), - mode,oid_to_hex (oid), path); + ret =err (o, +_ ("do not know what to do with %06o %s '%s'" ), + mode,oid_to_hex (oid), path); free_buf:free (buf); } update_index:if (!ret && update_cache) -add_cacheinfo (mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD ); +add_cacheinfo (o, mode, oid, path,0 , update_wd,ADD_CACHE_OK_TO_ADD );return ret; }
@@ -951,12 +969,12 @@ static int merge_file_1(struct merge_options *o, branch1, branch2);if ((merge_status <0 ) || !result_buf.ptr) - ret =error (_ ("Failed to execute internal merge" )); + ret =err (o,_ ("Failed to execute internal merge" ));if (!ret &&write_sha1_file (result_buf.ptr, result_buf.size, blob_type, result->oid.hash)) - ret =error (_ ("Unable to add %s to database" ), - a->path); + ret =err (o,_ ("Unable to add %s to database" ), + a->path);free (result_buf.ptr);if (ret)
@@ -1122,7 +1140,7 @@ static int conflict_rename_delete(struct merge_options *o,if (o->call_depth)return remove_file_from_cache (dest->path);else -return update_stages (dest->path,NULL , +return update_stages (o, dest->path,NULL , rename_branch == o->branch1 ? dest :NULL , rename_branch == o->branch1 ?NULL : dest); }
@@ -1180,9 +1198,9 @@ static int handle_file(struct merge_options *o,if ((ret =update_file (o,0 , &rename->oid, rename->mode, dst_name))) ;/* fall through, do allow dst_name to be released */ else if (stage ==2 ) - ret =update_stages (rename->path,NULL , rename, add); + ret =update_stages (o, rename->path,NULL , rename, add);else - ret =update_stages (rename->path,NULL , add, rename); + ret =update_stages (o, rename->path,NULL , add, rename);if (dst_name != rename->path)free (dst_name);
@@ -1575,23 +1593,25 @@ static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)return (is_null_oid (oid) || mode ==0 ) ?NULL : (struct object_id *)oid; } -static int read_oid_strbuf (const struct object_id *oid,struct strbuf *dst) +static int read_oid_strbuf (struct merge_options *o, +const struct object_id *oid,struct strbuf *dst) {void *buf;enum object_type type;unsigned long size; buf =read_sha1_file (oid->hash, &type, &size);if (!buf) -return error (_ ("cannot read object %s" ),oid_to_hex (oid)); +return err (o,_ ("cannot read object %s" ),oid_to_hex (oid));if (type !=OBJ_BLOB ) {free (buf); -return error (_ ("object %s is not a blob" ),oid_to_hex (oid)); +return err (o,_ ("object %s is not a blob" ),oid_to_hex (oid)); }strbuf_attach (dst, buf, size, size +1 );return 0 ; } -static int blob_unchanged(const struct object_id *o_oid, +static int blob_unchanged(struct merge_options *opt, + const struct object_id *o_oid, unsigned o_mode, const struct object_id *a_oid, unsigned a_mode,
@@ -1609,7 +1629,7 @@ static int blob_unchanged(const struct object_id *o_oid,return 0 ;assert (o_oid && a_oid); -if (read_oid_strbuf (o_oid, &o) ||read_oid_strbuf (a_oid, &a)) +if (read_oid_strbuf (opt, o_oid, &o) ||read_oid_strbuf (opt, a_oid, &a)) goto error_return;/* * Note: binary | is used so that both renormalizations are
@@ -1698,7 +1718,7 @@ static int merge_content(struct merge_options *o,*/ path_renamed_outside_HEAD = !path2 || !strcmp (path, path2);if (!path_renamed_outside_HEAD) { -add_cacheinfo (mfi.mode, &mfi.oid, path, +add_cacheinfo (o, mfi.mode, &mfi.oid, path,0 , (!o->call_depth),0 );return mfi.clean; }
@@ -1711,7 +1731,7 @@ static int merge_content(struct merge_options *o,output (o,1 ,_ ("CONFLICT (%s): Merge conflict in %s" ), reason, path);if (rename_conflict_info && !df_conflict_remains) -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }
@@ -1721,7 +1741,7 @@ static int merge_content(struct merge_options *o,remove_file_from_cache (path); }else {if (!mfi.clean) { -if (update_stages (path, &one, &a, &b)) +if (update_stages (o, path, &one, &a, &b))return -1 ; }else {int file_from_stage2 =was_tracked (path);
@@ -1729,7 +1749,7 @@ static int merge_content(struct merge_options *o,oidcpy (&merged.oid, &mfi.oid); merged.mode = mfi.mode; -if (update_stages (path,NULL , +if (update_stages (o, path,NULL , file_from_stage2 ? &merged :NULL , file_from_stage2 ?NULL : &merged))return -1 ;
@@ -1797,8 +1817,8 @@ static int process_entry(struct merge_options *o, }else if (o_oid && (!a_oid || !b_oid)) {/* Case A: Deleted in one */ if ((!a_oid && !b_oid) || - (!b_oid &&blob_unchanged (o_oid, o_mode, a_oid, a_mode, normalize, path)) || - (!a_oid &&blob_unchanged (o_oid, o_mode, b_oid, b_mode, normalize, path))) { + (!b_oid &&blob_unchanged (o, o_oid, o_mode, a_oid, a_mode, normalize, path)) || + (!a_oid &&blob_unchanged (o, o_oid, o_mode, b_oid, b_mode, normalize, path))) {/* Deleted in both or deleted in one and * unchanged in the other */ if (a_oid)
@@ -1894,7 +1914,7 @@ int merge_trees(struct merge_options *o,if (code !=0 ) {if (show (o,4 ) || o->call_depth) -error (_ ("merging of trees %s and %s failed" ), +err (o,_ ("merging of trees %s and %s failed" ),oid_to_hex (&head->object.oid),oid_to_hex (&merge->object.oid));return -1 ;
@@ -2029,7 +2049,7 @@ int merge_recursive(struct merge_options *o, o->call_depth--;if (!merged_common_ancestors) -return error (_ ("merge returned no commit" )); +return err (o,_ ("merge returned no commit" )); }discard_cache ();
@@ -2088,7 +2108,7 @@ int merge_recursive_generic(struct merge_options *o,for (i =0 ; i < num_base_list; ++i) {struct commit *base;if (!(base =get_ref (base_list[i],oid_to_hex (base_list[i])))) -return error (_ ("Could not parse object '%s'" ), +return err (o,_ ("Could not parse object '%s'" ),oid_to_hex (base_list[i]));commit_list_insert (base, &ca); }
@@ -2102,7 +2122,7 @@ int merge_recursive_generic(struct merge_options *o,if (active_cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK )) -return error (_ ("Unable to write index." )); +return err (o,_ ("Unable to write index." ));return clean ?0 :1 ; }
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 13/16 merge-recursive: write the commit title in one go
In reply to Johannes SchindelinIn 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we changed the code such that it prints the output in one go, to avoid interfering with the progress output.
Let's make sure that the same holds true when outputting the commit
title: previously, we used several printf() statements to stdout and assumed that stdout's buffer is large enough to hold the entire commit title.
Apart from making that speculation unnecessary, we change the code to add the message to the output buffer before flushing for another reason:
the next commit will introduce a new level of output buffering, where the caller can request the output not to be flushed, but to be retained for further processing.
This latter feature will be needed when teaching the sequencer to do rebase -i's brunt work: it wants to control the output of the cherry-picks (i.e. recursive merges).
--- merge-recursive.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
merge-recursive.c +9 -8
@@ -191,25 +191,26 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)static void output_commit_title (struct merge_options *o,struct commit *commit) { -int i; -flush_output (o); -for (i = o->call_depth; i--;) -fputs (" " , stdout); +strbuf_addchars (&o->obuf,' ' , o->call_depth *2 );if (commit->util) -printf ("virtual %s\n" ,merge_remote_util (commit)->name); +strbuf_addf (&o->obuf,"virtual %s\n" , +merge_remote_util (commit)->name);else { -printf ("%s " ,find_unique_abbrev (commit->object.oid.hash,DEFAULT_ABBREV )); +strbuf_addf (&o->obuf,"%s " , +find_unique_abbrev (commit->object.oid.hash, +DEFAULT_ABBREV ));if (parse_commit (commit) !=0 ) -printf (_ ("(bad commit)\n" )); +strbuf_addf (&o->obuf,_ ("(bad commit)\n" ));else {const char *title;const char *msg =get_commit_buffer (commit,NULL );int len =find_commit_subject (msg, &title);if (len) -printf ("%.*s\n" , len, title); +strbuf_addf (&o->obuf,"%.*s\n" , len, title);unuse_commit_buffer (commit, msg); } } +flush_output (o); } static int add_cacheinfo(struct merge_options *o,
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 14/16 merge-recursive: offer an option to retain the output in 'obuf'
In reply to Johannes SchindelinSince 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we already accumulate the output in a buffer. The idea was to avoid interfering with the progress output that goes to stderr, which is unbuffered, when we write to stdout, which is buffered.
We extend that buffering to allow the caller to handle the output (possibly suppressing it). This will help us when extending the sequencer to do rebase -i's brunt work: it does not want the picks to print anything by default but instead determine itself whether to print the output or not.
Note that we also redirect the error messages into the output buffer when the caller asked not to flush the output buffer, for two reasons:
1) to retain the correct output order, and 2) to allow the caller to suppress *all* output.
--- merge-recursive.c | 17 +++++++++++++---- merge-recursive.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
merge-recursive.c +13 -4
@@ -25,7 +25,7 @@static void flush_output (struct merge_options *o) { -if (o->obuf.len) { +if (o->buffer_output <2 && o->obuf.len) {fputs (o->obuf.buf, stdout);strbuf_reset (&o->obuf); }
@@ -35,12 +35,21 @@ static int err(struct merge_options *o, const char *err, ...) {va_list params; -flush_output (o); +if (o->buffer_output <2 ) +flush_output (o); +else { +strbuf_complete (&o->obuf,'\n' ); +strbuf_addstr (&o->obuf,"error: " ); + }va_start (params, err);strbuf_vaddf (&o->obuf, err, params);va_end (params); -error ("%s" , o->obuf.buf); -strbuf_reset (&o->obuf); +if (o->buffer_output >1 ) +strbuf_addch (&o->obuf,'\n' ); +else { +error ("%s" , o->obuf.buf); +strbuf_reset (&o->obuf); + }return -1 ; }
merge-recursive.h +1 -1
@@ -13,7 +13,7 @@ struct merge_options {MERGE_RECURSIVE_THEIRS } recursive_variant;const char *subtree_shift; - unsigned buffer_output : 1; +unsigned buffer_output;/* 1: output at end, 2: keep buffered */ unsigned renormalize : 1;long xdl_opts;int verbosity;
Signature · 1 line
2.9.0.281.g286a8d9
PATCH v6 15/16 Ensure that the output buffer is released after calling merge_trees()
In reply to Johannes SchindelinThe recursive merge machinery accumulates its output in an output buffer, to be flushed at the end of merge_recursive(). At this point, we forgot to release the output buffer.
When calling merge_trees() (i.e. the non-recursive part of the recursive merge) directly, the output buffer is never flushed because the caller may be merge_recursive() which wants to flush the output itself.
For the same reason, merge_trees() cannot release the output buffer: it may still be needed.
Forgetting to release the output buffer did not matter much when running git-checkout, or git-merge-recursive, because we exited after the operation anyway. Ever since cherry-pick learned to pick a commit range, however, this memory leak had the potential of becoming a problem.
--- builtin/checkout.c | 1 + merge-recursive.c | 2 ++ sequencer.c | 1 + 3 files changed, 4 insertions(+)
builtin/checkout.c +1 -0
@@ -573,6 +573,7 @@ static int merge_working_tree(const struct checkout_opts *opts,exit (128 ); ret =reset_tree (new->commit->tree, opts,0 , writeout_error); +strbuf_release (&o.obuf);if (ret)return ret; }
merge-recursive.c +2 -0
@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (!o->call_depth && o->buffer_output <2 ) +strbuf_release (&o->obuf);if (show (o,2 ))diff_warn_rename_limit ("merge.renamelimit" , o->needed_rename_limit,0 );
sequencer.c +1 -0
@@ -293,6 +293,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean =merge_trees (&o, head_tree, next_tree, base_tree, &result); +strbuf_release (&o.obuf);if (clean <0 )return clean;
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 15/16] Ensure that the output buffer is released after calling merge_trees()
Quoted 9 lines · Johannes Schindelin
The recursive merge machinery accumulates its output in an output buffer, to be flushed at the end of
merge_recursive(). At this point, we forgot to release the output buffer.
...merge-recursive.c +0
-0
merge-recursive.c int merge_recursive(struct merge_options *o, · line 2082
Quoted 5 lines
merge-recursive.c +2
-0@@ -2078,6 +2078,8 @@ int merge_recursive(struct merge_options *o,commit_list_insert (h2, &(*result)->parents->next); }flush_output (o); +if (!o->call_depth && o->buffer_output <2 ) +strbuf_release (&o->obuf);
OK, with !o->call_depth the change makes sense to me.
PATCH v6 16/16 merge-recursive: flush output buffer even when erroring out
In reply to Johannes SchindelinEver since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we had a problem: When the merge failed in a fatal way, all regular output was swallowed because we called die() and did not get a chance to drain the output buffers.
To fix this, several modifications were necessary:
- we needed to stop die()ing, to give callers a chance to do something when an error occurred (in this case, flush the output buffers),
- we needed to delay printing the error message so that the caller can print the buffered output before that, and
- we needed to make sure that the output buffers are flushed even when the return value indicates an error.
The first two changes were introduced through earlier commits in this patch series, and this commit addresses the third one.
--- merge-recursive.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
merge-recursive.c +3 -1
@@ -2069,8 +2069,10 @@ int merge_recursive(struct merge_options *o, o->ancestor ="merged common ancestors" ; clean =merge_trees (o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); -if (clean <0 ) +if (clean <0 ) { +flush_output (o);return clean; + }if (o->call_depth) { *result =make_virtual_commit (mrtree,"merged tree" );
Signature · 1 line
2.9.0.281.g286a8d9
Re: [PATCH v6 16/16] merge-recursive: flush output buffer even when erroring out
Quoted 4 lines · Johannes Schindelin
Ever since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we had a problem: When the merge failed in a fatal way, all regular output was swallowed because we called
die()and did not get a chance to drain the output buffers.
OK. Even though I really wanted to see somebody else review this series as well, I finished reading it through one more time before that happened, which is unfortunate because I think this is ready to start cooking in 'next' even though I no longer have much faith in my eyes alone after staring at this series so many times---you start missing details.
Thanks.
Re: [PATCH v6 16/16] merge-recursive: flush output buffer even when erroring out
Hi Junio,
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Ever since 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we had a problem: When the merge failed in a fatal way, all regular output was swallowed because we called
die()and did not get a chance to drain the output buffers.
Quoted 6 lines
OK. Even though I really wanted to see somebody else review this series as well, I finished reading it through one more time before that happened, which is unfortunate because I think this is ready to start cooking in 'next' even though I no longer have much faith in my eyes alone after staring at this series so many times---you start missing details.
Yeah, well, it is a rather crucial piece of the code.
But then, I really tried my best to re-review the series a couple of times (with my primary focus on robustness, not elegance) after working on different tasks for a couple of days.
Combined with my long-term dogfooding and my readiness to jump on any breakage I may have introduced, I am relatively confident nevertheless.
Thank you so much for your patient reviews!
Ciao,
Dscho
Re: [PATCH v6 16/16] merge-recursive: flush output buffer even when erroring out
Quoted 9 lines · Johannes Schindelin
Quoted 6 lines · Junio C Hamano
OK. Even though I really wanted to see somebody else review this series as well, I finished reading it through one more time before that happened, which is unfortunate because I think this is ready to start cooking in 'next' even though I no longer have much faith in my eyes alone after staring at this series so many times---you start missing details.
Quoted 3 lines
Yeah, well, it is a rather crucial piece of the code.
...
Thank you so much for your patient reviews!
Thanks for working on this to you, too ;-)