allow matching commit IDs in 'tog log' search
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
diff --git a/tog/tog.1 b/tog/tog.1
index a263a2b..da9425a 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -107,7 +107,8 @@ Show log entries for the parent directory of the currently selected path.
.It Cm /
Prompt for a search pattern and start searching for matching commits.
The search pattern is an extended regular expression which is matched
-against a commit's author name, committer name, and log message.
+against a commit's author name, committer name, log message, and
+commit ID SHA1 hash.
Regular expression syntax is documented in
.Xr re_format 7 .
.It Cm n
diff --git a/tog/tog.c b/tog/tog.c
index 3c2a6b3..2b8c94f 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1723,7 +1723,8 @@ search_start_log_view(struct tog_view *view)
}
static int
-match_commit(struct got_commit_object *commit, regex_t *regex)
+match_commit(struct got_commit_object *commit, const char *id_str,
+ regex_t *regex)
{
regmatch_t regmatch;
@@ -1732,7 +1733,8 @@ match_commit(struct got_commit_object *commit, regex_t *regex)
regexec(regex, got_object_commit_get_committer(commit), 1,
®match, 0) == 0 ||
regexec(regex, got_object_commit_get_logmsg(commit), 1,
- ®match, 0) == 0)
+ ®match, 0) == 0 ||
+ regexec(regex, id_str, 1, ®match, 0) == 0)
return 1;
return 0;
@@ -1764,6 +1766,7 @@ search_next_log_view(struct tog_view *view)
}
while (1) {
+ char *id_str;
if (entry == NULL) {
if (s->thread_args.log_complete ||
view->searching == TOG_SEARCH_BACKWARD) {
@@ -1777,11 +1780,17 @@ search_next_log_view(struct tog_view *view)
&s->thread_args.need_commits);
}
- if (match_commit(entry->commit, &view->regex)) {
+ err = got_object_id_str(&id_str, entry->id);
+ if (err)
+ return err;
+
+ if (match_commit(entry->commit, id_str, &view->regex)) {
view->search_next_done = 1;
s->matched_entry = entry;
+ free(id_str);
break;
}
+ free(id_str);
if (view->searching == TOG_SEARCH_FORWARD)
entry = TAILQ_NEXT(entry, entry);
else