Download raw body.
make gotadmin load always read data from stdin
This patch makes 'gotadmin load' read bundle streams from stdin only. This behaviour has better symmetry with gotadmin dump, and it allows us to drop the -b ("branch"?) option and move the reference list to the main command line. While here, verify that the names we get on the command line are valid reference names. In future I hope would will be able to automatically detect whether stdin contains a bundle stream of a fast-import stream (e.g by caching the first lines of standard input and checking for a bundle header). This way, the usage of gotadmin load would remain the same for both case and we would aways load from stdin. ok? While working on this it occurred to me that the user is currently required to list every ref in an absolute fashion, i.e. beginning with "refs/" -- maybe we could allow shorter forms as long as they are not ambiguous, much like other commands do? Then we could call gotadmin load with arguments like this: gotadmin load main origin/main < mybundle and these would be expanded to gotadmin load refs/heads/main refs/heads/origin/main < mybundle ----------------------------------------------- make gotadmin load always read data from standard input The -l option now takes an argument which specifies the bundle file to list. diff ca4f2e186c3c2fd07067c568d5558ac9843dfbdf 91c5429cda4970315a09c5b3fb4d0b729d136f8b commit - ca4f2e186c3c2fd07067c568d5558ac9843dfbdf commit + 91c5429cda4970315a09c5b3fb4d0b729d136f8b blob - 13fcc34f3da5081d4ae416da9ea13f440d64b1e9 blob + dd78162413eb39225652910fde36f8fd08043467 --- gotadmin/gotadmin.1 +++ gotadmin/gotadmin.1 @@ -387,32 +387,38 @@ be excluded. .El .It Xo .Cm load -.Op Fl lnq -.Op Fl b Ar reference +.Op Fl nq +.Op Fl l Ar bundle-path .Op Fl r Ar repository-path -.Op Ar file +.Op Ar reference ... .Xc -Read a Git bundle stream from standard input or -.Ar file . +Read a Git bundle stream from standard input and load its data into +a repository. .Pp +If one or more +.Ar reference +arguments are provided then only load the specified references +from the bundle. +Otherwise, all references will be loaded. +.Pp The options for .Cm gotadmin load are as follows: .Bl -tag -width Ds -.It Fl b Ar reference -Load only the specified +.It Fl l Ar bundle-path +List references available for loading from the bundle at the specified +.Ar bundle-path +and exit immediately. +If the +.Fl l +option is specified then no .Ar reference -from the bundle. -This option may be specified multiple times to build a list of -reference to load. -If not provided, all the reference will be loaded. -.It Fl l -List references available for loading from the bundle and exit -immediately. -Cannot be used together with -.Fl b -and -.Fl n . +arguments are allowed. +The +.Fl l +option is incompatible with the +.Fl n +option. .It Fl n Attempt to load the bundle but don't install new packfile or update any reference. blob - cdaeef909c106875bbbf659a52c64f0eac22d6d1 blob + 3d82b9f6c3907dadf515414ac9882e54f076f4ff --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -1551,8 +1551,8 @@ usage_load(void) __dead static void usage_load(void) { - fprintf(stderr, "usage: %s load [-lnq] [-b reference] " - "[-r repository-path] [file]\n", + fprintf(stderr, "usage: %s load [-nq] [-l bundle-file] " + "[-r repository-path] [reference ...]\n", getprogname()); exit(1); } @@ -1684,7 +1684,7 @@ cmd_load(int argc, char *argv[]) int list_refs_only = 0; int noop = 0; int verbosity = 0; - int ch; + int ch, i; TAILQ_INIT(&include_args); TAILQ_INIT(&available_refs); @@ -1695,16 +1695,13 @@ cmd_load(int argc, char *argv[]) err(1, "pledge"); #endif - while ((ch = getopt(argc, argv, "b:lnqr:")) != -1) { + while ((ch = getopt(argc, argv, "l:nqr:")) != -1) { switch (ch) { - case 'b': - error = got_pathlist_append(&include_args, - optarg, NULL); - if (error) - return error; - break; case 'l': list_refs_only = 1; + in = fopen(optarg, "re"); + if (in == NULL) + return got_error_from_errno2("open", optarg); break; case 'n': noop = 1; @@ -1727,18 +1724,19 @@ cmd_load(int argc, char *argv[]) argc -= optind; argv += optind; - if (list_refs_only && !TAILQ_EMPTY(&include_args)) - errx(1, "-b and -l are mutually exclusive"); - + if (list_refs_only && argc > 1) + errx(1, "-l and references on the command line are exclusive"); if (list_refs_only && noop) errx(1, "-n and -l are mutually exclusive"); - if (argc > 1) - usage_load(); - if (argc == 1) { - in = fopen(argv[0], "re"); - if (in == NULL) - return got_error_from_errno2("open", argv[0]); + for (i = 0; i < argc; i++) { + char *refname = argv[i]; + got_path_strip_trailing_slashes(refname); + if (!got_ref_name_is_valid(refname)) + errx(1, "invalid reference name %s", refname); + error = got_pathlist_append(&include_args, refname, NULL); + if (error) + goto done; } if (repo_path == NULL) { blob - 7b7bbe844754e7af7ee9a6c3e88f168a902dbafe blob + 70bf269325f1dc66d6be29ef5f6b010108cfb01a --- regress/cmdline/load.sh +++ regress/cmdline/load.sh @@ -24,7 +24,7 @@ test_load_bundle() { # then load it in an empty repository (cd "$testroot/" && gotadmin init -b master repo2) >/dev/null - (cd "$testroot/repo2" && gotadmin load "$testroot/bundle") \ + (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") \ >/dev/null if [ $? -ne 0 ]; then echo "failed to load the bundle" >&2 @@ -48,7 +48,7 @@ test_load_bundle() { (cd "$testroot/repo" && git bundle create -q \ "$testroot/bundle" "$base..master") - (cd "$testroot/repo2" && gotadmin load "$testroot/bundle") >/dev/null + (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") >/dev/null if [ $? -ne 0 ]; then echo "failed to load incremental bundle" >&2 test_done "$testroot" 1 @@ -102,7 +102,7 @@ EOF return 1 fi - (cd "$testroot/repo2" && gotadmin load -q -b refs/heads/newbranch \ + (cd "$testroot/repo2" && gotadmin load -q refs/heads/newbranch \ <$testroot/bundle) if [ $? -ne 0 ]; then echo "gotadmin load failed unexpectedly" >&2
make gotadmin load always read data from stdin