Skip to content

Commit ddc35d8

Browse files
dschogitster
authored andcommitted
scalar: implement the version command
The .NET version of Scalar has a `version` command. This was necessary because it was versioned independently of Git. Since Scalar is now tightly coupled with Git, it does not make sense for them to show different versions. Therefore, it shows the same output as `git version`. For backwards-compatibility with the .NET version, `scalar version` prints to `stderr`, though (`git version` prints to `stdout` instead). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d85ada7 commit ddc35d8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

contrib/scalar/scalar.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "refs.h"
1111
#include "dir.h"
1212
#include "packfile.h"
13+
#include "help.h"
1314

1415
/*
1516
* Remove the deepest subdirectory in the provided path string. Path must not
@@ -357,6 +358,15 @@ static int delete_enlistment(struct strbuf *enlistment)
357358
return 0;
358359
}
359360

361+
/*
362+
* Dummy implementation; Using `get_version_info()` would cause a link error
363+
* without this.
364+
*/
365+
void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
366+
{
367+
die("not implemented");
368+
}
369+
360370
static int cmd_clone(int argc, const char **argv)
361371
{
362372
const char *branch = NULL;
@@ -750,6 +760,34 @@ static int cmd_delete(int argc, const char **argv)
750760
return res;
751761
}
752762

763+
static int cmd_version(int argc, const char **argv)
764+
{
765+
int verbose = 0, build_options = 0;
766+
struct option options[] = {
767+
OPT__VERBOSE(&verbose, N_("include Git version")),
768+
OPT_BOOL(0, "build-options", &build_options,
769+
N_("include Git's build options")),
770+
OPT_END(),
771+
};
772+
const char * const usage[] = {
773+
N_("scalar verbose [-v | --verbose] [--build-options]"),
774+
NULL
775+
};
776+
struct strbuf buf = STRBUF_INIT;
777+
778+
argc = parse_options(argc, argv, NULL, options,
779+
usage, 0);
780+
781+
if (argc != 0)
782+
usage_with_options(usage, options);
783+
784+
get_version_info(&buf, build_options);
785+
fprintf(stderr, "%s\n", buf.buf);
786+
strbuf_release(&buf);
787+
788+
return 0;
789+
}
790+
753791
static struct {
754792
const char *name;
755793
int (*fn)(int, const char **);
@@ -761,6 +799,7 @@ static struct {
761799
{ "run", cmd_run },
762800
{ "reconfigure", cmd_reconfigure },
763801
{ "delete", cmd_delete },
802+
{ "version", cmd_version },
764803
{ NULL, NULL},
765804
};
766805

0 commit comments

Comments
 (0)