Commit Diff


commit - a39318fdf6658589063d3c3e85f3d56d03d9671c
commit + 69069811fa4d44f2abcf73fefdfb36fee7e9d9fe
blob - 317a0460c3863d0762a84f9c3ff292e39492445b
blob + 1aedfa7a0aa6f30a02df7becc13ab7762aa94ce5
--- tog/tog.1
+++ tog/tog.1
@@ -109,11 +109,8 @@ Quit the
 .Cm diff
 view.
 .El
-.It Cm blame [ Fl c Ar commit ] [ Ar repository-path ] Ar path
+.It Cm blame [ Fl c Ar commit ] [ Fl r Ar repository-path ] Ar path
 Display line-by-line history of a file at the specified path.
-If the
-.Ar repository path
-is omitted, assume the repository is located in the current working directory.
 .Pp
 The key bindings for
 .Cm tog blame
@@ -155,6 +152,10 @@ Start traversing history at the specified
 .Ar commit .
 The expected argument is the name of a branch or a SHA1 hash which corresponds
 to a commit object.
+.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 tree [ Fl c Ar commit ] [ Ar repository-path ]
 Display the repository tree.
blob - da22851072b220214f9be1970f360fb5c1f4a895
blob + 3913894ecf46f0dc2440ccdd0cd315f5fcfae288
--- tog/tog.c
+++ tog/tog.c
@@ -1284,7 +1284,7 @@ __dead static void
 usage_blame(void)
 {
 	endwin();
-	fprintf(stderr, "usage: %s blame [-c commit] [repository-path] path\n",
+	fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
 	    getprogname());
 	exit(1);
 }
@@ -1935,8 +1935,7 @@ cmd_blame(int argc, char *argv[])
 {
 	const struct got_error *error;
 	struct got_repository *repo = NULL;
-	char *repo_path = NULL;
-	char *path = NULL;
+	char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
 	struct got_object_id *commit_id = NULL;
 	char *commit_id_str = NULL;
 	int ch;
@@ -1947,11 +1946,16 @@ cmd_blame(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "c:")) != -1) {
+	while ((ch = getopt(argc, argv, "c:r:")) != -1) {
 		switch (ch) {
 		case 'c':
 			commit_id_str = optarg;
 			break;
+		case 'r':
+			repo_path = realpath(optarg, NULL);
+			if (repo_path == NULL)
+				err(1, "-r option");
+			break;
 		default:
 			usage();
 			/* NOTREACHED */
@@ -1961,25 +1965,32 @@ cmd_blame(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 
-	if (argc == 0) {
+	if (argc == 1)
+		path = argv[0];
+	else
 		usage_blame();
-	} else if (argc == 1) {
-		repo_path = getcwd(NULL, 0);
-		if (repo_path == NULL)
-			return got_error_from_errno();
-		path = argv[0];
-	} else if (argc == 2) {
-		repo_path = realpath(argv[0], NULL);
-		if (repo_path == NULL)
-			return got_error_from_errno();
-		path = argv[1];
-	} else
-		usage_blame();
-
-	error = got_repo_open(&repo, repo_path);
-	free(repo_path);
+
+	cwd = getcwd(NULL, 0);
+	if (cwd == NULL) {
+		error = got_error_from_errno();
+		goto done;
+	}
+	if (repo_path == NULL) {
+		repo_path = strdup(cwd);
+		if (repo_path == NULL) {
+			error = got_error_from_errno();
+			goto done;
+		}
+	}
+
+
+	error = got_repo_open(&repo, repo_path);
 	if (error != NULL)
 		return error;
+
+	error = got_repo_map_path(&in_repo_path, repo, path);
+	if (error != NULL)
+		goto done;
 
 	if (commit_id_str == NULL) {
 		struct got_reference *head_ref;
@@ -2006,9 +2017,12 @@ cmd_blame(int argc, char *argv[])
 		error = got_error_from_errno();
 		goto done;
 	}
-	error = show_blame_view(view, path, commit_id, repo);
+	error = show_blame_view(view, in_repo_path, commit_id, repo);
 	close_view(view);
 done:
+	free(in_repo_path);
+	free(repo_path);
+	free(cwd);
 	free(commit_id);
 	if (repo)
 		got_repo_close(repo);