Commit 09b5bff804353d5930f67d05e453815493aeb225

Christian Weisgerber 2020-02-23T16:28:39

switch "tog diff" repository path argument to a new -r option

diff --git a/tog/tog.1 b/tog/tog.1
index e27af0c..60eb4e5 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -166,7 +166,7 @@ Use the repository at the specified path.
 If not specified, assume the repository is located at or above the current
 working directory.
 .El
-.It Cm diff Oo Ar repository-path Oc Ar object1 object2
+.It Cm diff Oo Fl r Ar repository-path Oc Ar object1 object2
 Display the differences between two objects in the repository.
 Each
 .Ar object
@@ -174,9 +174,6 @@ argument is an object ID SHA1 hash.
 An abbreviated hash argument will be expanded to a full SHA1 hash
 automatically, provided the abbreviation is unique.
 Both objects must be of the same type (blobs, trees, or commits).
-If the
-.Ar repository path
-is omitted, use the current working directory.
 .Pp
 The key bindings for
 .Cm tog diff
@@ -209,6 +206,16 @@ Find the next line which matches the current search pattern.
 .It Cm N
 Find the previous line which matches the current search pattern.
 .El
+.Pp
+The options for
+.Cm tog diff
+are as follows:
+.Bl -tag -width Ds
+.It Fl r Ar repository-path
+Use the repository at the specified path.
+If not specified, assume the repository is located at or above the current
+working directory.
+.El
 .It Cm blame Oo Fl c Ar commit Oc Oo Fl r Ar repository-path Oc Ar path
 Display line-by-line history of a file at the specified path.
 .Pp
diff --git a/tog/tog.c b/tog/tog.c
index 1a25cb8..db491e8 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2682,7 +2682,7 @@ __dead static void
 usage_diff(void)
 {
 	endwin();
-	fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
+	fprintf(stderr, "usage: %s diff [-r repository-path] object1 object2\n",
 	    getprogname());
 	exit(1);
 }
@@ -3491,8 +3491,14 @@ cmd_diff(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "")) != -1) {
+	while ((ch = getopt(argc, argv, "r:")) != -1) {
 		switch (ch) {
+		case 'r':
+			repo_path = realpath(optarg, NULL);
+			if (repo_path == NULL)
+				return got_error_from_errno2("realpath",
+				    optarg);
+			break;
 		default:
 			usage_diff();
 			/* NOTREACHED */
@@ -3507,12 +3513,6 @@ cmd_diff(int argc, char *argv[])
 	} else if (argc == 2) {
 		id_str1 = argv[0];
 		id_str2 = argv[1];
-	} else if (argc == 3) {
-		repo_path = realpath(argv[0], NULL);
-		if (repo_path == NULL)
-			return got_error_from_errno2("realpath", argv[0]);
-		id_str1 = argv[1];
-		id_str2 = argv[2];
 	} else
 		usage_diff();