git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Nicolas Pitre <nico@cam.org>
Cc: git@vger.kernel.org, Jon Smirl <jonsmirl@gmail.com>
Subject: [OT] perhaps we want to support copied-context diff output
Date: Sat, 08 Dec 2007 00:18:56 -0800	[thread overview]
Message-ID: <7vmyslwqdr.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: alpine.LFD.0.99999.0712072357050.555@xanadu.home

The patch looks correct, but I have an offtopic comment that does not
have anything to do with the problem being discussed right now.

Nicolas Pitre <nico@cam.org> writes:

> diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
> index 4f44658..5002cc6 100644
> --- a/builtin-pack-objects.c
> +++ b/builtin-pack-objects.c
> @@ -1245,28 +1245,37 @@ static void get_object_details(void)
> ...
>  static int type_size_sort(const void *_a, const void *_b)
>  {
>  	const struct object_entry *a = *(struct object_entry **)_a;
>  	const struct object_entry *b = *(struct object_entry **)_b;
>  
> -	if (a->type < b->type)
> -		return -1;
>  	if (a->type > b->type)
> -		return 1;
> -	if (a->hash < b->hash)
>  		return -1;
> -	if (a->hash > b->hash)
> +	if (a->type < b->type)
>  		return 1;
> -	if (a->preferred_base < b->preferred_base)
> +	if (a->hash > b->hash)
>  		return -1;
> -	if (a->preferred_base > b->preferred_base)
> +	if (a->hash < b->hash)
>  		return 1;
> -	if (a->size < b->size)
> +	if (a->preferred_base > b->preferred_base)
>  		return -1;
> +	if (a->preferred_base < b->preferred_base)
> +		return 1;
>  	if (a->size > b->size)
> +		return -1;
> +	if (a->size < b->size)
>  		return 1;
> -	return a > b ? -1 : (a < b);  /* newest last */
> +	return a < b ? -1 : (a > b);  /* newest first */
>  }

Before being able to understand what was going on, I had to shuffle the
above patch by duplicating the context lines, prefix them with '-' and
then '+', and grouping preimage lines and postimage lines together, to
come up with this patch:

 static int type_size_sort(const void *_a, const void *_b)
 {
 	const struct object_entry *a = *(struct object_entry **)_a;
 	const struct object_entry *b = *(struct object_entry **)_b;
 
-	if (a->type < b->type)
-		return -1;
-	if (a->type > b->type)
-		return 1;
-	if (a->hash < b->hash)
-		return -1;
-	if (a->hash > b->hash)
-		return 1;
-	if (a->preferred_base < b->preferred_base)
-		return -1;
-	if (a->preferred_base > b->preferred_base)
-		return 1;
-	if (a->size < b->size)
-		return -1;
-	if (a->size > b->size)
-		return 1;
-	return a > b ? -1 : (a < b);  /* newest last */
+	if (a->type > b->type)
+		return -1;
+	if (a->type < b->type)
+		return 1;
+	if (a->hash > b->hash)
+		return -1;
+	if (a->hash < b->hash)
+		return 1;
+	if (a->preferred_base > b->preferred_base)
+		return -1;
+	if (a->preferred_base < b->preferred_base)
+		return 1;
+	if (a->size > b->size)
+		return -1;
+	if (a->size < b->size)
+		return 1;
+	return a < b ? -1 : (a > b);  /* newest first */
 }

Perhaps we may want to add "diff -c" (copied context) output format as
an option, which may be easier to read.

A possible alternative with much less impact to our toolset would be to
stay with unified context format but employ some heuristics (e.g. "a
hunk has many small context lines between preimage and postimage pairs")
and rewrite the diff output automatically like what I did by hand above.

The problematic region has 26 lines, among which 9 lines are deleted
material and 9 lines are added material, and it contains 8 isolated
groups of unchanged material, one line each.  A heuristics to notice
such excessively large number of groups of unchanged lines compared to
the size of the hunk itself would be reasonably easy to implement.

  reply	other threads:[~2007-12-08  8:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-08  5:00 [PATCH 1/2] pack-objects: reverse the delta search sort list Nicolas Pitre
2007-12-08  8:18 ` Junio C Hamano [this message]
2007-12-08  8:53   ` [OT] perhaps we want to support copied-context diff output Mike Hommey
2007-12-08 11:10     ` Peter Baumann

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=7vmyslwqdr.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonsmirl@gmail.com \
    --cc=nico@cam.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).