From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: carlos.duclos@nokia.com, git@vger.kernel.org
Subject: Re: [PATCH v2] git-archive: Add new option "--output" to write archive to a file instead of stdout.
Date: Mon, 16 Feb 2009 13:38:02 -0800 [thread overview]
Message-ID: <7v8wo6f4g5.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <4999C884.5050209@lsrfire.ath.cx> (René Scharfe's message of "Mon, 16 Feb 2009 21:11:48 +0100")
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> carlos.duclos@nokia.com schrieb:
>> NOTE: I can only use a webmail client, so some of the tabs might have
>> overwritten by it. If that's the case I'll resend the patch as MIME
>> attachment.
>
> Please do, as applying the patch as-is would be difficult, painful even.
Thanks. I agree with everything you said in your review, and adding a bit
more.
>> diff --git a/archive.c b/archive.c
>> index e6de039..fde8602 100644
>> --- a/archive.c
>> +++ b/archive.c
>> @@ -239,6 +239,18 @@ static void parse_treeish_arg(const char **argv,
>> ar_args->time = archive_time;
>> }
>>
>> +static void create_output_file(const char *output_file)
>> +{
>> + int output_fd = creat(output_file, 0666);
"git grep -n -w -e 'creat' -- '*.c'" shows nothing; we seem to prefer
using a longhand:
open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666);
instead. Personally I see nothing wrong in creat(2) per-se, but let's be
consistent.
>> + if (dup2(output_fd, 1) != 1)
>> + {
>> + close(output_fd);
>> + die("could not redirect output");
>> + }
>> +}
>
> Style:
> if (condition) {
> do(something);
> ...
> }
>
> output_fd can be closed after dup2()ing.
If the user is sick enough to close fd#1 from the shell when running
archive, it could already be pointing at fd#1 ;-)
> A successful dup2() call can return 0 on some systems (mingw here).
Yikes.
The logic would become:
fd = creat();
if (fd < 0)
die();
if (fd != 1) {
if (dup2(fd, 1) < 0 || close(fd))
die();
}
>> @@ -294,6 +308,9 @@ static int parse_archive_args(int argc, const char **argv,
>> if (!base)
>> base = "";
>>
>> + if(output)
Style: if (output)
prev parent reply other threads:[~2009-02-16 21:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-16 17:37 [PATCH v2] git-archive: Add new option "--output" to write archive to a file instead of stdout carlos.duclos
2009-02-16 17:59 ` Sverre Rabbelier
2009-02-16 20:11 ` René Scharfe
2009-02-16 21:38 ` Junio C Hamano [this message]
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=7v8wo6f4g5.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=carlos.duclos@nokia.com \
--cc=git@vger.kernel.org \
--cc=rene.scharfe@lsrfire.ath.cx \
/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).