diff mbox series

[v3,3/6] create .git/refs in files-backend.c

Message ID 5b7060cb2fc25fc1c71b7c70864ebf758b59aa90.1580848060.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Reftable support git-core | expand

Commit Message

Linus Arver via GitGitGadget Feb. 4, 2020, 8:27 p.m. UTC
From: Han-Wen Nienhuys <hanwen@google.com>

This prepares for supporting the reftable format, which will want
create its own file system layout in .git

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 builtin/init-db.c    | 2 --
 refs/files-backend.c | 5 +++++
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Junio C Hamano Feb. 4, 2020, 9:29 p.m. UTC | #1
"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Han-Wen Nienhuys <hanwen@google.com>
>
> This prepares for supporting the reftable format, which will want
> create its own file system layout in .git
>
> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> ---
>  builtin/init-db.c    | 2 --
>  refs/files-backend.c | 5 +++++
>  2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 944ec77fe1..45bdea0589 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -226,8 +226,6 @@ static int create_default_files(const char *template_path,
>  	 * We need to create a "refs" dir in any case so that older
>  	 * versions of git can tell that this is a repository.
>  	 */
> -	safe_create_dir(git_path("refs"), 1);
> -	adjust_shared_perm(git_path("refs"));
>  
>  	if (refs_init_db(&err))
>  		die("failed to set up refs db: %s", err.buf);
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 0ea66a28b6..0c53b246e8 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -3158,6 +3158,11 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
>  		files_downcast(ref_store, REF_STORE_WRITE, "init_db");
>  	struct strbuf sb = STRBUF_INIT;
>  
> +	files_ref_path(refs, &sb, "refs");

Have you run "git diff --check" before committing?

> +	safe_create_dir(sb.buf, 1);
> +        /* adjust permissions even if directory already exists. */

whitespace error here, but this comment is really appreciated.  It
wasn't immediately clear why we do this again in the original.

> +	adjust_shared_perm(sb.buf);
> +
>  	/*
>  	 * Create .git/refs/{heads,tags}
>  	 */
Han-Wen Nienhuys Feb. 5, 2020, 11:34 a.m. UTC | #2
On Tue, Feb 4, 2020 at 10:29 PM Junio C Hamano <gitster@pobox.com> wrote:
> > +     files_ref_path(refs, &sb, "refs");
>
> Have you run "git diff --check" before committing?

let me install the clang-format pre-commit hook.
SZEDER Gábor Feb. 5, 2020, 11:42 a.m. UTC | #3
On Tue, Feb 04, 2020 at 08:27:37PM +0000, Han-Wen Nienhuys via GitGitGadget wrote:
> From: Han-Wen Nienhuys <hanwen@google.com>
> 
> This prepares for supporting the reftable format, which will want
> create its own file system layout in .git

This breaks 'git init', and, consequently, the whole test suite:

  $ ./git init /tmp/foo
  /tmp/foo/.git/refs/tmp/foo/.git/refs/heads: No such file or directory


>  builtin/init-db.c    | 2 --
>  refs/files-backend.c | 5 +++++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 944ec77fe1..45bdea0589 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -226,8 +226,6 @@ static int create_default_files(const char *template_path,
>  	 * We need to create a "refs" dir in any case so that older
>  	 * versions of git can tell that this is a repository.
>  	 */
> -	safe_create_dir(git_path("refs"), 1);
> -	adjust_shared_perm(git_path("refs"));
>  
>  	if (refs_init_db(&err))
>  		die("failed to set up refs db: %s", err.buf);
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 0ea66a28b6..0c53b246e8 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -3158,6 +3158,11 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
>  		files_downcast(ref_store, REF_STORE_WRITE, "init_db");
>  	struct strbuf sb = STRBUF_INIT;
>  
> +	files_ref_path(refs, &sb, "refs");
> +	safe_create_dir(sb.buf, 1);
> +        /* adjust permissions even if directory already exists. */
> +	adjust_shared_perm(sb.buf);
> +
>  	/*
>  	 * Create .git/refs/{heads,tags}
>  	 */
> -- 
> gitgitgadget
>
Jeff King Feb. 5, 2020, 12:24 p.m. UTC | #4
On Wed, Feb 05, 2020 at 12:42:10PM +0100, SZEDER Gábor wrote:

> On Tue, Feb 04, 2020 at 08:27:37PM +0000, Han-Wen Nienhuys via GitGitGadget wrote:
> > From: Han-Wen Nienhuys <hanwen@google.com>
> > 
> > This prepares for supporting the reftable format, which will want
> > create its own file system layout in .git
> 
> This breaks 'git init', and, consequently, the whole test suite:
> 
>   $ ./git init /tmp/foo
>   /tmp/foo/.git/refs/tmp/foo/.git/refs/heads: No such file or directory

Yeah, this is one of the fixes in the patch I sent earlier in the
thread. The issue is here:

> > @@ -3158,6 +3158,11 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
> >  		files_downcast(ref_store, REF_STORE_WRITE, "init_db");
> >  	struct strbuf sb = STRBUF_INIT;
> >  
> > +	files_ref_path(refs, &sb, "refs");
> > +	safe_create_dir(sb.buf, 1);
> > +        /* adjust permissions even if directory already exists. */
> > +	adjust_shared_perm(sb.buf);
> > +
> >  	/*
> >  	 * Create .git/refs/{heads,tags}
> >  	 */

Right after this context, we call files_ref_path() with "sb" again.
There needs to be a strbuf_reset() beforehand.

-Peff
diff mbox series

Patch

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 944ec77fe1..45bdea0589 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -226,8 +226,6 @@  static int create_default_files(const char *template_path,
 	 * We need to create a "refs" dir in any case so that older
 	 * versions of git can tell that this is a repository.
 	 */
-	safe_create_dir(git_path("refs"), 1);
-	adjust_shared_perm(git_path("refs"));
 
 	if (refs_init_db(&err))
 		die("failed to set up refs db: %s", err.buf);
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0ea66a28b6..0c53b246e8 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3158,6 +3158,11 @@  static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
 		files_downcast(ref_store, REF_STORE_WRITE, "init_db");
 	struct strbuf sb = STRBUF_INIT;
 
+	files_ref_path(refs, &sb, "refs");
+	safe_create_dir(sb.buf, 1);
+        /* adjust permissions even if directory already exists. */
+	adjust_shared_perm(sb.buf);
+
 	/*
 	 * Create .git/refs/{heads,tags}
 	 */