commit 27b10c3cfd1526a6dd9f8101b12531a99b3411e4 from: Stefan Sperling via: Thomas Adam date: Mon Jul 04 22:45:58 2022 UTC move 'got init' command to 'gotadmin init' This functionality is better suited for gotadmin because it is technically a server-side repository operation when we consider the 'got' tool as the client-side tool. I have plans to move 'got import' into gotadmin as well. ok op@ commit - c0805ce576af63f905cfae094062eec19d255c85 commit + 27b10c3cfd1526a6dd9f8101b12531a99b3411e4 blob - cd6dc8e50f799c6392612e374795bd9522d1ddad blob + e2ca64cf2ca617ca42a53d36ba06816d803f28af --- 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 @@ -2813,7 +2802,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 - 58eec0e6e73bb768ac0b197ec46bc189ad837b47 blob + 527aac5ec1564ad8bda90d4d954008c453b86bbe --- got/got.c +++ got/got.c @@ -89,7 +89,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); @@ -120,7 +119,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 *[]); @@ -152,7 +150,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" }, @@ -344,59 +341,6 @@ apply_unveil(const char *repo_path, int repo_read_only return got_error_from_errno("unveil"); return NULL; -} - -__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 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 - b88d54df494f629ad336256ee0db5595bf370946 blob + 67c42d41819d891117256e71fc6e7b79f1223d64 --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -78,12 +78,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 *[]); @@ -91,6 +93,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" }, @@ -262,6 +265,59 @@ done: got_worktree_close(worktree); free(cwd); 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 * 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