Commit d142fc4582a55b3d8550935f8546bfa080f2bd98

Stefan Sperling 2018-04-01T19:48:17

tweak the log command synopsis and update man page

diff --git a/got/got.1 b/got/got.1
index 84b212f..e776aa4 100644
--- a/got/got.1
+++ b/got/got.1
@@ -75,11 +75,19 @@ In this case, only files beneath the specified directory prefix will
 be checked out.
 .\".It Cm status
 .\"Show current status of files.
-.It Cm log
+.It Cm log [ Fl p ] [ Fl c Ar commit ] [ Ar repository-path ]
 Display history of the repository.
 If the
 .Fl p
 flag is given, display the patch of modifications made in each commit.
+If a
+.Ar commit
+is specified with the
+.Fl c
+option, start traversing history at this commit.
+If the
+.Ar repository path
+is omitted, use the current working directory.
 .El
 .Sh EXIT STATUS
 .Ex -std got
diff --git a/got/got.c b/got/got.c
index 41ca7c9..ba1a257 100644
--- a/got/got.c
+++ b/got/got.c
@@ -404,7 +404,7 @@ print_commits(struct got_object *root_obj, struct got_object_id *root_id,
 __dead void
 usage_log(void)
 {
-	fprintf(stderr, "usage: %s log [-p] [repository-path] [commit]\n",
+	fprintf(stderr, "usage: %s log [-p] [-c commit] [repository-path]\n",
 	    getprogname());
 	exit(1);
 }
@@ -417,7 +417,7 @@ cmd_log(int argc, char *argv[])
 	struct got_object_id *id = NULL;
 	struct got_object *obj;
 	char *repo_path = NULL;
-	char *commit_id_str = NULL;
+	char *start_commit = NULL;
 	int ch;
 	int show_patch = 0;
 
@@ -426,11 +426,14 @@ cmd_log(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "p")) != -1) {
+	while ((ch = getopt(argc, argv, "pc:")) != -1) {
 		switch (ch) {
 		case 'p':
 			show_patch = 1;
 			break;
+		case 'c':
+			start_commit = optarg;
+			break;
 		default:
 			usage();
 			/* NOTREACHED */
@@ -446,9 +449,6 @@ cmd_log(int argc, char *argv[])
 			err(1, "getcwd");
 	} else if (argc == 1) {
 		repo_path = argv[0];
-	} else if (argc == 2) {
-		repo_path = argv[0];
-		commit_id_str = argv[1];
 	} else
 		usage_log();
 
@@ -456,7 +456,7 @@ cmd_log(int argc, char *argv[])
 	if (error != NULL)
 		return error;
 
-	if (commit_id_str == NULL) {
+	if (start_commit == NULL) {
 		struct got_reference *head_ref;
 		error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
 		if (error != NULL)
@@ -467,7 +467,7 @@ cmd_log(int argc, char *argv[])
 			return error;
 		error = got_object_open(&obj, repo, id);
 	} else {
-		error = got_object_open_by_id_str(&obj, repo, commit_id_str);
+		error = got_object_open_by_id_str(&obj, repo, start_commit);
 		if (error == NULL) {
 			id = got_object_get_id(obj);
 			if (id == NULL)