move tog blame's repo-path parameter to -r option
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/tog/tog.1 b/tog/tog.1
index 317a046..1aedfa7 100644
--- a/tog/tog.1
+++ b/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.
diff --git a/tog/tog.c b/tog/tog.c
index da22851..3913894 100644
--- a/tog/tog.c
+++ b/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,26 +1965,33 @@ cmd_blame(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc == 0) {
- usage_blame();
- } else if (argc == 1) {
- repo_path = getcwd(NULL, 0);
- if (repo_path == NULL)
- return got_error_from_errno();
+ if (argc == 1)
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
+ else
usage_blame();
+ 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);
- free(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;
error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
@@ -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);