git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Don't allow fast-import tree delta chains to exceed maximum depth
Date: Tue, 13 Nov 2007 21:46:01 -0800	[thread overview]
Message-ID: <7vhcjpnzvq.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20071114044842.GA6876@spearce.org> (Shawn O. Pearce's message of "Tue, 13 Nov 2007 23:48:42 -0500")

"Shawn O. Pearce" <spearce@spearce.org> writes:

>  Junio, this patch is against maint.  It will apply cleanly to maint
>  but is also crafted to ensure it should apply to next with git-am -3.
>  Its a real bug that's lasted a long time in fast-import.  I think
>  it is maint material.

Thanks.

> diff --git a/fast-import.c b/fast-import.c
> index c07e3d8..7544949 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -154,13 +154,16 @@ Format of STDIN stream:
>  
>  #define PACK_ID_BITS 16
>  #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
> +#define DEPTH_BITS 13
> +#define MAX_DEPTH ((1<<DEPTH_BITS)-1)
>  
>  struct object_entry
>  {
>  	struct object_entry *next;
>  	uint32_t offset;
> -	unsigned type : TYPE_BITS;
> -	unsigned pack_id : PACK_ID_BITS;
> +	uint32_t type : TYPE_BITS,
> +		pack_id : PACK_ID_BITS,
> +		depth : DEPTH_BITS;
>  	unsigned char sha1[20];
>  };

uint32_t with bit-width specifiers look somewhat funny here...

>  
> @@ -1105,7 +1108,7 @@ static int store_object(
>  		unsigned pos = sizeof(hdr) - 1;
>  
>  		delta_count_by_type[type]++;
> -		last->depth++;
> +		e->depth = ++last->depth++;

"lvalue required as increment operand"?

Wouldn't it be easier to read like this?

diff --git a/fast-import.c b/fast-import.c
index 7544949..d32c412 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -161,7 +161,7 @@ struct object_entry
 {
 	struct object_entry *next;
 	uint32_t offset;
-	uint32_t type : TYPE_BITS,
+	unsigned type : TYPE_BITS,
 		pack_id : PACK_ID_BITS,
 		depth : DEPTH_BITS;
 	unsigned char sha1[20];
@@ -1108,7 +1108,7 @@ static int store_object(
 		unsigned pos = sizeof(hdr) - 1;
 
 		delta_count_by_type[type]++;
-		e->depth = ++last->depth++;
+		e->depth = last->depth + 1;
 
 		hdrlen = encode_header(OBJ_OFS_DELTA, deltalen, hdr);
 		write_or_die(pack_data->pack_fd, hdr, hdrlen);
@@ -1121,8 +1121,6 @@ static int store_object(
 		pack_size += sizeof(hdr) - pos;
 	} else {
 		e->depth = 0;
-		if (last)
-			last->depth = 0;
 		hdrlen = encode_header(type, datlen, hdr);
 		write_or_die(pack_data->pack_fd, hdr, hdrlen);
 		pack_size += hdrlen;
@@ -1138,6 +1136,7 @@ static int store_object(
 			free(last->data);
 		last->data = dat;
 		last->offset = e->offset;
+		last->depth = e->depth;
 		last->len = datlen;
 	}
 	return 0;

  parent reply	other threads:[~2007-11-14  5:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-14  4:48 [PATCH] Don't allow fast-import tree delta chains to exceed maximum depth Shawn O. Pearce
2007-11-14  5:45 ` Brian Downing
2007-11-14  5:46 ` Junio C Hamano [this message]
2007-11-14  5:54   ` Shawn O. Pearce

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=7vhcjpnzvq.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.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).