Re: [PATCH 05/15] sequencer: lib'ify read_and_refresh_cache()
Johannes Schindelin writes: > To be truly useful, the sequencer should never die() but always return > an error. > > Signed-off-by: Johannes Schindelin > --- > sequencer.c | 15 ++- > 1 file changed, 10 insertions(+), 5 deletions(-) Instead of dying there, you let the caller high up in the callchain to notice the error and handle it (by dying). There are two call sites of read_and_refresh_cache(), one of which is pick_commits(), whose callers you already verified that they are prepared to do the right thing given an "error" return from it when you did 3/15, so the conversion is safe. The other one, sequencer_pick_revisions() is also prepared to relay an error return back to its caller and you made sure its callers are all safe when you did 3/15. Good. > diff --git a/sequencer.c b/sequencer.c > index b90294f..a8c3a48 100644 > --- a/sequencer.c > +++ b/sequencer.c > @@ -638,18 +638,21 @@ static int prepare_revs(struct replay_opts *opts) > return 0; > } > > -static void read_and_refresh_cache(struct replay_opts *opts) > +static int read_and_refresh_cache(struct replay_opts *opts) > { > static struct lock_file index_lock; > int index_fd = hold_locked_index(&index_lock, 0); > if (read_index_preload(&the_index, NULL) < 0) > - die(_("git %s: failed to read the index"), action_name(opts)); > + return error(_("git %s: failed to read the index"), > + action_name(opts)); > refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, > NULL); > if (the_index.cache_changed && index_fd >= 0) { > if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) > - die(_("git %s: failed to refresh the index"), > action_name(opts)); > + return error(_("git %s: failed to refresh the index"), > + action_name(opts)); > } > rollback_lock_file(&index_lock); > + return 0; > } > > static int format_todo(struct strbuf *buf, struct commit_list *todo_list, > @@ -977,7 +980,8 @@ static int pick_commits(struct commit_list *todo_list, > struct replay_opts *opts) > if (opts->allow_ff) > assert(!(opts->signoff || opts->no_commit || > opts->record_origin || opts->edit)); > - read_and_refresh_cache(opts); > + if (read_and_refresh_cache(opts)) > + return -1; > > for (cur = todo_list; cur; cur = cur->next) { > save_todo(cur, opts); > @@ -1041,7 +1045,8 @@ int sequencer_pick_revisions(struct replay_opts *opts) > if (opts->subcommand == REPLAY_NONE) > assert(opts->revs); > > - read_and_refresh_cache(opts); > + if (read_and_refresh_cache(opts)) > + return -1; > > /* >* Decide what to do depending on the arguments; a fresh -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 05/15] sequencer: lib'ify read_and_refresh_cache()
Hi Eric, On Wed, 24 Aug 2016, Eric Sunshine wrote: > On Tue, Aug 23, 2016 at 12:07 PM, Johannes Schindelin > wrote: > > To be truly useful, the sequencer should never die() but always return > > an error. > > > > Signed-off-by: Johannes Schindelin > > --- > > diff --git a/sequencer.c b/sequencer.c > > @@ -638,18 +638,21 @@ static int prepare_revs(struct replay_opts *opts) > > -static void read_and_refresh_cache(struct replay_opts *opts) > > +static int read_and_refresh_cache(struct replay_opts *opts) > > { > > static struct lock_file index_lock; > > int index_fd = hold_locked_index(&index_lock, 0); > > if (read_index_preload(&the_index, NULL) < 0) > > - die(_("git %s: failed to read the index"), > > action_name(opts)); > > + return error(_("git %s: failed to read the index"), > > + action_name(opts)); > > refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, > > NULL, NULL); > > if (the_index.cache_changed && index_fd >= 0) { > > if (write_locked_index(&the_index, &index_lock, > > COMMIT_LOCK)) > > - die(_("git %s: failed to refresh the index"), > > action_name(opts)); > > + return error(_("git %s: failed to refresh the > > index"), > > + action_name(opts)); > > Do these two error returns need to rollback the lockfile? Here, too, the atexit() handler does the job, and again, this is not a change in behavior. Thanks for your review! Dscho -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 05/15] sequencer: lib'ify read_and_refresh_cache()
On Tue, Aug 23, 2016 at 12:07 PM, Johannes Schindelin wrote: > To be truly useful, the sequencer should never die() but always return > an error. > > Signed-off-by: Johannes Schindelin > --- > diff --git a/sequencer.c b/sequencer.c > @@ -638,18 +638,21 @@ static int prepare_revs(struct replay_opts *opts) > -static void read_and_refresh_cache(struct replay_opts *opts) > +static int read_and_refresh_cache(struct replay_opts *opts) > { > static struct lock_file index_lock; > int index_fd = hold_locked_index(&index_lock, 0); > if (read_index_preload(&the_index, NULL) < 0) > - die(_("git %s: failed to read the index"), action_name(opts)); > + return error(_("git %s: failed to read the index"), > + action_name(opts)); > refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, > NULL); > if (the_index.cache_changed && index_fd >= 0) { > if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) > - die(_("git %s: failed to refresh the index"), > action_name(opts)); > + return error(_("git %s: failed to refresh the index"), > + action_name(opts)); Do these two error returns need to rollback the lockfile? > } > rollback_lock_file(&index_lock); > + return 0; > } -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 05/15] sequencer: lib'ify read_and_refresh_cache()
To be truly useful, the sequencer should never die() but always return an error. Signed-off-by: Johannes Schindelin --- sequencer.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sequencer.c b/sequencer.c index b90294f..a8c3a48 100644 --- a/sequencer.c +++ b/sequencer.c @@ -638,18 +638,21 @@ static int prepare_revs(struct replay_opts *opts) return 0; } -static void read_and_refresh_cache(struct replay_opts *opts) +static int read_and_refresh_cache(struct replay_opts *opts) { static struct lock_file index_lock; int index_fd = hold_locked_index(&index_lock, 0); if (read_index_preload(&the_index, NULL) < 0) - die(_("git %s: failed to read the index"), action_name(opts)); + return error(_("git %s: failed to read the index"), + action_name(opts)); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); if (the_index.cache_changed && index_fd >= 0) { if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) - die(_("git %s: failed to refresh the index"), action_name(opts)); + return error(_("git %s: failed to refresh the index"), + action_name(opts)); } rollback_lock_file(&index_lock); + return 0; } static int format_todo(struct strbuf *buf, struct commit_list *todo_list, @@ -977,7 +980,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit)); - read_and_refresh_cache(opts); + if (read_and_refresh_cache(opts)) + return -1; for (cur = todo_list; cur; cur = cur->next) { save_todo(cur, opts); @@ -1041,7 +1045,8 @@ int sequencer_pick_revisions(struct replay_opts *opts) if (opts->subcommand == REPLAY_NONE) assert(opts->revs); - read_and_refresh_cache(opts); + if (read_and_refresh_cache(opts)) + return -1; /* * Decide what to do depending on the arguments; a fresh -- 2.10.0.rc1.99.gcd66998 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html