From: Junio C Hamano <gitster@pobox.com>
To: John Keeping <john@keeping.me.uk>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] diffcore-break: don't divide by zero
Date: Tue, 02 Apr 2013 14:15:17 -0700 [thread overview]
Message-ID: <7vvc84ab2y.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <a2b6c61371ac6ff1e180c6600e57499ff94b2fd2.1364931627.git.john@keeping.me.uk> (John Keeping's message of "Tue, 2 Apr 2013 20:50:31 +0100")
John Keeping <john@keeping.me.uk> writes:
> When the source file is empty, the calculation of the merge score
> results in a division by zero. Since the merge score is initialized to
> zero, it makes sense to just leave it as it is if the source size is
> zero. This means that we still use the extent of damage metric to
> decide whether to break the filepair.
Well spotted. An empty blob to another blob that is larger than 400
bytes will trigger div0, and it makes sense to leave merge-score to
0 (i.e. do not show as whole-delete-then-whole-add after rename
detection is done and the broken filepair is merged back).
Actually, if src->size is 0, we probably shouldn't break the filepair
in the first place. That is, if your preimage and postimage looked
like these:
== preimage == == postimage ==
F (empty file) F (a large file)
E (a new empty file)
do we want to see F renamed to E and then a new file created as F
while running "git diff -B -M"? I doubt it.
So in that sense, this might be a better solution. I dunno.
diffcore-break.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/diffcore-break.c b/diffcore-break.c
index 44f8678..eabafd5 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -67,6 +67,8 @@ static int should_break(struct diff_filespec *src,
max_size = ((src->size > dst->size) ? src->size : dst->size);
if (max_size < MINIMUM_BREAK_SIZE)
return 0; /* we do not break too small filepair */
+ if (src->size == 0)
+ return 0; /* we do not let empty files get renamed */
if (diffcore_count_changes(src, dst,
&src->cnt_data, &dst->cnt_data,
next prev parent reply other threads:[~2013-04-02 21:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-02 19:50 [PATCH 0/2] Fixes for undefined behaviour John Keeping
2013-04-02 19:50 ` [PATCH 1/2] diffcore-break: don't divide by zero John Keeping
2013-04-02 21:15 ` Junio C Hamano [this message]
2013-04-02 21:36 ` John Keeping
2013-04-02 22:41 ` Junio C Hamano
2013-04-03 19:24 ` [PATCH v2] " John Keeping
2013-04-02 19:50 ` [PATCH 2/2] bisect: avoid signed integer overflow John Keeping
2013-04-02 21:09 ` Junio C Hamano
2013-04-03 19:17 ` John Keeping
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=7vvc84ab2y.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=john@keeping.me.uk \
/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).