commit 1fc091f308f7aba6185a85cf0a8a3a8441c11458 from: Mark Jamsek via: Thomas Adam date: Tue Sep 05 17:45:48 2023 UTC tog: add basic regress for log limit and log search This required minor changes to tog.c to teach tog the new test instructions and feed it search terms when driven by the harness. More is needed for these features but this provides some basic coverage for the & and / log keymaps. ok stsp commit - 236685110a720e7794a734da8872ac71174f3291 commit + 1fc091f308f7aba6185a85cf0a8a3a8441c11458 blob - c9e0f9386c09837c4f369034ac78348d9c7f2abd blob + bc8e1f86537b6f5d928c84cdd4144af824835317 --- regress/tog/log.sh +++ regress/tog/log.sh @@ -572,17 +572,157 @@ test_log_show_base_commit() commit $head_id [1/3] master $ymd flan_hacker ~[master] new base mixed-commit $ymd flan_hacker base commit + EOF + + tog log + cmp -s "$testroot/view.expected" "$testroot/view" + ret=$? + if [ $ret -ne 0 ]; then + diff -u "$testroot/view.expected" "$testroot/view" + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_log_limit_view() +{ + test_init log_limit_view 80 4 + local repo="$testroot/repo" + local wt="$testroot/wt" + + got checkout "$repo" "$wt" > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got checkout failed unexpectedly" + test_done "$testroot" "$ret" + return 1 + fi + + cd "$wt" + + echo "alpha0" > alpha + got commit -m alpha0 > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "beta0" > beta + got commit -m beta0 > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "alpha1" > alpha + got commit -m alpha1 > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "beta1" > beta + got commit -m beta1 > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + local author_time=$(git_show_author_time "$repo") + local ymd=$(date -u -r $author_time +"%G-%m-%d") + local id=$(git_show_head "$repo") + + # check base commit marker is not drawn + cat <<-EOF >$TOG_TEST_SCRIPT + &beta + SCREENDUMP EOF + cat <<-EOF >$testroot/view.expected + commit $id [1/2] master + $ymd flan_hacker [master] beta1 + $ymd flan_hacker beta0 + + EOF + tog log cmp -s "$testroot/view.expected" "$testroot/view" ret=$? if [ $ret -ne 0 ]; then diff -u "$testroot/view.expected" "$testroot/view" + fi + test_done "$testroot" "$ret" +} + +test_log_search() +{ + test_init log_search 80 8 + local repo="$testroot/repo" + local wt="$testroot/wt" + local id=$(git_show_head "$repo") + + set -- "$id" + + got checkout "$repo" "$wt" > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got checkout failed unexpectedly" test_done "$testroot" "$ret" return 1 fi + cd "$wt" + + for i in $(seq 16); do + echo "alpha $i" > alpha + + got ci -m "alpha commit $i" > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + id=$(git_show_head "$repo") + set -- "$@" "$id" + done + + local author_time=$(git_show_author_time "$repo") + local ymd=$(date -u -r $author_time +"%G-%m-%d") + + cat <<-EOF >$TOG_TEST_SCRIPT + /alpha commit 8 + n + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + commit $(pop_idx 9 $@) [9/17] no more matches + $ymd flan_hacker alpha commit 14 + $ymd flan_hacker alpha commit 13 + $ymd flan_hacker alpha commit 12 + $ymd flan_hacker alpha commit 11 + $ymd flan_hacker alpha commit 10 + $ymd flan_hacker alpha commit 9 + $ymd flan_hacker alpha commit 8 + EOF + + tog log + cmp -s "$testroot/view.expected" "$testroot/view" + ret=$? + if [ $ret -ne 0 ]; then + diff -u "$testroot/view.expected" "$testroot/view" + fi test_done "$testroot" "$ret" } @@ -596,3 +736,5 @@ run_test test_log_hsplit_tree run_test test_log_logmsg_widechar run_test test_log_commit_keywords run_test test_log_show_base_commit +run_test test_log_limit_view +run_test test_log_search blob - eae631b96969f4879fee13d1decff2fc94ffdf11 blob + ef460ef97a1a026c9f09084327688fc233fa180d --- tog/tog.c +++ tog/tog.c @@ -632,6 +632,7 @@ struct tog_io { FILE *cout; FILE *f; FILE *sdump; + char *input_str; int wait_for_ui; } tog_io; static int using_mock_io; @@ -1337,21 +1338,26 @@ view_search_start(struct tog_view *view, int fast_refr else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent) v = view->parent; - mvwaddstr(v->window, v->nlines - 1, 0, "/"); - wclrtoeol(v->window); - - nodelay(v->window, FALSE); /* block for search term input */ - nocbreak(); - echo(); - ret = wgetnstr(v->window, pattern, sizeof(pattern)); - wrefresh(v->window); - cbreak(); - noecho(); - nodelay(v->window, TRUE); - if (!fast_refresh && !using_mock_io) - halfdelay(10); - if (ret == ERR) - return NULL; + if (tog_io.input_str != NULL) { + if (strlcpy(pattern, tog_io.input_str, sizeof(pattern)) >= + sizeof(pattern)) + return got_error(GOT_ERR_NO_SPACE); + } else { + mvwaddstr(v->window, v->nlines - 1, 0, "/"); + wclrtoeol(v->window); + nodelay(v->window, FALSE); /* block for search term input */ + nocbreak(); + echo(); + ret = wgetnstr(v->window, pattern, sizeof(pattern)); + wrefresh(v->window); + cbreak(); + noecho(); + nodelay(v->window, TRUE); + if (!fast_refresh && !using_mock_io) + halfdelay(10); + if (ret == ERR) + return NULL; + } if (regcomp(&view->regex, pattern, REG_EXTENDED | REG_NEWLINE) == 0) { err = view->search_start(view); @@ -1633,14 +1639,16 @@ tog_read_script_key(FILE *script, struct tog_view *vie const struct got_error *err = NULL; char *line = NULL; size_t linesz = 0; + ssize_t n; + if (view->count && --view->count) { *ch = view->ch; return NULL; } else *ch = -1; - if (getline(&line, &linesz, script) == -1) { + if ((n = getline(&line, &linesz, script)) == -1) { if (feof(script)) { *done = 1; goto done; @@ -1675,8 +1683,17 @@ tog_read_script_key(FILE *script, struct tog_view *vie *t = '\0'; /* ignore error, view->count is 0 if instruction is invalid */ view->count = strtonum(line, 0, INT_MAX, NULL); - } else + } else { *ch = *line; + if (n > 2 && (*ch == '/' || *ch == '&')) { + /* skip leading keymap and trim trailing newline */ + tog_io.input_str = strndup(line + 1, n - 2); + if (tog_io.input_str == NULL) { + err = got_error_from_errno("strndup"); + goto done; + } + } + } done: free(line); @@ -1967,6 +1984,8 @@ tog_io_close(void) err = got_ferror(tog_io.f, GOT_ERR_IO); if (tog_io.sdump && fclose(tog_io.sdump) == EOF && err == NULL) err = got_ferror(tog_io.sdump, GOT_ERR_IO); + if (tog_io.input_str != NULL) + free(tog_io.input_str); return err; } @@ -3551,19 +3570,24 @@ limit_log_view(struct tog_view *view) else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent) v = view->parent; - /* Get the pattern */ - wmove(v->window, v->nlines - 1, 0); - wclrtoeol(v->window); - mvwaddstr(v->window, v->nlines - 1, 0, "&/"); - nodelay(v->window, FALSE); - nocbreak(); - echo(); - ret = wgetnstr(v->window, pattern, sizeof(pattern)); - cbreak(); - noecho(); - nodelay(v->window, TRUE); - if (ret == ERR) - return NULL; + if (tog_io.input_str != NULL) { + if (strlcpy(pattern, tog_io.input_str, sizeof(pattern)) >= + sizeof(pattern)) + return got_error(GOT_ERR_NO_SPACE); + } else { + wmove(v->window, v->nlines - 1, 0); + wclrtoeol(v->window); + mvwaddstr(v->window, v->nlines - 1, 0, "&/"); + nodelay(v->window, FALSE); + nocbreak(); + echo(); + ret = wgetnstr(v->window, pattern, sizeof(pattern)); + cbreak(); + noecho(); + nodelay(v->window, TRUE); + if (ret == ERR) + return NULL; + } if (*pattern == '\0') { /* @@ -3674,19 +3698,22 @@ search_next_log_view(struct tog_view *view) doupdate(); if (s->search_entry) { - int errcode, ch; - errcode = pthread_mutex_unlock(&tog_mutex); - if (errcode) - return got_error_set_errno(errcode, - "pthread_mutex_unlock"); - ch = wgetch(view->window); - errcode = pthread_mutex_lock(&tog_mutex); - if (errcode) - return got_error_set_errno(errcode, - "pthread_mutex_lock"); - if (ch == CTRL('g') || ch == KEY_BACKSPACE) { - view->search_next_done = TOG_SEARCH_HAVE_MORE; - return NULL; + if (!using_mock_io) { + int errcode, ch; + + errcode = pthread_mutex_unlock(&tog_mutex); + if (errcode) + return got_error_set_errno(errcode, + "pthread_mutex_unlock"); + ch = wgetch(view->window); + errcode = pthread_mutex_lock(&tog_mutex); + if (errcode) + return got_error_set_errno(errcode, + "pthread_mutex_lock"); + if (ch == CTRL('g') || ch == KEY_BACKSPACE) { + view->search_next_done = TOG_SEARCH_HAVE_MORE; + return NULL; + } } if (view->searching == TOG_SEARCH_FORWARD) entry = TAILQ_NEXT(s->search_entry, entry);