git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Stefan Beller <sbeller@google.com>,
	git@vger.kernel.org, sahlberg@google.com
Subject: Re: [PATCH] refs.c: add a function to append a reflog entry to a fd
Date: Thu, 20 Nov 2014 08:57:32 -0800	[thread overview]
Message-ID: <xmqqmw7l4xoj.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20141120023655.GG6527@google.com> (Jonathan Nieder's message of "Wed, 19 Nov 2014 18:36:55 -0800")

Jonathan Nieder <jrnieder@gmail.com> writes:

>> Break out the code to create the string and writing it to the file
>> descriptor from log_ref_write and add it into a dedicated function
>> log_ref_write_fd.
>
> (grammar) I'm having trouble parsing the above.

Yeah, I can see what it wants to say, but still...

>> Let's discuss the change and decide if I shouldsend a follow up patch to change
>> it into snprintf.
>
> Both sprintf and snprintf are error-prone functions.  It would be
> lovely in a followup to use strbuf_addf or xstrfmt in this code path.
> strbufs are how git deals with bookkeeping for string sizes --- they
> are very pleasant.

Yeah, that solves both sides of not stomping on other peoples' data
(which may lead to replaced return address and such) and not giving
broken result (which may cause trouble to the callers) equally well
without raising a stink about "security!!!", which is good ;-).

>> @@ -3010,19 +3032,9 @@ static int log_ref_write(const char *refname,
>> const unsigned char *old_sha1,
> [...]
>> +	result = log_ref_write_fd(logfd, old_sha1, new_sha1,
>> +				  git_committer_info(0), msg);
>> +	if (result) {
>>  		int save_errno = errno;
>>  		close(logfd);
>>  		error("Unable to append to %s", log_file);
>
> Since 'result' isn't used here, this could be simplified to
>
> 	if (log_ref_write_fd(...)) {
> 		...
> 	}

Yeah that is a good simplification.

  reply	other threads:[~2014-11-20 16:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20  0:42 [PATCH] refs.c: add a function to append a reflog entry to a fd Stefan Beller
2014-11-20  1:22 ` Junio C Hamano
2014-11-20  1:34   ` Junio C Hamano
2014-11-20  2:05     ` Stefan Beller
2014-11-20  2:36       ` Jonathan Nieder
2014-11-20 16:57         ` Junio C Hamano [this message]
2014-11-20 18:37         ` [PATCH v3] " Stefan Beller
2014-11-20 21:20           ` Jonathan Nieder
2014-11-20 21:24             ` Stefan Beller
2014-11-20 21:31               ` Jonathan Nieder
2014-11-20 21:42           ` Junio C Hamano
2014-11-20 21:58             ` Stefan Beller
2014-11-20 22:05               ` Jonathan Nieder
2014-11-20 22:11                 ` Junio C Hamano
2014-11-20 21:59             ` [PATCH v4] " Stefan Beller
2014-11-20 22:11               ` Jonathan Nieder
2014-11-20 22:29                 ` Junio C Hamano
2014-11-20  1:42 ` [PATCH] " Jonathan Nieder

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=xmqqmw7l4xoj.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=sahlberg@google.com \
    --cc=sbeller@google.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).