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

Re: [PATCH v4 15/21] init: allow alternate ref strorage to be set for new repos

From
David Turner <dturner@twopensource.com>
Date
Feb 17, 2016, 20:47 UTC
Message-ID
<1455742036.7528.18.camel@twopensource.com>
In-Reply-To
<56BDF9B1.5050302@alum.mit.edu>
On Fri, 2016-02-12 at 16:26 +0100, Michael Haggerty wrote:
Show 57 quoted lines
> On 02/05/2016 08:44 PM, David Turner wrote:
> > git init learns a new argument --ref-storage.  Presently, only
> > "files" is supported, but later we will add other storage backends.
> > 
> > When this argument is used, the repository's extensions.refStorage
> > configuration value is set (as well as
> > core.repositoryformatversion),
> > and the ref storage backend's initdb function is used to set up the
> > ref database.
> > 
> > Signed-off-by: David Turner <dturner@twopensource.com>
> > Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> > ---
> >  Documentation/git-init-db.txt          |  2 +-
> >  Documentation/git-init.txt             |  7 +++++-
> >  builtin/init-db.c                      | 44
> > +++++++++++++++++++++++++++-------
> >  cache.h                                |  2 ++
> >  contrib/completion/git-completion.bash |  3 ++-
> >  path.c                                 | 29 ++++++++++++++++++++--
> >  refs.c                                 |  8 +++++++
> >  refs.h                                 |  8 +++++++
> >  setup.c                                | 12 ++++++++++
> >  t/t0001-init.sh                        | 25 +++++++++++++++++++
> >  10 files changed, 127 insertions(+), 13 deletions(-)
> > 
> > [...]
> > diff --git a/Documentation/git-init.txt b/Documentation/git
> > -init.txt
> > index 8174d27..d2b150f 100644
> > --- a/Documentation/git-init.txt
> > +++ b/Documentation/git-init.txt
> > @@ -12,7 +12,7 @@ SYNOPSIS
> >  'git init' [-q | --quiet] [--bare] [-
> > -template=<template_directory>]
> >  	  [--separate-git-dir <git dir>]
> >  	  [--shared[=<permissions>]] [directory]
> > -
> > +	  [--ref-storage=<name>]
> >  
> >  DESCRIPTION
> >  -----------
> > @@ -113,6 +113,11 @@ does not exist, it will be created.
> >  
> >  --
> >  
> > +--ref-storage=<name>::
> > +Type of refs storage backend. Default is to use the original
> > "files"
> > +storage, which stores ref data in files in .git/refs and
> > +.git/packed-refs.
> > +
> 
> Technically, that should be $GIT_DIR/refs and $GIT_DIR/packed-refs.
> But
> it might be that we are not so picky about the distinction in the
> user docs.
We're not (according to grep), but we probably should be.
Show 35 quoted lines
> >  TEMPLATE DIRECTORY
> >  ------------------
> >  
> > diff --git a/builtin/init-db.c b/builtin/init-db.c
> > index 801e977..d331ce8 100644
> > --- a/builtin/init-db.c
> > +++ b/builtin/init-db.c
> > @@ -24,6 +24,7 @@ static int init_is_bare_repository = 0;
> >  static int init_shared_repository = -1;
> >  static const char *init_db_template_dir;
> >  static const char *git_link;
> > +static char *requested_ref_storage_backend;
> >  
> >  static void copy_templates_1(struct strbuf *path, struct strbuf
> > *template,
> >  			     DIR *dir)
> > @@ -179,6 +180,7 @@ static int create_default_files(const char
> > *template_path)
> >  	int reinit;
> >  	int filemode;
> >  	struct strbuf err = STRBUF_INIT;
> > +	int repo_version = 0;
> >  
> >  	/* Just look for `init.templatedir` */
> >  	git_config(git_init_db_config, NULL);
> > @@ -205,6 +207,32 @@ static int create_default_files(const char
> > *template_path)
> >  	}
> >  
> >  	/*
> > +	 * Create the default symlink from ".git/HEAD" to the
> > "master"
> 
> I know that you are just moving this comment, but s/symlink/symref/
> would make it more up-to-date.
OK.
Show 83 quoted lines
> > +	 * branch, if it does not exist yet.
> > +	 */
> > [...]
> > diff --git a/setup.c b/setup.c
> > index 0deb022..1a62277 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -1,5 +1,6 @@
> >  #include "cache.h"
> >  #include "dir.h"
> > +#include "refs.h"
> >  #include "string-list.h"
> >  
> >  static int inside_git_dir = -1;
> > @@ -263,6 +264,15 @@ int get_common_dir_noenv(struct strbuf *sb,
> > const char *gitdir)
> >  	return ret;
> >  }
> >  
> > +int ref_storage_backend_config(const char *var, const char *value,
> > void *ptr)
> > +{
> > +	char **cdata = ptr;
> > +
> > +	if (!strcmp(var, "extensions.refstorage"))
> > +		*cdata = xstrdup(value);
> > +	return 0;
> > +}
> > +
> >  /*
> >   * Test if it looks like we're at a git directory.
> >   * We want to see:
> > @@ -390,6 +400,8 @@ static int check_repo_format(const char *var,
> > const char *value, void *cb)
> >  			;
> >  		else if (!strcmp(ext, "preciousobjects"))
> >  			repository_format_precious_objects =
> > git_config_bool(var, value);
> > +		else if (!strcmp(ext, "refstorage"))
> > +			ref_storage_backend = xstrdup(value);
> >  		else
> >  			string_list_append(&unknown_extensions,
> > ext);
> >  	}
> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> > index 295aa59..31c8279 100755
> > --- a/t/t0001-init.sh
> > +++ b/t/t0001-init.sh
> > @@ -174,6 +174,31 @@ test_expect_success 'reinit' '
> >  	test_i18ncmp again/empty again/err2
> >  '
> >  
> > +test_expect_success 'init with bogus storage backend fails' '
> > +
> > +	(
> > +		mkdir again2 &&
> > +		cd again2 &&
> > +		test_must_fail git init --ref-storage=test >out2
> > 2>err2 &&
> > +		test_i18ngrep "Unknown ref storage backend test"
> > err2
> > +	)
> > +'
> > +
> > +test_expect_failure 'reinit with changed storage backend fails' '
> > +
> > +	(
> > +		mkdir again3 &&
> > +		cd again3 &&
> > +		git init >out1 2>err1 &&
> > +		git init --ref-storage=test >out2 2>err2
> > +	) &&
> > +	test_i18ngrep "Initialized empty" again3/out1 &&
> > +	test_i18ngrep "Reinitialized existing" again3/out2 &&
> > +	>again3/empty &&
> > +	test_i18ncmp again3/empty again3/err1 &&
> > +	test_i18ncmp again3/empty again3/err2
> > +'
> > +
> 
> Is it worth testing re-initializing with the same --ref-storage?
> Perhaps
> not.

Would be nice, but since we cannot guarantee that any alternate backend exists, we have no way to test this. We'd have to add an entire "test" ref backend just for tests, which seems a bit overboard.

Show 7 quoted lines
> >  test_expect_success 'init with --template' '
> >  	mkdir template-source &&
> >  	echo content >template-source/file &&
> > 
> 
> Michael
> 
Previous: Michael HaggertyNext: Michael Haggerty
Message 35 of 53 in “refs backend”
  1. 00/20 refs backendDavid Turner, Feb 5, 2016
  2. 01/21 refs: add a backend method structure with transaction functionsDavid Turner, Feb 5, 2016
  3. 02/21 refs: add methods for misc ref operationsDavid Turner, Feb 5, 2016
  4. Michael HaggertyFeb 11, 2016
  5. David TurnerFeb 12, 2016
  6. 03/21 refs: add methods for the ref iteratorsDavid Turner, Feb 5, 2016
  7. Michael HaggertyFeb 11, 2016
  8. David TurnerFeb 12, 2016
  9. 04/21 refs: add do_for_each_per_worktree_refDavid Turner, Feb 5, 2016
  10. 05/21 refs: add methods for reflogDavid Turner, Feb 5, 2016
  11. 06/21 refs: add method for initial ref transaction commitDavid Turner, Feb 5, 2016
  12. 07/21 refs: add method for delete_refsDavid Turner, Feb 5, 2016
  13. 08/21 refs: add methods to init refs dbDavid Turner, Feb 5, 2016
  14. Michael HaggertyFeb 11, 2016
  15. David TurnerFeb 11, 2016
  16. 09/21 refs: add method to rename refsDavid Turner, Feb 5, 2016
  17. Michael HaggertyFeb 11, 2016
  18. David TurnerFeb 11, 2016
  19. 10/21 refs: make lock genericDavid Turner, Feb 5, 2016
  20. 11/21 refs: move duplicate check to common codeDavid Turner, Feb 5, 2016
  21. 12/21 refs: allow log-only updatesDavid Turner, Feb 5, 2016
  22. Michael HaggertyFeb 11, 2016
  23. David TurnerFeb 11, 2016
  24. 13/21 refs: resolve symbolic refs firstDavid Turner, Feb 5, 2016
  25. Michael HaggertyFeb 12, 2016
  26. David TurnerFeb 18, 2016
  27. Michael HaggertyFeb 18, 2016
  28. 14/21 refs: always handle non-normal refs in files backendDavid Turner, Feb 5, 2016
  29. Michael HaggertyFeb 12, 2016
  30. David TurnerFeb 18, 2016
  31. Michael HaggertyFeb 18, 2016
  32. David TurnerFeb 18, 2016
  33. 15/21 init: allow alternate ref strorage to be set for new reposDavid Turner, Feb 5, 2016
  34. Michael HaggertyFeb 12, 2016
  35. David TurnerFeb 17, 2016
  36. Michael HaggertyFeb 18, 2016
  37. 16/21 refs: check submodules ref storage configDavid Turner, Feb 5, 2016
  38. 17/21 clone: allow ref storage backend to be set for cloneDavid Turner, Feb 5, 2016
  39. 18/21 svn: learn ref-storage argumentDavid Turner, Feb 5, 2016
  40. 19/21 refs: add register_ref_storage_backends()David Turner, Feb 5, 2016
  41. Michael HaggertyFeb 12, 2016
  42. David TurnerFeb 17, 2016
  43. 20/21 refs: add LMDB refs storage backendDavid Turner, Feb 5, 2016
  44. Michael HaggertyFeb 11, 2016
  45. David TurnerFeb 11, 2016
  46. Michael HaggertyFeb 12, 2016
  47. David TurnerFeb 13, 2016
  48. Duy NguyenFeb 14, 2016
  49. Duy NguyenFeb 15, 2016
  50. David TurnerFeb 16, 2016
  51. David TurnerFeb 17, 2016
  52. 21/21 refs: tests for lmdb backendDavid Turner, Feb 5, 2016
  53. Junio C HamanoFeb 8, 2016

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.