git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] index-pack: do not segfault when keep_name is NULL
Date: Mon, 17 Mar 2014 15:07:01 -0700	[thread overview]
Message-ID: <xmqqmwgobhtm.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1394965862-8173-1-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Sun, 16 Mar 2014 17:31:02 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> keep_name is used to print error messages a couple lines down. Reset
> it to the real path returned by odb_pack_keep() if it's set to NULL by
> caller.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  One of these moments I will make git log and friends optionally recognize
>  "Diff-Options:" line in commit message. Adding -U14 in this case
>  should help the reviewer to see how those error messages are printed.
>
>  builtin/index-pack.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index a6b1c17..d95c3dc 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -1283,9 +1283,10 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
>  	if (keep_msg) {
>  		int keep_fd, keep_msg_len = strlen(keep_msg);
>  
> -		if (!keep_name)
> +		if (!keep_name) {
>  			keep_fd = odb_pack_keep(name, sizeof(name), sha1);
> -		else
> +			keep_name = name;
> +		} else
>  			keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);

I think this fixes the right problem in a wrong way that hurts
longer-term maintainability.  Why not do

	keep_name ? keep_name : name

at the place where the name is used?  Otherwise you will have to
worry about affecting later codepaths that may want to try to use
!keep_name to switch between two codepaths, no?

>  
>  		if (keep_fd < 0) {

  reply	other threads:[~2014-03-17 22:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-16 10:31 [PATCH] index-pack: do not segfault when keep_name is NULL Nguyễn Thái Ngọc Duy
2014-03-17 22:07 ` Junio C Hamano [this message]
2014-03-17 23:07 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
  -- strict thread matches above, loose matches on Subject: below --
2014-03-16 13:34 [PATCH 0/4] Better "gc --aggressive" Nguyễn Thái Ngọc Duy
2014-03-16 13:35 ` [PATCH] index-pack: do not segfault when keep_name is NULL Nguyễn Thái Ngọc Duy

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=xmqqmwgobhtm.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /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).