# [PATCH] pretend-sha1: grave bugfix.

4 messages from 2007-02-16 to 2007-02-16. Participants: Junio C Hamano, Johannes Schindelin, Shawn O. Pearce.
Thread: https://gitlist.dev/t/6839

## Junio C Hamano, 2007-02-16 01:16

Subject: [PATCH] pretend-sha1: grave bugfix.
Message-ID: <7v3b56dhr1.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v3b56dhr1.fsf%40assigned-by-dhcp.cox.net

```
We stashed away objects that we pretend to have, but did not save the
actual data.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 * I wonder how recent merge-recursive with multiple merge bases
   (or an empty one) ever worked with this bug.  Am I
   hallucinating?

 sha1_file.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index b83f59f..2c87031 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1545,11 +1545,13 @@ int pretend_sha1_file(void *buf, unsigned long len, const char *type, unsigned c
 	co = &cached_objects[cached_object_nr++];
 	co->size = len;
 	co->type = strdup(type);
+	co->buf = xmalloc(len);
+	memcpy(co->buf, buf, len);
 	hashcpy(co->sha1, sha1);
 	return 0;
 }
 
-void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
+void *read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
 {
 	unsigned long mapsize;
 	void *map, *buf;
-- 
1.5.0.31.g78e90

```

## Johannes Schindelin, 2007-02-16 04:05

Subject: Re: [PATCH] pretend-sha1: grave bugfix.
Message-ID: <Pine.LNX.4.63.0702160503290.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702160503290.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <7v3b56dhr1.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Thu, 15 Feb 2007, Junio C Hamano wrote:

>  * I wonder how recent merge-recursive with multiple merge bases
>    (or an empty one) ever worked with this bug.  Am I
>    hallucinating?

Probably the fact helped that merge-recursive only pretends 
zero-sized blobs.

Ciao,
Dscho

```

## Shawn O. Pearce, 2007-02-16 05:09

Subject: Re: [PATCH] pretend-sha1: grave bugfix.
Message-ID: <20070216050943.GD28894@spearce.org>
URL: https://gitlist.dev/e/20070216050943.GD28894%40spearce.org
In-Reply-To: <Pine.LNX.4.63.0702160503290.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> On Thu, 15 Feb 2007, Junio C Hamano wrote:
> 
> >  * I wonder how recent merge-recursive with multiple merge bases
> >    (or an empty one) ever worked with this bug.  Am I
> >    hallucinating?
> 
> Probably the fact helped that merge-recursive only pretends 
> zero-sized blobs.

Most definately.  We never look at the pointer to an object's data if
len == 0, which it does in this case of merge-recursive's empty tree.

Aren't we using this for git-blame --contents?  How'd that ever
work for a non-empty file?

-- 
Shawn.

```

## Junio C Hamano, 2007-02-16 07:29

Subject: Re: [PATCH] pretend-sha1: grave bugfix.
Message-ID: <7v8xeya7bw.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8xeya7bw.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070216050943.GD28894@spearce.org>

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

> Aren't we using this for git-blame --contents?  How'd that ever
> work for a non-empty file?

My guess is that git-blame's blob handling has its own built-in
cache to avoid read_sha1_file(), and that single "initial" blob
is primed by hand, so read_sha1_file() is usually not called for
that object name.

```
