Author: rinrab
Date: Thu Apr 2 20:13:49 2026
New Revision: 1932767
Log:
svnbrowse: Factor-out functions to performa all actions with the model.
* subversion/svnbrowse/svnbrowse.c
(enter_path -> model_enter_path): Rename for consistency.
(model_get_selected_item,
model_go_enter,
model_go_up,
model_move_selection): New functions.
(sub_main): Use those functions.
Modified:
subversion/trunk/subversion/svnbrowse/svnbrowse.c
Modified: subversion/trunk/subversion/svnbrowse/svnbrowse.c
==============================================================================
--- subversion/trunk/subversion/svnbrowse/svnbrowse.c Thu Apr 2 19:46:31 2026 (r1932766)
+++ subversion/trunk/subversion/svnbrowse/svnbrowse.c Thu Apr 2 20:13:49 2026 (r1932767)
@@ -109,8 +109,8 @@ state_create(svn_browse__state_t **state
}
static svn_error_t *
-enter_path(svn_browse__model_t *ctx, const char *relpath,
- apr_pool_t *scratch_pool)
+model_enter_path(svn_browse__model_t *ctx, const char *relpath,
+ apr_pool_t *scratch_pool)
{
svn_browse__state_t *newstate;
apr_pool_t *state_pool = svn_pool_create(ctx->pool);
@@ -125,6 +125,44 @@ enter_path(svn_browse__model_t *ctx, con
return SVN_NO_ERROR;
}
+static svn_browse__item_t *
+model_get_selected_item(svn_browse__model_t *model)
+{
+ return APR_ARRAY_IDX(model->current->list, model->current->selection,
+ svn_browse__item_t *);
+}
+
+static svn_error_t *
+model_go_enter(svn_browse__model_t *model, apr_pool_t *scratch_pool)
+{
+ svn_browse__item_t *item = model_get_selected_item(model);
+ const char *new_url = svn_relpath_join(model->current->relpath, item->name,
+ scratch_pool);
+ return svn_error_trace(model_enter_path(model, new_url, scratch_pool));
+}
+
+static svn_error_t *
+model_go_up(svn_browse__model_t *model, apr_pool_t *scratch_pool)
+{
+ const char *new_url = svn_relpath_dirname(model->current->relpath,
+ scratch_pool);
+ return svn_error_trace(model_enter_path(model, new_url, scratch_pool));
+}
+
+static svn_error_t *
+model_move_selection(svn_browse__model_t *model, int delta)
+{
+ model->current->selection += delta;
+
+ if (model->current->selection >= model->current->list->nelts)
+ model->current->selection = model->current->list->nelts - 1;
+
+ if (model->current->selection < 0)
+ model->current->selection = 0;
+
+ return SVN_NO_ERROR;
+}
+
static svn_error_t *
model_create(svn_browse__model_t **model_p,
const char *url,
@@ -271,25 +309,20 @@ sub_main(int *code, int argc, char *argv
{
case KEY_UP:
case 'k':
- ctx->current->selection--;
+ SVN_ERR(model_move_selection(ctx, -1));
break;
case KEY_DOWN:
case 'j':
- ctx->current->selection++;
+ SVN_ERR(model_move_selection(ctx, 1));
break;
case '\n':
case '\r':
- item = APR_ARRAY_IDX(ctx->current->list, ctx->current->selection,
- svn_browse__item_t *);
- new_url = svn_relpath_join(ctx->current->relpath, item->name,
- iterpool);
- SVN_ERR(enter_path(ctx, new_url, iterpool));
+ SVN_ERR(model_go_enter(ctx, iterpool));
break;
case KEY_BACKSPACE:
case '-':
case 'u':
- new_url = svn_relpath_dirname(ctx->current->relpath, iterpool);
- SVN_ERR(enter_path(ctx, new_url, iterpool));
+ SVN_ERR(model_go_up(ctx, iterpool));
break;
/* TODO: quit via escape. some say just check for 27, but it I think it's
* a bit ugly. */
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.