From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Clemens Buchacher <drizzd@aon.at>, git@vger.kernel.org
Subject: Re: [PATCH] fix recursive-merge of empty files with different permissions
Date: Thu, 13 Mar 2008 11:50:08 -0700 [thread overview]
Message-ID: <7vabl2xxun.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: alpine.LSU.1.00.0803131607030.1656@racer.site
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> diff --git a/builtin-merge-file.c b/builtin-merge-file.c
> index adce6d4..cde4b2c 100644
> --- a/builtin-merge-file.c
> +++ b/builtin-merge-file.c
> @@ -57,7 +57,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
>
> if (!f)
> ret = error("Could not open %s for writing", filename);
> - else if (fwrite(result.ptr, result.size, 1, f) != 1)
> + else if (result.size &&
> + fwrite(result.ptr, result.size, 1, f) != 1)
> ret = error("Could not write to %s", filename);
> else if (fclose(f))
> ret = error("Could not close %s", filename);
Lol. We are dealing with N-byte quantity so we send one record of length
N and make sure we processed one record, and it does not work when N is
zero.
We could instead send N records of size 1 and make sure we processed N
records to lose the conditional instead, but the patch avoids unnecessary
call to fread/fwrite so that is good. Thanks.
It felt funny because my current bedtime reading happens to be "Zero: The
Biography of a Dangerous Idea (ISBN 0140296476)".
> diff --git a/xdiff-interface.c b/xdiff-interface.c
> index bba2364..61dc5c5 100644
> --- a/xdiff-interface.c
> +++ b/xdiff-interface.c
> @@ -152,8 +152,8 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
> if ((f = fopen(filename, "rb")) == NULL)
> return error("Could not open %s", filename);
> sz = xsize_t(st.st_size);
> - ptr->ptr = xmalloc(sz);
> - if (fread(ptr->ptr, sz, 1, f) != 1)
> + ptr->ptr = xmalloc(sz ? sz : 1);
> + if (sz && fread(ptr->ptr, sz, 1, f) != 1)
> return error("Could not read %s", filename);
> fclose(f);
> ptr->size = sz;
Do you need to actually allocate ptr->ptr when sz is zero, instead of
setting it to NULL, like:
sz = xsize_t(st.st_size);
ptr->size = sz;
if (!sz)
ptr->ptr = NULL;
else {
ptr->ptr = xmalloc(sz);
if (fread(ptr->ptr, 1, sz, f) != sz)
return error("Could not read %s", filename);
}
fclose(f);
next prev parent reply other threads:[~2008-03-13 18:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-08 17:17 [PATCH] fix recursive-merge of empty files with different permissions Clemens Buchacher
2008-03-08 17:51 ` Johannes Schindelin
2008-03-13 12:52 ` Clemens Buchacher
2008-03-13 15:19 ` Johannes Schindelin
2008-03-13 18:50 ` Junio C Hamano [this message]
2008-03-13 21:28 ` Johannes Schindelin
2008-03-13 19:22 ` [PATCH] merge-recursive: cause a conflict if file mode does not match Clemens Buchacher
2008-03-13 21:17 ` Johannes Schindelin
2008-03-13 22:47 ` [PATCH] merge-recursive: handle file mode changes Clemens Buchacher
2008-03-13 23:40 ` Johannes Schindelin
2008-03-14 9:21 ` [PATCH] merge-recursive: handle file mode and links similarly to file content Clemens Buchacher
2008-03-14 10:13 ` Clemens Buchacher
2008-03-14 0:08 ` [PATCH] merge-recursive: handle file mode changes Junio C Hamano
2008-03-14 0:12 ` Junio C Hamano
2008-03-14 13:02 ` Clemens Buchacher
2008-03-14 0:17 ` Jakub Narebski
2008-03-14 12:56 ` Clemens Buchacher
2008-03-14 10:15 ` Junio C Hamano
2008-03-14 12:17 ` Clemens Buchacher
2008-03-14 16:01 ` Junio C Hamano
2008-03-14 17:28 ` Clemens Buchacher
2008-03-14 17:49 ` Junio C Hamano
2008-03-14 10:07 ` [PATCH] merge-recursive: cause a conflict if file mode does not match Clemens Buchacher
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=7vabl2xxun.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
/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).