commit - ff129794b3e633a240763b063e8966f92f74d299
commit + 38d18775b821d504089ef6268fc301f527ccb169
blob - 0efd11eb1ea05278d857c70ca545f17de8f87588
blob + f2dbcb38ea508b565dbea5ebfbccbf5530868b1c
--- cvg/cvg.c
+++ cvg/cvg.c
goto done;
if (!list_refs_only) {
- error = got_repo_init(repo_path, NULL);
+ error = got_repo_init(repo_path, NULL, GOT_HASH_SHA1);
if (error)
goto done;
error = got_repo_pack_fds_open(&pack_fds);
blob - 82cc6a0781f740c40e728b1018f50ffc72607f9b
blob + 8d7484c497a231b5351f541295c4fa4d6609a5e0
--- got/got.1
+++ got/got.1
.Nm
are as follows:
.Bl -tag -width checkout
-.It Cm init Oo Fl b Ar branch Oc Ar repository-path
+.It Cm init Oo Fl A Ar hashing-algorithm Oc Oo Fl b Ar branch Oc Ar repository-path
Create a new empty repository at the specified
.Ar repository-path .
.Pp
.Cm got init
are as follows:
.Bl -tag -width Ds
+.It Fl A Ar hashing-algorithm
+Configure the repository's
+.Ar hashing-algorithm
+used for the computation of Git object IDs.
+Possible values are
+.Cm sha1
+.Pq the default
+or
+.Cm sha256 .
.It Fl b Ar branch
Make the repository's HEAD reference point to the specified
.Ar branch
blob - 3f403ec8e8aec0b1e344d07f677b0cd872cdaa28
blob + eedba272792e095dfe5a62504a47e88c579c69c8
--- got/got.c
+++ got/got.c
__dead static void
usage_init(void)
{
- fprintf(stderr, "usage: %s init [-b branch] repository-path\n",
+ fprintf(stderr, "usage: %s init [-A hashing-algorithm] [-b branch]"
+ " repository-path\n",
getprogname());
exit(1);
}
const struct got_error *error = NULL;
const char *head_name = NULL;
char *repo_path = NULL;
+ enum got_hash_algorithm algo = GOT_HASH_SHA1;
int ch;
- while ((ch = getopt(argc, argv, "b:")) != -1) {
+ while ((ch = getopt(argc, argv, "A:b:")) != -1) {
switch (ch) {
+ case 'A':
+ if (!strcmp(optarg, "sha1"))
+ algo = GOT_HASH_SHA1;
+ else if (!strcmp(optarg, "sha256"))
+ algo = GOT_HASH_SHA256;
+ else
+ return got_error_path(optarg,
+ GOT_ERR_OBJECT_FORMAT);
+ break;
case 'b':
head_name = optarg;
break;
if (error)
goto done;
- error = got_repo_init(repo_path, head_name);
+ error = got_repo_init(repo_path, head_name, algo);
done:
free(repo_path);
return error;
err(1, "pledge");
#endif
if (!list_refs_only) {
- error = got_repo_init(repo_path, NULL);
+ error = got_repo_init(repo_path, NULL, GOT_HASH_SHA1);
if (error)
goto done;
error = got_repo_pack_fds_open(&pack_fds);
blob - 00bb07ed7939d88c75f1fb6e94a7b77a86d50730
blob + d9461631d623c70a1fa3f0a27dc61e1fbc5f011a
--- gotadmin/gotadmin.1
+++ gotadmin/gotadmin.1
.Nm
are as follows:
.Bl -tag -width checkout
-.It Cm init Oo Fl b Ar branch Oc Ar repository-path
+.It Cm init Oo Fl A Ar hashing-algorithm Oc Oo Fl b Ar branch Oc Ar repository-path
Create a new empty repository at the specified
.Ar repository-path .
.Pp
.Cm gotadmin init
are as follows:
.Bl -tag -width Ds
+.It Fl A Ar hashing-algorithm
+Configure the repository's
+.Ar hashing-algorithm
+used for the computation of Git object IDs.
+Possible values are
+.Cm sha1
+.Pq the default
+or
+.Cm sha256 .
.It Fl b Ar branch
Make the repository's HEAD reference point to the specified
.Ar branch
blob - d1a3eb16e15433fc6661b79fd57450c7752f6b39
blob + 6678a9dd097384ee9c7b2545f4a1e9211a83054d
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
__dead static void
usage_init(void)
{
- fprintf(stderr, "usage: %s init [-b branch] repository-path\n",
+ fprintf(stderr, "usage: %s init [-A hashing-algorithm] [-b branch]"
+ " repository-path\n",
getprogname());
exit(1);
}
const struct got_error *error = NULL;
const char *head_name = NULL;
char *repo_path = NULL;
+ enum got_hash_algorithm algo = GOT_HASH_SHA1;
int ch;
#ifndef PROFILE
err(1, "pledge");
#endif
- while ((ch = getopt(argc, argv, "b:")) != -1) {
+ while ((ch = getopt(argc, argv, "A:b:")) != -1) {
switch (ch) {
+ case 'A':
+ if (!strcmp(optarg, "sha1"))
+ algo = GOT_HASH_SHA1;
+ else if (!strcmp(optarg, "sha256"))
+ algo = GOT_HASH_SHA256;
+ else
+ return got_error_path(optarg,
+ GOT_ERR_OBJECT_FORMAT);
+ break;
case 'b':
head_name = optarg;
break;
if (error)
goto done;
- error = got_repo_init(repo_path, head_name);
+ error = got_repo_init(repo_path, head_name, algo);
done:
free(repo_path);
return error;
blob - c53bf9434590b858c1ce59018954e81ff934dfc1
blob + e4dd636f145daee8d00edb26040118dabe291813
--- include/got_repository.h
+++ include/got_repository.h
* Create a new repository with optional specified
* HEAD ref in an empty directory at a specified path.
*/
-const struct got_error *got_repo_init(const char *, const char *);
+const struct got_error *got_repo_init(const char *, const char *,
+ enum got_hash_algorithm);
/* Attempt to find a unique object ID for a given ID string prefix. */
const struct got_error *got_repo_match_object_id_prefix(struct got_object_id **,
blob - d39172980ea798fa07c161a3cecc055dfc76136c
blob + f6c9b881e64ee0270d643a9dc809378060318b2b
--- lib/repository.c
+++ lib/repository.c
}
const struct got_error *
-got_repo_init(const char *repo_path, const char *head_name)
+got_repo_init(const char *repo_path, const char *head_name,
+ enum got_hash_algorithm algo)
{
const struct got_error *err = NULL;
const char *dirnames[] = {
const char *description_str = "Unnamed repository; "
"edit this file 'description' to name the repository.";
const char *headref = "ref: refs/heads/";
- const char *gitconfig_str = "[core]\n"
+ const char *gitconfig_sha1 = "[core]\n"
"\trepositoryformatversion = 0\n"
"\tfilemode = true\n"
"\tbare = true\n";
+ const char *gitconfig_sha256 = "[core]\n"
+ "\trepositoryformatversion = 1\n"
+ "\tfilemode = true\n"
+ "\tbare = true\n"
+ "[extensions]\n"
+ "\tobjectformat = sha256\n";
+ const char *gitconfig = gitconfig_sha1;
char *headref_str, *path;
size_t i;
+
+ if (algo == GOT_HASH_SHA256)
+ gitconfig = gitconfig_sha256;
if (!got_path_dir_is_empty(repo_path))
return got_error(GOT_ERR_DIR_NOT_EMPTY);
if (asprintf(&path, "%s/%s", repo_path, "config") == -1)
return got_error_from_errno("asprintf");
- err = got_path_create_file(path, gitconfig_str);
+ err = got_path_create_file(path, gitconfig);
free(path);
if (err)
return err;