Skip to content

Commit 0198e14

Browse files
committed
svnbrowse: Add a function that creates model from a specific URL at revision
and performs all required initialization. * subversion/svnbrowse/svnbrowse.c (init_client): Remove function. (model_create): New function that replaces init_client. (sub_main): Forward to model_create() so it constructs the model; Make the it so the ctx local variable is a pointer to that model. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1932719 13f79535-47bb-0310-9956-ffa450edef68
1 parent f3e35bd commit 0198e14

1 file changed

Lines changed: 49 additions & 31 deletions

File tree

subversion/svnbrowse/svnbrowse.c

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,6 @@ typedef struct svn_browse__model_t {
6868
apr_pool_t *pool;
6969
} svn_browse__model_t;
7070

71-
static svn_error_t *
72-
init_client(svn_browse__model_t *ctx, apr_pool_t *pool)
73-
{
74-
svn_auth_baton_t *auth;
75-
76-
SVN_ERR(svn_client_create_context2(&ctx->client, NULL, pool));
77-
78-
/* Set up Authentication stuff. */
79-
SVN_ERR(svn_cmdline_create_auth_baton2(&auth, FALSE, NULL, NULL, NULL, FALSE,
80-
FALSE, FALSE, FALSE, FALSE, FALSE,
81-
NULL, NULL, NULL, pool));
82-
83-
ctx->client->auth_baton = auth;
84-
85-
return SVN_NO_ERROR;
86-
}
87-
8871
static svn_error_t *
8972
list_cb(void *baton,
9073
const char *path,
@@ -144,6 +127,41 @@ enter_path(svn_browse__model_t *ctx, const char *relpath,
144127
return SVN_NO_ERROR;
145128
}
146129

130+
static svn_error_t *
131+
model_create(svn_browse__model_t **model_p,
132+
const char *url,
133+
svn_opt_revision_t revision,
134+
apr_pool_t *result_pool,
135+
apr_pool_t *scratch_pool)
136+
{
137+
svn_browse__model_t *model = apr_pcalloc(result_pool, sizeof(*model));
138+
svn_auth_baton_t *auth;
139+
svn_client_ctx_t *client;
140+
apr_pool_t *state_pool;
141+
svn_browse__state_t *state;
142+
143+
/* Set up Authentication stuff. */
144+
SVN_ERR(svn_cmdline_create_auth_baton2(&auth, FALSE, NULL, NULL, NULL, FALSE,
145+
FALSE, FALSE, FALSE, FALSE, FALSE,
146+
NULL, NULL, NULL, result_pool));
147+
148+
SVN_ERR(svn_client_create_context2(&client, NULL, result_pool));
149+
client->auth_baton = auth;
150+
151+
/* TODO: we must use the repository root URL */
152+
model->root = apr_pstrdup(result_pool, url);
153+
model->revision = revision;
154+
model->client = client;
155+
model->pool = result_pool;
156+
157+
/* the state should be in a separate pool so it's safe to free it */
158+
state_pool = svn_pool_create(result_pool);
159+
SVN_ERR(state_create(&model->current, model, "", state_pool, scratch_pool));
160+
161+
*model_p = model;
162+
return SVN_NO_ERROR;
163+
}
164+
147165
static void
148166
ui_draw(svn_browse__model_t *ctx, apr_pool_t *pool)
149167
{
@@ -184,19 +202,19 @@ ui_draw(svn_browse__model_t *ctx, apr_pool_t *pool)
184202
static svn_error_t *
185203
sub_main(int *code, int argc, char *argv[], apr_pool_t *pool)
186204
{
187-
svn_browse__model_t ctx = { 0 };
205+
const char *url;
206+
svn_opt_revision_t revision;
207+
svn_browse__model_t *ctx;
188208
apr_pool_t *iterpool;
189209

190210
if (argc != 2)
191211
return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
192212
"usage: svnbrowse <URL>");
193213

194-
SVN_ERR(svn_uri_canonicalize_safe(&ctx.root, NULL, argv[1], pool, pool));
195-
ctx.revision.kind = svn_opt_revision_head;
196-
ctx.pool = pool;
214+
SVN_ERR(svn_uri_canonicalize_safe(&url, NULL, argv[1], pool, pool));
215+
revision.kind = svn_opt_revision_head;
197216

198-
SVN_ERR(init_client(&ctx, pool));
199-
SVN_ERR(state_create(&ctx.current, &ctx, "", svn_pool_create(pool), pool));
217+
SVN_ERR(model_create(&ctx, url, revision, pool, pool));
200218

201219
/* init the display */
202220
initscr();
@@ -216,7 +234,7 @@ sub_main(int *code, int argc, char *argv[], apr_pool_t *pool)
216234
const char *new_url;
217235

218236
clear();
219-
ui_draw(&ctx, iterpool);
237+
ui_draw(ctx, iterpool);
220238
refresh();
221239

222240
/* getch() reads the next character/key with the following additional
@@ -232,25 +250,25 @@ sub_main(int *code, int argc, char *argv[], apr_pool_t *pool)
232250
{
233251
case KEY_UP:
234252
case 'k':
235-
ctx.current->selection--;
253+
ctx->current->selection--;
236254
break;
237255
case KEY_DOWN:
238256
case 'j':
239-
ctx.current->selection++;
257+
ctx->current->selection++;
240258
break;
241259
case '\n':
242260
case '\r':
243-
item = APR_ARRAY_IDX(ctx.current->list, ctx.current->selection,
261+
item = APR_ARRAY_IDX(ctx->current->list, ctx->current->selection,
244262
svn_browse__item_t *);
245-
new_url = svn_relpath_join(ctx.current->relpath, item->relpath,
263+
new_url = svn_relpath_join(ctx->current->relpath, item->relpath,
246264
iterpool);
247-
SVN_ERR(enter_path(&ctx, new_url, iterpool));
265+
SVN_ERR(enter_path(ctx, new_url, iterpool));
248266
break;
249267
case KEY_BACKSPACE:
250268
case '-':
251269
case 'u':
252-
new_url = svn_relpath_dirname(ctx.current->relpath, iterpool);
253-
SVN_ERR(enter_path(&ctx, new_url, iterpool));
270+
new_url = svn_relpath_dirname(ctx->current->relpath, iterpool);
271+
SVN_ERR(enter_path(ctx, new_url, iterpool));
254272
break;
255273
/* TODO: quit via escape. some say just check for 27, but it I think it's
256274
* a bit ugly. */

0 commit comments

Comments
 (0)