118
* On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
119
* either return an error to be displayed, or set *EXIT_CODE to non-zero and
120
* return SVN_NO_ERROR.
118
122
* Why is this not an svn subcommand? I have this vague idea that it could
119
123
* be run as part of the build process, with the output embedded in the svn
120
124
* program. Obviously we don't want to have to run svn when building svn.
123
main(int argc, const char *argv[])
127
sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
125
129
const char *wc_path, *trail_url;
126
130
const char *local_abspath;
128
131
svn_wc_revision_status_t *res;
129
132
svn_boolean_t no_newline = FALSE, committed = FALSE;
130
133
svn_error_t *err;
147
/* Initialize the app. */
148
if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS)
151
/* Create our top-level pool. Use a separate mutexless allocator,
152
* given this application is single threaded.
154
pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
156
150
/* Check library versions */
157
err = check_lib_versions();
159
return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
151
SVN_ERR(check_lib_versions());
161
153
#if defined(WIN32) || defined(__CYGWIN__)
162
154
/* Set the working copy administrative directory name. */
163
155
if (getenv("SVN_ASP_DOT_NET_HACK"))
165
err = svn_wc_set_adm_dir("_svn", pool);
167
return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
157
SVN_ERR(svn_wc_set_adm_dir("_svn", pool));
171
err = svn_cmdline__getopt_init(&os, argc, argv, pool);
173
return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
161
SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
175
163
os->interleave = 1;
198
190
help(options, pool);
200
192
case SVNVERSION_OPT_VERSION:
201
193
is_version = TRUE;
204
usage(pool); /* this will exit() */
196
*exit_code = EXIT_FAILURE;
210
SVN_INT_ERR(version(quiet, pool));
204
SVN_ERR(version(quiet, pool));
213
207
if (os->ind > argc || os->ind < argc - 2)
214
usage(pool); /* this will exit() */
216
SVN_INT_ERR(svn_utf_cstring_to_utf8(&wc_path,
217
(os->ind < argc) ? os->argv[os->ind]
221
SVN_INT_ERR(svn_opt__arg_canonicalize_path(&wc_path, wc_path, pool));
222
SVN_INT_ERR(svn_dirent_get_absolute(&local_abspath, wc_path, pool));
223
SVN_INT_ERR(svn_wc_context_create(&wc_ctx, NULL, pool, pool));
209
*exit_code = EXIT_FAILURE;
214
SVN_ERR(svn_utf_cstring_to_utf8(&wc_path,
215
(os->ind < argc) ? os->argv[os->ind] : ".",
218
SVN_ERR(svn_opt__arg_canonicalize_path(&wc_path, wc_path, pool));
219
SVN_ERR(svn_dirent_get_absolute(&local_abspath, wc_path, pool));
220
SVN_ERR(svn_wc_context_create(&wc_ctx, NULL, pool, pool));
225
222
if (os->ind+1 < argc)
226
SVN_INT_ERR(svn_utf_cstring_to_utf8(&trail_url, os->argv[os->ind+1],
223
SVN_ERR(svn_utf_cstring_to_utf8(&trail_url, os->argv[os->ind+1], pool));
229
225
trail_url = NULL;
240
236
svn_error_clear(err);
242
SVN_INT_ERR(svn_io_check_special_path(local_abspath, &kind, &special,
238
SVN_ERR(svn_io_check_special_path(local_abspath, &kind, &special, pool));
246
SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned symlink%s"),
247
no_newline ? "" : "\n"));
241
SVN_ERR(svn_cmdline_printf(pool, _("Unversioned symlink%s"),
242
no_newline ? "" : "\n"));
248
243
else if (kind == svn_node_dir)
249
SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned directory%s"),
250
no_newline ? "" : "\n"));
244
SVN_ERR(svn_cmdline_printf(pool, _("Unversioned directory%s"),
245
no_newline ? "" : "\n"));
251
246
else if (kind == svn_node_file)
252
SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned file%s"),
253
no_newline ? "" : "\n"));
247
SVN_ERR(svn_cmdline_printf(pool, _("Unversioned file%s"),
248
no_newline ? "" : "\n"));
256
SVN_INT_ERR(svn_cmdline_fprintf(stderr, pool,
257
kind == svn_node_none
258
? _("'%s' doesn't exist\n")
259
: _("'%s' is of unknown type\n"),
260
svn_dirent_local_style(local_abspath,
262
svn_pool_destroy(pool);
251
SVN_ERR(svn_cmdline_fprintf(stderr, pool,
252
kind == svn_node_none
253
? _("'%s' doesn't exist\n")
254
: _("'%s' is of unknown type\n"),
255
svn_dirent_local_style(local_abspath,
257
*exit_code = EXIT_FAILURE;
265
svn_pool_destroy(pool);
271
265
if (! SVN_IS_VALID_REVNUM(res->min_rev))
273
267
/* Local uncommitted modifications, no revision info was found. */
274
SVN_INT_ERR(svn_cmdline_printf(pool, _("Uncommitted local addition, "
276
no_newline ? "" : "\n"));
277
svn_pool_destroy(pool);
268
SVN_ERR(svn_cmdline_printf(pool, _("Uncommitted local addition, "
270
no_newline ? "" : "\n"));
281
274
/* Build compact '123[:456]M?S?' string. */
282
SVN_INT_ERR(svn_cmdline_printf(pool, "%ld", res->min_rev));
275
SVN_ERR(svn_cmdline_printf(pool, "%ld", res->min_rev));
283
276
if (res->min_rev != res->max_rev)
284
SVN_INT_ERR(svn_cmdline_printf(pool, ":%ld", res->max_rev));
277
SVN_ERR(svn_cmdline_printf(pool, ":%ld", res->max_rev));
285
278
if (res->modified)
286
SVN_INT_ERR(svn_cmdline_fputs("M", stdout, pool));
279
SVN_ERR(svn_cmdline_fputs("M", stdout, pool));
287
280
if (res->switched)
288
SVN_INT_ERR(svn_cmdline_fputs("S", stdout, pool));
281
SVN_ERR(svn_cmdline_fputs("S", stdout, pool));
289
282
if (res->sparse_checkout)
290
SVN_INT_ERR(svn_cmdline_fputs("P", stdout, pool));
283
SVN_ERR(svn_cmdline_fputs("P", stdout, pool));
292
285
if (! no_newline)
293
SVN_INT_ERR(svn_cmdline_fputs("\n", stdout, pool));
286
SVN_ERR(svn_cmdline_fputs("\n", stdout, pool));
292
main(int argc, const char *argv[])
295
int exit_code = EXIT_SUCCESS;
298
/* Initialize the app. */
299
if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS)
302
/* Create our top-level pool. Use a separate mutexless allocator,
303
* given this application is single threaded.
305
pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
307
err = sub_main(&exit_code, argc, argv, pool);
309
/* Flush stdout and report if it fails. It would be flushed on exit anyway
310
but this makes sure that output is not silently lost if it fails. */
311
err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
315
exit_code = EXIT_FAILURE;
316
svn_cmdline_handle_exit_error(err, NULL, "svnversion: ");
295
319
svn_pool_destroy(pool);
297
/* Flush stdout to make sure that the user will see any printing errors. */
298
SVN_INT_ERR(svn_cmdline_fflush(stdout));