Skip to contentSkip to conversation

Garbage in .git directories???

PATCH In review Dmitry Torokhov 7 participants 23 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

I just did:

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

[dtor@anvil work]$ ls -la .git/
total 40

drwxrwxr-x    9 dtor dtor 4096 Sep 17 21:17 .
drwxrwxr-x    3 dtor dtor 4096 Sep 17 21:17 ..
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 branches
-rw-rw-r--    1 dtor dtor   58 Sep 17 21:17 description
lrwxrwxrwx    1 dtor dtor   17 Sep 17 21:17 HEAD -> refs/heads/master
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 hooks
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 info
drwxr-xr-x  260 dtor dtor 4096 Sep 17 17:41 objects
drwxrwxr-x    4 dtor dtor 4096 May  1 19:15 refs
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:28 remotes
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 V?Cl?���?E ???#V?C??ſl??E#V?C??;H
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The similar garbage(?) shows when I clone git's repository.

Is this expected?

Signature · 1 line
Dmitry
#1 lore raw
Quoted 20 lines · Dmitry Torokhov

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

[dtor@anvil work]$ ls -la .git/
total 40

drwxrwxr-x    9 dtor dtor 4096 Sep 17 21:17 .
drwxrwxr-x    3 dtor dtor 4096 Sep 17 21:17 ..
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 branches
-rw-rw-r--    1 dtor dtor   58 Sep 17 21:17 description
lrwxrwxrwx    1 dtor dtor   17 Sep 17 21:17 HEAD -> refs/heads/master
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 hooks
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 info
drwxr-xr-x  260 dtor dtor 4096 Sep 17 17:41 objects
drwxrwxr-x    4 dtor dtor 4096 May  1 19:15 refs
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:28 remotes
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 V?Cl?�?E ???#V?C??ſl??E#V?C??;H
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 2 lines

The similar garbage(?) shows when I clone git's repository.

FWIW, using cg-clone (using git-core 0.99.6 and cogito 0.14.1) I keep finding a directory in .git which consists of a single DEL character (\177).

-hpa

#2 lore raw

Dear diary, on Mon, Sep 19, 2005 at 09:10:19PM CEST, I got a letter where "H. Peter Anvin" <[email protected]> told me that...

Quoted 24 lines
Quoted 23 lines · Dmitry Torokhov

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

[dtor@anvil work]$ ls -la .git/
total 40

drwxrwxr-x    9 dtor dtor 4096 Sep 17 21:17 .
drwxrwxr-x    3 dtor dtor 4096 Sep 17 21:17 ..
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 branches
-rw-rw-r--    1 dtor dtor   58 Sep 17 21:17 description
lrwxrwxrwx    1 dtor dtor   17 Sep 17 21:17 HEAD -> refs/heads/master
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 hooks
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 info
drwxr-xr-x  260 dtor dtor 4096 Sep 17 17:41 objects
drwxrwxr-x    4 dtor dtor 4096 May  1 19:15 refs
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:28 remotes
drwxrwxr-x    2 dtor dtor 4096 Sep 17 21:17 V?Cl?????E 
???#V?C????l??E#V?C??;H
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 5 lines
Quoted 2 lines

The similar garbage(?) shows when I clone git's repository.

FWIW, using cg-clone (using git-core 0.99.6 and cogito 0.14.1) I keep finding a directory in .git which consists of a single DEL character (\177).

Does cg-init produce it too? It really seems that this has to be a bug in git-init-db. If that is the case, could you try temporarily renaming the templates directory?

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox
#3 lore raw
Quoted 6 lines · Petr Baudis
Quoted 2 lines

FWIW, using cg-clone (using git-core 0.99.6 and cogito 0.14.1) I keep finding a directory in .git which consists of a single DEL character (\177).

Does cg-init produce it too? It really seems that this has to be a bug in git-init-db. If that is the case, could you try temporarily renaming the templates directory?

cg-init does produce it, too. I'm not sure what you mean with temporarily renaming the templates directory?

-hpa

#4 lore raw

Dear diary, on Tue, Sep 20, 2005 at 01:16:14AM CEST, I got a letter where "H. Peter Anvin" <[email protected]> told me that...

Quoted 6 lines
Quoted 5 lines · Petr Baudis
Quoted 4 lines

FWIW, using cg-clone (using git-core 0.99.6 and cogito 0.14.1) I keep finding a directory in .git which consists of a single DEL character (\177).

Quoted 6 lines
Quoted 3 lines

Does cg-init produce it too? It really seems that this has to be a bug in git-init-db. If that is the case, could you try temporarily renaming the templates directory?

cg-init does produce it, too. I'm not sure what you mean with temporarily renaming the templates directory?

Preventing git-init-db to copy its stuff into your .git/ - I think the bug is likely somewhere there. Actually, this can be prevented by passing an argument to git-init-db:

	git-init-db --template=somethingnonexisting

Another idea - try this patch:

init-db.c +1 -0
@@ -154,6 +154,7 @@ static void copy_templates(const char *g
 	}
 
 	memcpy(path, git_dir, len);
+	path[len] = 0;
 	copy_templates_1(path, len,
 			 template_path, template_len,
 			 dir);
Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#5 lore raw
Quoted 9 lines · Petr Baudis

Dear diary, on Tue, Sep 20, 2005 at 01:16:14AM CEST, I got a letter

Another idea - try this patch:

init-db.c static void copy_templates(const char *g · line 160

Quoted 7 lines
init-db.c +1 -0
@@ -154,6 +154,7 @@ static void copy_templates(const char *g
 	}
 
 	memcpy(path, git_dir, len);
+	path[len] = 0;
 	copy_templates_1(path, len,
 			 template_path, template_len,
 			 dir);

This seems to have worked.

-hpa

#6 lore raw

PATCH 1/1 Fix git-init-db creating crap directories

Dear diary, on Tue, Sep 20, 2005 at 01:58:52AM CEST, I got a letter where "H. Peter Anvin" <[email protected]> told me that...

Quoted 11 lines
Quoted 10 lines · Petr Baudis

Dear diary, on Tue, Sep 20, 2005 at 01:16:14AM CEST, I got a letter

Another idea - try this patch:

init-db.c +0 -0
@@ -154,6 +154,7 @@ static void copy_templates(const char *g
 	}
 
Quoted 8 lines

init-db.c static void copy_templates(const char *g · line 160

Quoted 6 lines
init-db.c +1 -0
 	memcpy(path, git_dir, len);
+	path[len] = 0;
 	copy_templates_1(path, len,
 			 template_path, template_len,
 			 dir);

This seems to have worked.

Great. Resending a marginally better version with a cool log message and everything.

--

The base target directory for the templates copying was initialized to git_dir, but git_dir[len] is not zero but / at the time we do the initialization. This is not what we want for our target directory string since we pass it to mkdir(), so make it zero-terminated manually.

---
commit dbe1fe2f0d6de58bc0c9f98e6cf9573874612890
tree 30398d409fa27e95e3e592c803f6cd5a93652234
parent 79d2a11ec497fe940ca9a1fd8e0b9f295d39c290
author Petr Baudis <[email protected]> Tue, 20 Sep 2005 01:55:53 +0200 committer Petr Baudis <xpasky@machine.(none)> Tue, 20 Sep 2005 01:55:53 +0200

 init-db.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
init-db.c +2 -1
@@ -153,7 +153,8 @@ static void copy_templates(const char *g
 		return;
 	}
 
-	memcpy(path, git_dir, len);
+	memcpy(path, git_dir, len-1);
+	path[len] = 0;
 	copy_templates_1(path, len,
 			 template_path, template_len,
 			 dir);
Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#7 lore raw

Re: [PATCH] Fix git-init-db creating crap directories

init-db.c static void copy_templates(const char *g · line 158

Quoted 11 lines · Petr Baudis
init-db.c +2 -1
@@ -153,7 +153,8 @@ static void copy_templates(const char *g
 		return;
 	}
 
-	memcpy(path, git_dir, len);
+	memcpy(path, git_dir, len-1);
+	path[len] = 0;
 	copy_templates_1(path, len,

Wrong! You're not initializing path[len-1]!

-hpa

#8 lore raw

PATCH 1/1 Fix git-init-db creating crap directories (zeroth try)

Dear diary, on Tue, Sep 20, 2005 at 02:09:41AM CEST, I got a letter where "H. Peter Anvin" <[email protected]> told me that...

Quoted 8 lines
Quoted 7 lines · Petr Baudis
init-db.c +0 -0
@@ -153,7 +153,8 @@ static void copy_templates(const char *g
 		return;
 	}
 
Quoted 6 lines

init-db.c static void copy_templates(const char *g · line 158

Quoted 4 lines
init-db.c +2 -1
-	memcpy(path, git_dir, len);
+	memcpy(path, git_dir, len-1);
+	path[len] = 0;
 	copy_templates_1(path, len,

Wrong! You're not initializing path[len-1]!

Oops, sorry. That's what you get when you want to make things marginally better. ;-) We indeed want to pass copy_templates_1() the trailing slash as well.

Let's just settle with the original patch then.

--

The base target directory for the templates copying was initialized to git_dir, but git_dir[len] is not zero but / at the time we do the initialization. This is not what we want for our target directory string since we pass it to mkdir(), so make it zero-terminated manually.

---

init-db.c +1 -0
@@ -154,6 +154,7 @@ static void copy_templates(const char *g
 	}
 
 	memcpy(path, git_dir, len);
+	path[len] = 0;
 	copy_templates_1(path, len,
 			 template_path, template_len,
 			 dir);
Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#9 lore raw

Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)

Quoted 9 lines · Petr Baudis
Quoted 7 lines
Quoted 5 lines
(quoted diff) +2 -1
-	memcpy(path, git_dir, len);
+	memcpy(path, git_dir, len-1);
+	path[len] = 0;

copy_templates_1(path, len,

Wrong! You're not initializing path[len-1]!

Quoted 6 lines

Oops, sorry. That's what you get when you want to make things marginally better. ;-) We indeed want to pass copy_templates_1() the trailing slash as well.

Let's just settle with the original patch then.

But if len is the index of the '/', then you're not.

Think about it: the memcpy(path, git_dir, len) copies bytes 0..len-1. Thus you need to use path[len] = 0 to terminate.

If you want to copy len-1 characters, then you need to use path[len-1] = 0.

-hpa

#10 lore raw

Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)

Dear diary, on Tue, Sep 20, 2005 at 02:42:47AM CEST, I got a letter where "H. Peter Anvin" <[email protected]> told me that...

Quoted 10 lines
Quoted 9 lines · Petr Baudis
Quoted 7 lines
Quoted 5 lines
(quoted diff) +2 -1
-	memcpy(path, git_dir, len);
+	memcpy(path, git_dir, len-1);
+	path[len] = 0;

copy_templates_1(path, len,

Wrong! You're not initializing path[len-1]!

Quoted 8 lines
Quoted 6 lines

Oops, sorry. That's what you get when you want to make things marginally better. ;-) We indeed want to pass copy_templates_1() the trailing slash as well.

Let's just settle with the original patch then.

But if len is the index of the '/', then you're not.

But fortunately len is not the index of the '/', len-1 is. len is the length of the leading path fragment including the trailing slash.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#11 lore raw

Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)

Quoted 6 lines · Petr Baudis
Quoted 2 lines

But if len is the index of the '/', then you're not.

But fortunately len is not the index of the '/', len-1 is. len is the length of the leading path fragment including the trailing slash.

Then you'd need len-1 both inside the memcpy() and the assignment, of course.

-hpa

#12 lore raw

Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)

In reply to Petr Baudis
Quoted 3 lines · Petr Baudis
Quoted 3 lines
Quoted 3 lines

Oops, sorry. That's what you get when you want to make things marginally better. ;-) We indeed want to pass copy_templates_1() the trailing slash as well.

Original patch from you is the right one. Thanks.

#13 lore raw
In reply to H. Peter Anvin

H. Peter Anvin <[email protected]> wrote:

[...]

Quoted 3 lines

FWIW, using cg-clone (using git-core 0.99.6 and cogito 0.14.1) I keep finding a directory in .git which consists of a single DEL character (\177).

Using latest cogito (0.15 63ef5488c38b6660c72f042d4aa3015d72a3bd28) + latest git (0.99.7), cloning locally I don't see that. My older repositories (cloned over the net at various times or made locally) don't show it either.

Signature · 4 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513
#14 lore raw
In reply to Dmitry Torokhov
Quoted 10 lines · Dmitry Torokhov

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

drwxrwxr-x 2 dtor dtor 4096 Sep 17 21:17 V?Cl?���?E ???#V?C??ſl??E#V?C??;H

                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

The similar garbage(?) shows when I clone git's repository.

Is this expected?

Absolutely not. And I don't see it when I try. What filesystem are you running this on? Looks like something did a "mkdir()" with an uninitialized pointer, but I don't see how that would happen.

Linus

#15 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 9 lines · Dmitry Torokhov

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

drwxrwxr-x 2 dtor dtor 4096 Sep 17 21:17 V?Cl?���?E ???#V?C??ſl??E#V?C??;H

                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

The similar garbage(?) shows when I clone git's repository.

Quoted 8 lines
Quoted 1 line

Is this expected?

Absolutely not. And I don't see it when I try. What filesystem are you running this on? Looks like something did a "mkdir()" with an uninitialized pointer, but I don't see how that would happen.

Linus

It is ext3 on 2.6.12-rc6.

Signature · 1 line
Dmitry
#16 lore raw
Quoted 14 lines · Dmitry Torokhov
Quoted 13 lines · Linus Torvalds
Quoted 10 lines · Dmitry Torokhov

git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work

and it seems there is some garbage in .git directory:

drwxrwxr-x 2 dtor dtor 4096 Sep 17 21:17 V?Cl?���?E ???#V?C??ſl??E#V?C??;H

                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

The similar garbage(?) shows when I clone git's repository.

Is this expected?

Quoted 9 lines
Quoted 6 lines

Absolutely not. And I don't see it when I try. What filesystem are you running this on? Looks like something did a "mkdir()" with an uninitialized pointer, but I don't see how that would happen.

Linus

It is ext3 on 2.6.12-rc6.

Couple more points - just using rsync to get the data (without using git) does not not produce that wierd directory, only got clone does.

Btw, after doing a pull from git repository git cone now produces the following:

sent 403 bytes received 2164 bytes 570.44 bytes/sec
total size is 533 speedup is 0.21
rsync: link_stat "/scm/git/git.git/objects/info/alternates" (in pub) failed: No such file or directory (2) rsync error: some files could not be transferred (code 23) at main.c(1173)

Signature · 1 line
Dmitry
#17 lore raw
Quoted 7 lines · Dmitry Torokhov

Btw, after doing a pull from git repository git cone now produces the following:

sent 403 bytes received 2164 bytes 570.44 bytes/sec
total size is 533 speedup is 0.21
rsync: link_stat "/scm/git/git.git/objects/info/alternates" (in pub) failed: No such file or directory (2) rsync error: some files could not be transferred (code 23) at main.c(1173)

The garbage directory does ont reproduce for me, but I know what this is. It is an harmless error message -- I'll hide it in the next update. It is checking to see if the remote repository uses alternates just in case -- since git.git does not use it, it just does not find one (and needlessly complains).

#18 lore raw
In reply to Dmitry Torokhov
Quoted 3 lines · Dmitry Torokhov

Couple more points - just using rsync to get the data (without using git) does not not produce that wierd directory, only got clone does.

Does a plain "git-init-db" in a newly created empty directory do the same? There was a bug (a long time ago) that created garbage instead of the template files, I think.

Also, is there something inside of the garbage subdirectory?

Quoted 2 lines

Btw, after doing a pull from git repository git cone now produces the following:

Ignore that one, looks like a silly error. Unrelated.

Linus

#19 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Dmitry Torokhov

Couple more points - just using rsync to get the data (without using git) does not not produce that wierd directory, only got clone does.

Does a plain "git-init-db" in a newly created empty directory do the same? There was a bug (a long time ago) that created garbage instead of the template files, I think.

Yes, plain git-init-db produces the garbage.

[dtor@anvil tst]$ git-init-db
defaulting to local storage area
[dtor@anvil tst]$ ls -l .git/
total 32

drwxrwxr-x    2 dtor dtor 4096 Sep 19 19:08 branches
-rw-rw-r--    1 dtor dtor   58 Sep 19 19:08 description
lrwxrwxrwx    1 dtor dtor   17 Sep 19 19:08 HEAD -> refs/heads/master
drwxrwxr-x    2 dtor dtor 4096 Sep 19 19:08 hooks
drwxrwxr-x    2 dtor dtor 4096 Sep 19 19:08 info
drwxrwxr-x  260 dtor dtor 4096 Sep 19 19:08 objects
drwxrwxr-x    4 dtor dtor 4096 Sep 19 19:08 refs
drwxrwxr-x    2 dtor dtor 4096 Sep 19 19:08 remotes
drwxrwxr-x    2 dtor dtor 4096 Sep 19 19:08 V?Cl???E ???#V?C??տl??E#V?C??;H

[dtor@anvil tst]$ git --version
git version 0.99.7

(Actually this is last night's pull).

Signature · 1 line
Dmitry
#20 lore raw
Quoted 2 lines · Dmitry Torokhov

Yes, plain git-init-db produces the garbage.

Hmm. It doesn't do it for me, but I suspect it will be obvious where it happens if you send us the output from "strace git-init-db"

Thanks,

Linus

#21 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Dmitry Torokhov

Yes, plain git-init-db produces the garbage.

Hmm. It doesn't do it for me, but I suspect it will be obvious where it happens if you send us the output from "strace git-init-db"

Peter's fix for copy_templates() fixes the problem for me.

Signature · 1 line
Dmitry
#22 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Dmitry Torokhov

Couple more points - just using rsync to get the data (without using git) does not not produce that wierd directory, only got clone does.

Does a plain "git-init-db" in a newly created empty directory do the same? There was a bug (a long time ago) that created garbage instead of the template files, I think.

Will test once get home...

Quoted 2 lines

Also, is there something inside of the garbage subdirectory?

No, they are always empty.

Signature · 1 line
Dmitry