From: Junio C Hamano <gitster@pobox.com>
To: Duy Nguyen <pclouds@gmail.com>
Cc: "Eric Sunshine" <sunshine@sunshineco.com>,
"Git List" <git@vger.kernel.org>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
tim@tim-landscheidt.de
Subject: Re: [PATCH v2 1/3] am: add --show-current-patch
Date: Fri, 02 Feb 2018 10:56:22 -0800 [thread overview]
Message-ID: <xmqq372jdxux.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180202092511.GA28946@ash> (Duy Nguyen's message of "Fri, 2 Feb 2018 16:25:11 +0700")
Duy Nguyen <pclouds@gmail.com> writes:
> Subject: [PATCH] Preserve errno in case case before calling sth_errno()
>
> All these locations do something like this
>
> sth_errno(..., somefunc(...));
>
> where somefunc() can potentially change errno, which will be read by
> sth_errno(). Call somefunc separately with errno preserved to avoid
> this.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> builtin/am.c | 8 +++++++-
> builtin/commit.c | 8 ++++++--
> builtin/init-db.c | 9 ++++++---
> rerere.c | 9 ++++++---
> shallow.c | 27 ++++++++++++++++++---------
> 5 files changed, 43 insertions(+), 18 deletions(-)
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index c9b7946bad..e384749f73 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -570,9 +570,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
> set_git_work_tree(work_tree);
> else
> set_git_work_tree(git_work_tree_cfg);
> - if (access(get_git_work_tree(), X_OK))
> - die_errno (_("Cannot access work tree '%s'"),
> - get_git_work_tree());
> + if (access(get_git_work_tree(), X_OK)) {
> + int saved_errno = errno;
> + const char *path = get_git_work_tree();
> + errno = saved_errno;
> + die_errno(_("Cannot access work tree '%s'"), path);
> + }
> }
This one is the most faithful conversion from "mechanical rewrite"
point of view, but I wonder if we should instead take the returned
path from get_git_work_tree() and use it in both calls. After all,
this is hardly performance sensitive codepath, so even "an obviously
safe but wasteful with extra xstrdup/free" version
work_tree_path = xstrdup(get_git_work_tree());
if (access(work_tree_path, X_OK))
die_errno(_("msg..."), work_tree_path);
free(work_tree_path);
may be an improvement.
> diff --git a/rerere.c b/rerere.c
> index 1ce440f4bb..f19a53ff2c 100644
> --- a/rerere.c
> +++ b/rerere.c
> @@ -683,9 +683,12 @@ static int merge(const struct rerere_id *id, const char *path)
> * A successful replay of recorded resolution.
> * Mark that "postimage" was used to help gc.
> */
> - if (utime(rerere_path(id, "postimage"), NULL) < 0)
> - warning_errno("failed utime() on %s",
> - rerere_path(id, "postimage"));
> + if (utime(rerere_path(id, "postimage"), NULL) < 0) {
> + int saved_errno = errno;
> + const char *path = rerere_path(id, "postimage");
> + errno = saved_errno;
> + warning_errno("failed utime() on %s", path);
> + }
Likewise.
> diff --git a/shallow.c b/shallow.c
> index df4d44ea7a..9da82f5292 100644
> --- a/shallow.c
> +++ b/shallow.c
> @@ -295,9 +295,12 @@ const char *setup_temporary_shallow(const struct oid_array *extra)
> temp = xmks_tempfile(git_path("shallow_XXXXXX"));
>
> if (write_in_full(temp->fd, sb.buf, sb.len) < 0 ||
> - close_tempfile_gently(temp) < 0)
> - die_errno("failed to write to %s",
> - get_tempfile_path(temp));
> + close_tempfile_gently(temp) < 0) {
> + int saved_errno = errno;
> + const char *path = get_tempfile_path(temp);
> + errno = saved_errno;
> + die_errno("failed to write to %s", path);
> + }
It feels a bit questionable to my taste to pretend that we are truly
oblivious to how trivial get_tempfile_path() is, i.e. no more than
just a few field accesses to "tempfile" struct. It buries more
important thing that is happening in the code in noise.
> @@ -319,9 +322,12 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
Likewise.
> @@ -366,9 +372,12 @@ void prune_shallow(int show_only)
Likewise.
All others I snipped looked like good changes. Thanks.
next prev parent reply other threads:[~2018-02-02 18:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-26 9:55 [PATCH 0/2] Add "git rebase --show-patch" Nguyễn Thái Ngọc Duy
2018-01-26 9:55 ` [PATCH 1/2] am: add --show-patch Nguyễn Thái Ngọc Duy
2018-01-26 9:55 ` [PATCH 2/2] rebase: " Nguyễn Thái Ngọc Duy
2018-01-26 11:12 ` Phillip Wood
2018-01-26 11:22 ` Duy Nguyen
2018-01-30 11:15 ` Phillip Wood
2018-01-26 19:11 ` Eric Sunshine
2018-01-27 1:42 ` Duy Nguyen
2018-01-26 18:47 ` [PATCH 0/2] Add "git rebase --show-patch" Tim Landscheidt
2018-01-27 1:45 ` Duy Nguyen
2018-01-27 11:26 ` Ævar Arnfjörð Bjarmason
2018-01-29 15:09 ` Johannes Schindelin
2018-01-30 9:10 ` Duy Nguyen
2018-01-30 12:32 ` Johannes Schindelin
2018-01-30 20:19 ` Junio C Hamano
2018-02-01 2:06 ` Tim Landscheidt
2018-01-31 9:30 ` [PATCH v2 0/3] " Nguyễn Thái Ngọc Duy
2018-01-31 9:30 ` [PATCH v2 1/3] am: add --show-current-patch Nguyễn Thái Ngọc Duy
2018-01-31 9:40 ` Eric Sunshine
2018-01-31 22:59 ` Junio C Hamano
2018-02-02 9:25 ` Duy Nguyen
2018-02-02 9:46 ` Eric Sunshine
2018-02-02 9:53 ` Duy Nguyen
2018-02-02 18:56 ` Junio C Hamano [this message]
2018-01-31 9:30 ` [PATCH] gitignore.txt: elaborate shell glob syntax Nguyễn Thái Ngọc Duy
2018-01-31 23:22 ` Junio C Hamano
2018-02-01 9:59 ` Duy Nguyen
2018-01-31 9:30 ` [PATCH v2 2/3] rebase: add --show-current-patch Nguyễn Thái Ngọc Duy
2018-01-31 9:30 ` [PATCH v2 3/3] rebase: introduce and use pseudo-ref ORIG_COMMIT Nguyễn Thái Ngọc Duy
2018-01-31 23:18 ` Junio C Hamano
2018-02-01 10:02 ` Duy Nguyen
2018-02-02 19:00 ` Junio C Hamano
2018-02-01 11:05 ` Phillip Wood
2018-02-11 9:43 ` [PATCH v3 0/3] Add "git rebase --show-current-patch" Nguyễn Thái Ngọc Duy
2018-02-11 9:43 ` [PATCH v3 1/3] am: add --show-current-patch Nguyễn Thái Ngọc Duy
2018-02-11 9:43 ` [PATCH v3 2/3] rebase: " Nguyễn Thái Ngọc Duy
2018-02-11 9:43 ` [PATCH v3 3/3] rebase: introduce and use pseudo-ref REBASE_HEAD Nguyễn Thái Ngọc Duy
2018-02-22 0:21 ` [PATCH v3 0/3] Add "git rebase --show-current-patch" Junio C Hamano
2018-02-22 0:54 ` Tim Landscheidt
2018-02-23 10:20 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq372jdxux.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=sunshine@sunshineco.com \
--cc=tim@tim-landscheidt.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).