add one-line output mode to got log with -s flag -s for short. Moves log search to -S. Patch by Evan Silberman
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
diff --git a/got/got.1 b/got/got.1
index b91cfb2..44f372d 100644
--- a/got/got.1
+++ b/got/got.1
@@ -756,7 +756,7 @@ does not support negated ignore patterns prefixed with
and gives no special significance to the location of path component separators,
.Dq / ,
in a pattern.
-.It Cm log Oo Fl b Oc Oo Fl c Ar commit Oc Oo Fl C Ar number Oc Oo Fl l Ar N Oc Oo Fl p Oc Oo Fl P Oc Oo Fl s Ar search-pattern Oc Oo Fl r Ar repository-path Oc Oo Fl R Oc Oo Fl x Ar commit Oc Op Ar path
+.It Cm log Oo Fl b Oc Oo Fl c Ar commit Oc Oo Fl C Ar number Oc Oo Fl l Ar N Oc Oo Fl p Oc Oo Fl P Oc Oo Fl s Oc Oo Fl S Ar search-pattern Oc Oo Fl r Ar repository-path Oc Oo Fl R Oc Oo Fl x Ar commit Oc Op Ar path
Display history of a repository.
If a
.Ar path
@@ -802,6 +802,9 @@ Display the patch of modifications made in each commit.
If a
.Ar path
is specified, only show the patch of modifications at or within this path.
+Cannot be used with the
+.Fl s
+option.
.It Fl P
Display the list of file paths changed in each commit, using the following
status codes:
@@ -811,7 +814,20 @@ status codes:
.It A Ta new file was added
.It m Ta modified file modes (executable bit only)
.El
-.It Fl s Ar search-pattern
+Cannot be used with the
+.Fl s
+option.
+.It Fl s
+Display a short one-line summary of each commit, instead of the default
+history format.
+The one-line format prints the beginning of the SHA1 hash of each commit,
+followed by a space and the first line of the log message.
+Cannot be used together with the
+.Fl p
+or
+.Fl P
+option.
+.It Fl S Ar search-pattern
If specified, show only commits with a log message matched by the extended
regular expression
.Ar search-pattern .
diff --git a/got/got.c b/got/got.c
index d88f23c..473318f 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3841,6 +3841,39 @@ build_refs_str(char **refs_str, struct got_reflist_head *refs,
}
static const struct got_error *
+print_commit_oneline(struct got_commit_object *commit, struct got_object_id *id)
+{
+ const struct got_error *err = NULL;
+ char *id_str, *s, *nl, *logmsg0;
+
+ err = got_object_id_str(&id_str, id);
+ if (err)
+ return err;
+
+ err = got_object_commit_get_logmsg(&logmsg0, commit);
+ if (err)
+ goto done;
+
+ s = logmsg0;
+ while (isspace((unsigned char)s[0]))
+ s++;
+
+ nl = strchr(s, '\n');
+ if (nl) {
+ *nl = '\0';
+ }
+
+ printf("%.7s %s\n", id_str, s);
+
+ if (fflush(stdout) != 0 && err == NULL)
+ err = got_error_from_errno("fflush");
+done:
+ free(id_str);
+ free(logmsg0);
+ return err;
+}
+
+static const struct got_error *
print_commit(struct got_commit_object *commit, struct got_object_id *id,
struct got_repository *repo, const char *path,
struct got_pathlist_head *changed_paths, int show_patch,
@@ -3941,7 +3974,7 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
struct got_repository *repo, const char *path, int show_changed_paths,
int show_patch, const char *search_pattern, int diff_context, int limit,
int log_branches, int reverse_display_order,
- struct got_reflist_object_id_map *refs_idmap)
+ struct got_reflist_object_id_map *refs_idmap, int one_line)
{
const struct got_error *err;
struct got_commit_graph *graph;
@@ -4020,9 +4053,12 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
STAILQ_INSERT_HEAD(&reversed_commits, qid, entry);
got_object_commit_close(commit);
} else {
- err = print_commit(commit, id, repo, path,
- show_changed_paths ? &changed_paths : NULL,
- show_patch, diff_context, refs_idmap, NULL);
+ if (one_line)
+ err = print_commit_oneline(commit, id);
+ else
+ err = print_commit(commit, id, repo, path,
+ show_changed_paths ? &changed_paths : NULL,
+ show_patch, diff_context, refs_idmap, NULL);
got_object_commit_close(commit);
if (err)
break;
@@ -4049,9 +4085,12 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
if (err)
break;
}
- err = print_commit(commit, &qid->id, repo, path,
- show_changed_paths ? &changed_paths : NULL,
- show_patch, diff_context, refs_idmap, NULL);
+ if (one_line)
+ err = print_commit_oneline(commit, &qid->id);
+ else
+ err = print_commit(commit, &qid->id, repo, path,
+ show_changed_paths ? &changed_paths : NULL,
+ show_patch, diff_context, refs_idmap, NULL);
got_object_commit_close(commit);
if (err)
break;
@@ -4082,9 +4121,9 @@ done:
__dead static void
usage_log(void)
{
- fprintf(stderr, "usage: %s log [-b] [-c commit] [-C number] [ -l N ] "
- "[-p] [-P] [-x commit] [-s search-pattern] [-r repository-path] "
- "[-R] [path]\n", getprogname());
+ fprintf(stderr, "usage: %s log [-b] [-p] [-P] [-s] [-c commit] "
+ "[-C number] [ -l N ] [-x commit] [-S search-pattern] "
+ "[-r repository-path] [-R] [path]\n", getprogname());
exit(1);
}
@@ -4116,7 +4155,7 @@ cmd_log(int argc, char *argv[])
const char *search_pattern = NULL;
int diff_context = -1, ch;
int show_changed_paths = 0, show_patch = 0, limit = 0, log_branches = 0;
- int reverse_display_order = 0;
+ int reverse_display_order = 0, one_line = 0;
const char *errstr;
struct got_reflist_head refs;
struct got_reflist_object_id_map *refs_idmap = NULL;
@@ -4132,7 +4171,7 @@ cmd_log(int argc, char *argv[])
limit = get_default_log_limit();
- while ((ch = getopt(argc, argv, "bpPc:C:l:r:Rs:x:")) != -1) {
+ while ((ch = getopt(argc, argv, "bpPc:C:l:r:RsS:x:")) != -1) {
switch (ch) {
case 'p':
show_patch = 1;
@@ -4170,6 +4209,9 @@ cmd_log(int argc, char *argv[])
reverse_display_order = 1;
break;
case 's':
+ one_line = 1;
+ break;
+ case 'S':
search_pattern = optarg;
break;
case 'x':
@@ -4189,6 +4231,9 @@ cmd_log(int argc, char *argv[])
else if (!show_patch)
errx(1, "-C requires -p");
+ if (one_line && (show_patch || show_changed_paths))
+ errx(1, "cannot use -s with -p or -P");
+
cwd = getcwd(NULL, 0);
if (cwd == NULL) {
error = got_error_from_errno("getcwd");
@@ -4307,7 +4352,7 @@ cmd_log(int argc, char *argv[])
error = print_commits(start_id, end_id, repo, path ? path : "",
show_changed_paths, show_patch, search_pattern, diff_context,
- limit, log_branches, reverse_display_order, refs_idmap);
+ limit, log_branches, reverse_display_order, refs_idmap, one_line);
done:
free(path);
free(repo_path);
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index f13bd90..41cee9e 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -297,6 +297,40 @@ test_log_limit() {
test_done "$testroot" "0"
}
+test_log_oneline() {
+ local testroot=`test_init log_oneline`
+ local commit_id0=`git_show_head $testroot/repo`
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified alpha" > $testroot/wt/alpha
+ (cd $testroot/wt && got commit -m "test oneline
+no" > /dev/null)
+ local commit_id1=`git_show_head $testroot/repo`
+
+ echo "modified beta" > $testroot/wt/beta
+ (cd $testroot/wt && got commit -m " test oneline
+no" > /dev/null)
+ local commit_id2=`git_show_head $testroot/repo`
+
+ printf "%.7s test oneline\n" $commit_id2 > $testroot/stdout.expected
+ printf "%.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected
+
+ (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ test_done "$testroot" "0"
+}
+
test_log_patch_added_file() {
local testroot=`test_init log_patch_added_file`
local commit_id0=`git_show_head $testroot/repo`
@@ -587,7 +621,7 @@ test_log_reverse_display() {
# commit matching with -s applies before -R
echo "commit $commit_id1" > $testroot/stdout.expected
echo "commit $commit_id2" >> $testroot/stdout.expected
- (cd $testroot/wt && got log -R -s 'commit[12]' | \
+ (cd $testroot/wt && got log -R -S 'commit[12]' | \
grep ^commit > $testroot/stdout)
cmp -s $testroot/stdout.expected $testroot/stdout
ret=$?
@@ -815,6 +849,7 @@ run_test test_log_in_worktree
run_test test_log_in_worktree_with_path_prefix
run_test test_log_tag
run_test test_log_limit
+run_test test_log_oneline
run_test test_log_patch_added_file
run_test test_log_nonexistent_path
run_test test_log_end_at_commit