"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
move got init to gotadmin init
To:
gameoftrees@openbsd.org
Date:
Sat, 2 Jul 2022 14:00:22 +0200

Download raw body.

Thread
  • Stefan Sperling:

    move got init to gotadmin init

In retrospect, the 'got init' command seems more suitable for gotadmin.
Consider maintenance of a server-side setup, where gotadmin would be used
to maintain repositories. The 'got' command should be client-side only.

ok?

I also plan to move 'got import' over but this requires a bit more work
which I haven't found time for yet.

diff f0032ce63b4f4f035e5f7894a406a96931f99f3f 7065fb19cd4fd8eb17af205eb70645c681fd4d54
commit - f0032ce63b4f4f035e5f7894a406a96931f99f3f
commit + 7065fb19cd4fd8eb17af205eb70645c681fd4d54
blob - d2db3f11b55b0dcd7008e9f4662210887aa2742b
blob + 5b396a54b690e80840795b713f4d4c676bc87bde
--- got/got.1
+++ got/got.1
@@ -62,17 +62,6 @@ The commands for
 .Nm
 are as follows:
 .Bl -tag -width checkout
-.It Cm init Ar repository-path
-Create a new empty repository at the specified
-.Ar repository-path .
-.Pp
-After
-.Cm got init ,
-the
-.Cm got import
-command must be used to populate the empty repository before
-.Cm got checkout
-can be used.
 .Tg im
 .It Cm import Oo Fl b Ar branch Oc Oo Fl m Ar message Oc Oo Fl r Ar repository-path Oc Oo Fl I Ar pattern Oc Ar directory
 .Dl Pq alias: Cm im
@@ -2772,7 +2761,7 @@ a new Git repository could be created and populated wi
 e.g. from a temporary CVS checkout located at
 .Pa /tmp/src :
 .Pp
-.Dl $ got init /var/git/src.git
+.Dl $ gotadmin init /var/git/src.git
 .Dl $ got import -r /var/git/src.git -I CVS -I obj /tmp/src
 .Pp
 Check out a work tree from the Git repository to /usr/src:
blob - 5f7f00007937a048564e685aac0a8c6b9e98adab
blob + bb6afb26a2c19fed9abfc5f32068fd5dcfec2190
--- got/got.c
+++ got/got.c
@@ -87,7 +87,6 @@ struct got_cmd {
 };
 
 __dead static void	usage(int, int);
-__dead static void	usage_init(void);
 __dead static void	usage_import(void);
 __dead static void	usage_clone(void);
 __dead static void	usage_fetch(void);
@@ -118,7 +117,6 @@ __dead static void	usage_unstage(void);
 __dead static void	usage_cat(void);
 __dead static void	usage_info(void);
 
-static const struct got_error*		cmd_init(int, char *[]);
 static const struct got_error*		cmd_import(int, char *[]);
 static const struct got_error*		cmd_clone(int, char *[]);
 static const struct got_error*		cmd_fetch(int, char *[]);
@@ -150,7 +148,6 @@ static const struct got_error*		cmd_cat(int, char *[])
 static const struct got_error*		cmd_info(int, char *[]);
 
 static const struct got_cmd got_commands[] = {
-	{ "init",	cmd_init,	usage_init,	"" },
 	{ "import",	cmd_import,	usage_import,	"im" },
 	{ "clone",	cmd_clone,	usage_clone,	"cl" },
 	{ "fetch",	cmd_fetch,	usage_fetch,	"fe" },
@@ -345,59 +342,6 @@ apply_unveil(const char *repo_path, int repo_read_only
 }
 
 __dead static void
-usage_init(void)
-{
-	fprintf(stderr, "usage: %s init repository-path\n", getprogname());
-	exit(1);
-}
-
-static const struct got_error *
-cmd_init(int argc, char *argv[])
-{
-	const struct got_error *error = NULL;
-	char *repo_path = NULL;
-	int ch;
-
-	while ((ch = getopt(argc, argv, "")) != -1) {
-		switch (ch) {
-		default:
-			usage_init();
-			/* NOTREACHED */
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
-		err(1, "pledge");
-#endif
-	if (argc != 1)
-		usage_init();
-
-	repo_path = strdup(argv[0]);
-	if (repo_path == NULL)
-		return got_error_from_errno("strdup");
-
-	got_path_strip_trailing_slashes(repo_path);
-
-	error = got_path_mkdir(repo_path);
-	if (error &&
-	    !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
-		goto done;
-
-	error = apply_unveil(repo_path, 0, NULL);
-	if (error)
-		goto done;
-
-	error = got_repo_init(repo_path);
-done:
-	free(repo_path);
-	return error;
-}
-
-__dead static void
 usage_import(void)
 {
 	fprintf(stderr, "usage: %s import [-b branch] [-m message] "
blob - 80fd9074549181f88fa96e0b7e0ee1063bec0780
blob + 6bf525c6b6eb1e12a47eb54d15ca3f317e29b05e
--- gotadmin/gotadmin.1
+++ gotadmin/gotadmin.1
@@ -53,6 +53,17 @@ The commands for
 .Nm
 are as follows:
 .Bl -tag -width checkout
+.It Cm init Ar repository-path
+Create a new empty repository at the specified
+.Ar repository-path .
+.Pp
+After
+.Cm gotadmin init ,
+the
+.Cm got import
+command must be used to populate the empty repository before
+.Cm got checkout
+can be used.
 .It Cm info Oo Fl r Ar repository-path Oc
 Display information about a repository.
 This includes some configuration settings from
blob - d2e712fec877f56e6a3e85c0e93d10cc4ce1a702
blob + f4d2b3013d6751cf1612acb25b8552e3910f05f5
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -79,12 +79,14 @@ struct gotadmin_cmd {
 };
 
 __dead static void	usage(int, int);
+__dead static void	usage_init(void);
 __dead static void	usage_info(void);
 __dead static void	usage_pack(void);
 __dead static void	usage_indexpack(void);
 __dead static void	usage_listpack(void);
 __dead static void	usage_cleanup(void);
 
+static const struct got_error*		cmd_init(int, char *[]);
 static const struct got_error*		cmd_info(int, char *[]);
 static const struct got_error*		cmd_pack(int, char *[]);
 static const struct got_error*		cmd_indexpack(int, char *[]);
@@ -92,6 +94,7 @@ static const struct got_error*		cmd_listpack(int, char
 static const struct got_error*		cmd_cleanup(int, char *[]);
 
 static const struct gotadmin_cmd gotadmin_commands[] = {
+	{ "init",	cmd_init,	usage_init,	"" },
 	{ "info",	cmd_info,	usage_info,	"" },
 	{ "pack",	cmd_pack,	usage_pack,	"" },
 	{ "indexpack",	cmd_indexpack,	usage_indexpack,"ix" },
@@ -265,7 +268,60 @@ done:
 	return err;
 }
 
+__dead static void
+usage_init(void)
+{
+	fprintf(stderr, "usage: %s init repository-path\n", getprogname());
+	exit(1);
+}
+
 static const struct got_error *
+cmd_init(int argc, char *argv[])
+{
+	const struct got_error *error = NULL;
+	char *repo_path = NULL;
+	int ch;
+
+	while ((ch = getopt(argc, argv, "")) != -1) {
+		switch (ch) {
+		default:
+			usage_init();
+			/* NOTREACHED */
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+#ifndef PROFILE
+	if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
+		err(1, "pledge");
+#endif
+	if (argc != 1)
+		usage_init();
+
+	repo_path = strdup(argv[0]);
+	if (repo_path == NULL)
+		return got_error_from_errno("strdup");
+
+	got_path_strip_trailing_slashes(repo_path);
+
+	error = got_path_mkdir(repo_path);
+	if (error &&
+	    !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
+		goto done;
+
+	error = apply_unveil(repo_path, 0);
+	if (error)
+		goto done;
+
+	error = got_repo_init(repo_path);
+done:
+	free(repo_path);
+	return error;
+}
+
+static const struct got_error *
 cmd_info(int argc, char *argv[])
 {
 	const struct got_error *error = NULL;
blob - 920610e37ab899c23ebcb98ee645c7044a456669
blob + 71d20c61b9666f8571b8996f1bb477f6e01a3c1f
--- regress/cmdline/import.sh
+++ regress/cmdline/import.sh
@@ -20,7 +20,7 @@ test_import_basic() {
 	local testname=import_basic
 	local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
 
-	got init $testroot/repo
+	gotadmin init $testroot/repo
 
 	mkdir $testroot/tree
 	make_test_tree $testroot/tree
@@ -176,7 +176,7 @@ test_import_ignores() {
 	local testname=import_ignores
 	local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
 
-	got init $testroot/repo
+	gotadmin init $testroot/repo
 
 	mkdir $testroot/tree
 	make_test_tree $testroot/tree
@@ -206,7 +206,7 @@ test_import_empty_dir() {
 	local testname=import_empty_dir
 	local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
 
-	got init $testroot/repo
+	gotadmin init $testroot/repo
 
 	mkdir $testroot/tree
 	mkdir -p $testroot/tree/empty $testroot/tree/notempty
@@ -249,7 +249,7 @@ test_import_symlink() {
 	local testname=import_symlink
 	local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
 
-	got init $testroot/repo
+	gotadmin init $testroot/repo
 
 	mkdir $testroot/tree
 	echo 'this is file alpha' > $testroot/tree/alpha
blob - f322b4b27c50f6f8a96b7c8322063b329f68c34c
blob + fc218eff521a465dc36ca25aad4973aa104fbb4c
--- regress/cmdline/log.sh
+++ regress/cmdline/log.sh
@@ -670,7 +670,7 @@ test_log_in_worktree_different_repo() {
 	git_commit $testroot/repo -m "adding the test tree"
 	local head_commit=`git_show_head $testroot/repo`
 
-	got init $testroot/other-repo
+	gotadmin init $testroot/other-repo
 	mkdir -p $testroot/tree
 	make_test_tree $testroot/tree
 	got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
blob - 6125dc59b54701f50aa1248b7a9260c6ee5e9dca
blob + 9b68f290f9a1292250e21ea6a0e37961d6e9179c
--- regress/cmdline/send.sh
+++ regress/cmdline/send.sh
@@ -1204,7 +1204,7 @@ test_send_to_empty_repo() {
 	local testurl=ssh://127.0.0.1/$testroot
 	local commit_id=`git_show_head $testroot/repo`
 
-	got init $testroot/repo2
+	gotadmin init $testroot/repo2
 
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -1240,7 +1240,7 @@ EOF
 		return 1
 	fi
 
-	# XXX Workaround: We cannot give the target for HEAD to 'got init'
+	# XXX Workaround: We cannot give the target for HEAD to 'gotadmin init'
 	got ref -r $testroot/repo2 -s refs/heads/master HEAD
 
 	got ref -l -r $testroot/repo > $testroot/stdout