# Problem with cg-clone

6 messages from 2005-10-29 to 2005-10-29. Participants: Marcel Holtmann, Junio C Hamano, Linus Torvalds.
Thread: https://gitlist.dev/t/2270

## Marcel Holtmann, 2005-10-29 17:08

Subject: Problem with cg-clone
Message-ID: <1130605726.5396.39.camel@blade>
URL: https://gitlist.dev/e/1130605726.5396.39.camel%40blade

```
Hi guys,

I installed the latest git and cogito from their repositories and now
the local clone command is failing:

# cg-clone linux-2.6 test-2.6
defaulting to local storage area
Using hard links
`/data/kernel/linux-2.6/.git/HEAD' -> `.git/refs/heads/.origin-fetching'
error: Couldn't find 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404: not separate or in any pack
Cannot obtain needed object 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404
while processing commit 0000000000000000000000000000000000000000.
cg-fetch: objects fetch failed
cg-clone: fetch failed

Previously this was working fine and since cogito hasn't changed the
last few days, I suspect that git is at fault here or changed something.
Any ideas?

Regards

Marcel

```

## Junio C Hamano, 2005-10-29 19:41

Subject: Re: Problem with cg-clone
Message-ID: <7vacgs157c.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vacgs157c.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <1130605726.5396.39.camel@blade>

```
Marcel Holtmann <marcel@holtmann.org> writes:

> Previously this was working fine and since cogito hasn't changed the
> last few days, I suspect that git is at fault here or changed something.
> Any ideas?

I think I know what is going on.

git-init-db does not create .git/objects/[0-9a-f]{2}/
directories anymore, but git-local-fetch has not taught to
create them on demand.

```

## Linus Torvalds, 2005-10-29 19:57

Subject: Re: Problem with cg-clone
Message-ID: <Pine.LNX.4.64.0510291255230.3348@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0510291255230.3348%40g5.osdl.org
In-Reply-To: <7vacgs157c.fsf@assigned-by-dhcp.cox.net>

```


On Sat, 29 Oct 2005, Junio C Hamano wrote:
>
> Marcel Holtmann <marcel@holtmann.org> writes:
> 
> > Previously this was working fine and since cogito hasn't changed the
> > last few days, I suspect that git is at fault here or changed something.
> > Any ideas?
> 
> I think I know what is going on.
> 
> git-init-db does not create .git/objects/[0-9a-f]{2}/
> directories anymore, but git-local-fetch has not taught to
> create them on demand.

Here's a quick hack, totally untested, of course.

More properly it should use move_temp_to_file(), but if you're about to do 
a v0.99.9 release, maybe this could be good enough.

		Linus

---

diff --git a/local-fetch.c b/local-fetch.c
index 87a93de..21f5bf8 100644
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -52,9 +52,20 @@ static int setup_indices(void)
 	return 0;
 }
 
-static int copy_file(const char *source, const char *dest, const char *hex,
+static int copy_file(const char *source, char *dest, const char *hex,
 		     int warn_if_not_exists)
 {
+	char *dir = strrchr(dest, '/');
+
+	if (dir) {
+		*dir = 0;
+		if (mkdir(dir, 0777)) {
+			if (errno != EEXIST)
+				perror(dir);
+		}
+		*dir = '/';
+	}
+
 	if (use_link) {
 		if (!link(source, dest)) {
 			pull_say("link %s\n", hex);
@@ -150,7 +161,7 @@ static int fetch_file(const unsigned cha
 	static int object_name_start = -1;
 	static char filename[PATH_MAX];
 	char *hex = sha1_to_hex(sha1);
-	const char *dest_filename = sha1_file_name(sha1);
+	char *dest_filename = sha1_file_name(sha1);
 
  	if (object_name_start < 0) {
 		strcpy(filename, path); /* e.g. git.git */

```

## Junio C Hamano, 2005-10-29 19:59

Subject: Re: Problem with cg-clone
Message-ID: <7vwtjwytzw.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vwtjwytzw.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <1130605726.5396.39.camel@blade>

```
Marcel Holtmann <marcel@holtmann.org> writes:

> I installed the latest git and cogito from their repositories and now
> the local clone command is failing:
>
> # cg-clone linux-2.6 test-2.6
> defaulting to local storage area
> Using hard links
> `/data/kernel/linux-2.6/.git/HEAD' -> `.git/refs/heads/.origin-fetching'
> error: Couldn't find 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404: not separate or in any pack
> Cannot obtain needed object 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404
> while processing commit 0000000000000000000000000000000000000000.
> cg-fetch: objects fetch failed
> cg-clone: fetch failed

The attached patch should fix git-local-fetch which I think the
above problem is.  git-clone -l -s would be much faster if you
are doing a local clone, however.

---

diff --git a/local-fetch.c b/local-fetch.c
index 87a93de..0a07114 100644
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -52,9 +52,10 @@ static int setup_indices(void)
 	return 0;
 }
 
-static int copy_file(const char *source, const char *dest, const char *hex,
+static int copy_file(const char *source, char *dest, const char *hex,
 		     int warn_if_not_exists)
 {
+	safe_create_leading_directories(dest);
 	if (use_link) {
 		if (!link(source, dest)) {
 			pull_say("link %s\n", hex);
@@ -150,7 +151,7 @@ static int fetch_file(const unsigned cha
 	static int object_name_start = -1;
 	static char filename[PATH_MAX];
 	char *hex = sha1_to_hex(sha1);
-	const char *dest_filename = sha1_file_name(sha1);
+	char *dest_filename = sha1_file_name(sha1);
 
  	if (object_name_start < 0) {
 		strcpy(filename, path); /* e.g. git.git */

```

## Marcel Holtmann, 2005-10-29 20:10

Subject: Re: Problem with cg-clone
Message-ID: <1130616653.5396.56.camel@blade>
URL: https://gitlist.dev/e/1130616653.5396.56.camel%40blade
In-Reply-To: <7vwtjwytzw.fsf@assigned-by-dhcp.cox.net>

```
Hi Junio,

> > I installed the latest git and cogito from their repositories and now
> > the local clone command is failing:
> >
> > # cg-clone linux-2.6 test-2.6
> > defaulting to local storage area
> > Using hard links
> > `/data/kernel/linux-2.6/.git/HEAD' -> `.git/refs/heads/.origin-fetching'
> > error: Couldn't find 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404: not separate or in any pack
> > Cannot obtain needed object 8a212ab6b8a4ccc6f3c3d1beba5f92655c576404
> > while processing commit 0000000000000000000000000000000000000000.
> > cg-fetch: objects fetch failed
> > cg-clone: fetch failed
> 
> The attached patch should fix git-local-fetch which I think the
> above problem is.  git-clone -l -s would be much faster if you
> are doing a local clone, however.

I can confirm that with this patch everything is back to normal.

Regards

Marcel

```

## Junio C Hamano, 2005-10-29 20:19

Subject: Re: Problem with cg-clone
Message-ID: <7vslukyt2q.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vslukyt2q.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <1130616653.5396.56.camel@blade>

```
Marcel Holtmann <marcel@holtmann.org> writes:

>> The attached patch should fix git-local-fetch which I think the
>> above problem is.  git-clone -l -s would be much faster if you
>> are doing a local clone, however.
>
> I can confirm that with this patch everything is back to normal.

Thanks.  What Linus separately done (funny we did that
two-minutes apart) amounts to the same thing.

```
