make 'got log' accept a path to repository
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/got/got.c b/got/got.c
index 64b71bc..c6d31fe 100644
--- a/got/got.c
+++ b/got/got.c
@@ -40,6 +40,7 @@ struct cmd {
};
__dead void usage(void);
+__dead void usage_log(void);
int cmd_log(int, char *[]);
int cmd_status(int, char *[]);
@@ -151,6 +152,13 @@ print_commit_object(struct got_object *obj, struct got_object_id *id,
return err;
}
+__dead void
+usage_log(void)
+{
+ fprintf(stderr, "usage: %s log [REPO_PATH]\n", getprogname());
+ exit(1);
+}
+
int
cmd_log(int argc, char *argv[])
{
@@ -159,15 +167,19 @@ cmd_log(int argc, char *argv[])
struct got_reference *head_ref;
struct got_object_id *id;
struct got_object *obj;
- char *repo_path;
+ char *repo_path = NULL;
if (pledge("stdio rpath wpath cpath", NULL) == -1)
err(1, "pledge");
- /* TODO parse argv */
- repo_path = getcwd(NULL, 0);
- if (repo_path == NULL)
- err(1, "getcwd");
+ if (argc == 1) {
+ repo_path = getcwd(NULL, 0);
+ if (repo_path == NULL)
+ err(1, "getcwd");
+ } else if (argc == 2)
+ repo_path = argv[1];
+ else
+ usage_log();
error = got_repo_open(&repo, repo_path);
if (error != NULL || repo == NULL)