git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Petr Baudis <pasky@suse.cz>
Date
Sep 20, 2005, 00:07 UTC
Message-ID
<20050920000731.GJ18320@pasky.or.cz>
In-Reply-To
<432F50BC.5000304@zytor.com>

Dear diary, on Tue, Sep 20, 2005 at 01:58:52AM CEST, I got a letter where "H. Peter Anvin" <hpa@zytor.com> told me that...

Show 19 quoted lines
> Petr Baudis wrote:
> >Dear diary, on Tue, Sep 20, 2005 at 01:16:14AM CEST, I got a letter
> >
> >Another idea - try this patch:
> >
> >diff --git a/init-db.c b/init-db.c
> >--- a/init-db.c
> >+++ b/init-db.c
> >@@ -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.

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.

Signed-off-by: Petr Baudis <pasky@suse.cz>

--- commit dbe1fe2f0d6de58bc0c9f98e6cf9573874612890 tree 30398d409fa27e95e3e592c803f6cd5a93652234 parent 79d2a11ec497fe940ca9a1fd8e0b9f295d39c290 author Petr Baudis <pasky@suse.cz> 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(-)
diff --git a/init-db.c b/init-db.c
--- a/init-db.c
+++ b/init-db.c
@@ -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);
-- 
				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.
Previous: H. Peter AnvinNext: H. Peter Anvin
Message 16 of 22 in “Garbage in .git directories???”
  1. Dmitry TorokhovSep 18, 2005
  2. Linus TorvaldsSep 18, 2005
  3. Dmitry TorokhovSep 18, 2005
  4. Dmitry TorokhovSep 19, 2005
  5. Junio C HamanoSep 19, 2005
  6. Linus TorvaldsSep 19, 2005
  7. Dmitry TorokhovSep 19, 2005
  8. Dmitry TorokhovSep 20, 2005
  9. Linus TorvaldsSep 20, 2005
  10. Dmitry TorokhovSep 20, 2005
  11. H. Peter AnvinSep 19, 2005
  12. Petr BaudisSep 19, 2005
  13. H. Peter AnvinSep 19, 2005
  14. Petr BaudisSep 19, 2005
  15. H. Peter AnvinSep 19, 2005
  16. Fix git-init-db creating crap directoriesPetr Baudis, Sep 20, 2005
  17. H. Peter AnvinSep 20, 2005
  18. Fix git-init-db creating crap directories (zeroth try)Petr Baudis, Sep 20, 2005
  19. H. Peter AnvinSep 20, 2005
  20. Petr BaudisSep 20, 2005
  21. Junio C HamanoSep 20, 2005
  22. H. Peter AnvinSep 20, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.