git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/3] am: add --show-current-patch

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 2, 2018, 18:56 UTC
Message-ID
<xmqq372jdxux.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180202092511.GA28946@ash>
Duy Nguyen <pclouds@gmail.com> writes:
Show 18 quoted lines
> 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(-)
Show 18 quoted lines
> 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.
Show 17 quoted lines
> 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.
Show 17 quoted lines
> 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.
Previous: Duy NguyenNext: Nguyễn Thái Ngọc Duy
Message 24 of 40 in “Add "git rebase --show-patch"”
  1. 0/2 Add "git rebase --show-patch"Nguyễn Thái Ngọc Duy, Jan 26, 2018
  2. 1/2 am: add --show-patchNguyễn Thái Ngọc Duy, Jan 26, 2018
  3. 2/2 rebase: add --show-patchNguyễn Thái Ngọc Duy, Jan 26, 2018
  4. Phillip WoodJan 26, 2018
  5. Duy NguyenJan 26, 2018
  6. Phillip WoodJan 30, 2018
  7. Eric SunshineJan 26, 2018
  8. Duy NguyenJan 27, 2018
  9. Tim LandscheidtJan 26, 2018
  10. Duy NguyenJan 27, 2018
  11. Ævar Arnfjörð BjarmasonJan 27, 2018
  12. Johannes SchindelinJan 29, 2018
  13. Duy NguyenJan 30, 2018
  14. Johannes SchindelinJan 30, 2018
  15. Junio C HamanoJan 30, 2018
  16. Tim LandscheidtFeb 1, 2018
  17. 0/3 Add "git rebase --show-patch"Nguyễn Thái Ngọc Duy, Jan 31, 2018
  18. 1/3 am: add --show-current-patchNguyễn Thái Ngọc Duy, Jan 31, 2018
  19. Eric SunshineJan 31, 2018
  20. Junio C HamanoJan 31, 2018
  21. Duy NguyenFeb 2, 2018
  22. Eric SunshineFeb 2, 2018
  23. Duy NguyenFeb 2, 2018
  24. Junio C HamanoFeb 2, 2018
  25. gitignore.txt: elaborate shell glob syntaxNguyễn Thái Ngọc Duy, Jan 31, 2018
  26. Junio C HamanoJan 31, 2018
  27. Duy NguyenFeb 1, 2018
  28. 2/3 rebase: add --show-current-patchNguyễn Thái Ngọc Duy, Jan 31, 2018
  29. 3/3 rebase: introduce and use pseudo-ref ORIG_COMMITNguyễn Thái Ngọc Duy, Jan 31, 2018
  30. Junio C HamanoJan 31, 2018
  31. Duy NguyenFeb 1, 2018
  32. Junio C HamanoFeb 2, 2018
  33. Phillip WoodFeb 1, 2018
  34. 0/3 Add "git rebase --show-current-patch"Nguyễn Thái Ngọc Duy, Feb 11, 2018
  35. 1/3 am: add --show-current-patchNguyễn Thái Ngọc Duy, Feb 11, 2018
  36. 2/3 rebase: add --show-current-patchNguyễn Thái Ngọc Duy, Feb 11, 2018
  37. 3/3 rebase: introduce and use pseudo-ref REBASE_HEADNguyễn Thái Ngọc Duy, Feb 11, 2018
  38. Junio C HamanoFeb 22, 2018
  39. Tim LandscheidtFeb 22, 2018
  40. Duy NguyenFeb 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.