commit - 4c8cdf4312442023bfc61e0a4836f611370074aa
commit + 0f6b90a718be86fc6bc1dc4ed98dbf5ecc711c02
blob - 3a641cf18f1e48d808261abc46eccd40b4ebb038
blob + 14c7a67587111b249ac93afcdbfbd6952c8bb01a
--- 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 - 4ca1f1f4258c67ff27c56e47a3918d706f3589e6
blob + 3d79f079d176f8e5a73b8c4a5760a9ec689b1213
--- 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 - 03d652acaff8104cba5bfbedfa189fe21e58a796
blob + 7721c6c239557c9accd80b3bab5d98a3f57b1ddb
--- 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 - f64cc3c12d7556ae8580f2d3dd1a403b251b9c39
blob + b68f4c0125c3b5dc74af9fd83c10f355f42b07ce
--- 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;