~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/svnversion/svnversion.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include "private/svn_opt_private.h"
31
31
#include "private/svn_cmdline_private.h"
32
 
#include "private/svn_subr_private.h"
33
32
 
34
33
#include "svn_private_config.h"
35
34
 
48
47
{
49
48
  svn_error_clear(svn_cmdline_fprintf
50
49
                  (stderr, pool, _("Type 'svnversion --help' for usage.\n")));
51
 
  exit(1);
52
50
}
53
51
 
54
52
 
58
56
  svn_error_clear
59
57
    (svn_cmdline_fprintf
60
58
     (stdout, pool,
61
 
      _("usage: svnversion [OPTIONS] [WC_PATH [TRAIL_URL]]\n\n"
 
59
      _("usage: svnversion [OPTIONS] [WC_PATH [TRAIL_URL]]\n"
 
60
        "Subversion working copy identification tool.\n"
 
61
        "Type 'svnversion --version' to see the program version.\n"
 
62
        "\n"
62
63
        "  Produce a compact version identifier for the working copy path\n"
63
64
        "  WC_PATH.  TRAIL_URL is the trailing portion of the URL used to\n"
64
65
        "  determine if WC_PATH itself is switched (detection of switches\n"
95
96
      ++options;
96
97
    }
97
98
  svn_error_clear(svn_cmdline_fprintf(stdout, pool, "\n"));
98
 
  exit(0);
99
99
}
100
100
 
101
101
 
115
115
}
116
116
 
117
117
/*
 
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.
 
121
 *
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.
121
125
 */
122
 
int
123
 
main(int argc, const char *argv[])
 
126
static svn_error_t *
 
127
sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
124
128
{
125
129
  const char *wc_path, *trail_url;
126
130
  const char *local_abspath;
127
 
  apr_pool_t *pool;
128
131
  svn_wc_revision_status_t *res;
129
132
  svn_boolean_t no_newline = FALSE, committed = FALSE;
130
133
  svn_error_t *err;
144
147
      {0,             0,  0,  0}
145
148
    };
146
149
 
147
 
  /* Initialize the app. */
148
 
  if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS)
149
 
    return EXIT_FAILURE;
150
 
 
151
 
  /* Create our top-level pool.  Use a separate mutexless allocator,
152
 
   * given this application is single threaded.
153
 
   */
154
 
  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
155
 
 
156
150
  /* Check library versions */
157
 
  err = check_lib_versions();
158
 
  if (err)
159
 
    return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
 
151
  SVN_ERR(check_lib_versions());
160
152
 
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"))
164
156
    {
165
 
      err = svn_wc_set_adm_dir("_svn", pool);
166
 
      if (err)
167
 
        return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
 
157
      SVN_ERR(svn_wc_set_adm_dir("_svn", pool));
168
158
    }
169
159
#endif
170
160
 
171
 
  err = svn_cmdline__getopt_init(&os, argc, argv, pool);
172
 
  if (err)
173
 
    return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
 
161
  SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
174
162
 
175
163
  os->interleave = 1;
176
164
  while (1)
181
169
      if (APR_STATUS_IS_EOF(status))
182
170
        break;
183
171
      if (status != APR_SUCCESS)
184
 
        usage(pool);  /* this will exit() */
 
172
        {
 
173
          *exit_code = EXIT_FAILURE;
 
174
          usage(pool);
 
175
          return SVN_NO_ERROR;
 
176
        }
185
177
 
186
178
      switch (opt)
187
179
        {
196
188
          break;
197
189
        case 'h':
198
190
          help(options, pool);
199
 
          break;
 
191
          return SVN_NO_ERROR;
200
192
        case SVNVERSION_OPT_VERSION:
201
193
          is_version = TRUE;
202
194
          break;
203
195
        default:
204
 
          usage(pool);  /* this will exit() */
 
196
          *exit_code = EXIT_FAILURE;
 
197
          usage(pool);
 
198
          return SVN_NO_ERROR;
205
199
        }
206
200
    }
207
201
 
208
202
  if (is_version)
209
203
    {
210
 
      SVN_INT_ERR(version(quiet, pool));
211
 
      exit(0);
 
204
      SVN_ERR(version(quiet, pool));
 
205
      return SVN_NO_ERROR;
212
206
    }
213
207
  if (os->ind > argc || os->ind < argc - 2)
214
 
    usage(pool);  /* this will exit() */
215
 
 
216
 
  SVN_INT_ERR(svn_utf_cstring_to_utf8(&wc_path,
217
 
                                      (os->ind < argc) ? os->argv[os->ind]
218
 
                                                       : ".",
219
 
                                      pool));
220
 
 
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));
 
208
    {
 
209
      *exit_code = EXIT_FAILURE;
 
210
      usage(pool);
 
211
      return SVN_NO_ERROR;
 
212
    }
 
213
 
 
214
  SVN_ERR(svn_utf_cstring_to_utf8(&wc_path,
 
215
                                  (os->ind < argc) ? os->argv[os->ind] : ".",
 
216
                                  pool));
 
217
 
 
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));
224
221
 
225
222
  if (os->ind+1 < argc)
226
 
    SVN_INT_ERR(svn_utf_cstring_to_utf8(&trail_url, os->argv[os->ind+1],
227
 
                                        pool));
 
223
    SVN_ERR(svn_utf_cstring_to_utf8(&trail_url, os->argv[os->ind+1], pool));
228
224
  else
229
225
    trail_url = NULL;
230
226
 
239
235
 
240
236
      svn_error_clear(err);
241
237
 
242
 
      SVN_INT_ERR(svn_io_check_special_path(local_abspath, &kind, &special,
243
 
                                            pool));
 
238
      SVN_ERR(svn_io_check_special_path(local_abspath, &kind, &special, pool));
244
239
 
245
240
      if (special)
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"));
254
249
      else
255
250
        {
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,
261
 
                                                                 pool)));
262
 
          svn_pool_destroy(pool);
263
 
          return EXIT_FAILURE;
 
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,
 
256
                                                             pool)));
 
257
          *exit_code = EXIT_FAILURE;
 
258
          return SVN_NO_ERROR;
264
259
        }
265
 
      svn_pool_destroy(pool);
266
 
      return EXIT_SUCCESS;
 
260
      return SVN_NO_ERROR;
267
261
    }
268
262
 
269
 
  SVN_INT_ERR(err);
 
263
  SVN_ERR(err);
270
264
 
271
265
  if (! SVN_IS_VALID_REVNUM(res->min_rev))
272
266
    {
273
267
      /* Local uncommitted modifications, no revision info was found. */
274
 
      SVN_INT_ERR(svn_cmdline_printf(pool, _("Uncommitted local addition, "
275
 
                                             "copy or move%s"),
276
 
                                             no_newline ? "" : "\n"));
277
 
      svn_pool_destroy(pool);
278
 
      return EXIT_SUCCESS;
 
268
      SVN_ERR(svn_cmdline_printf(pool, _("Uncommitted local addition, "
 
269
                                         "copy or move%s"),
 
270
                                 no_newline ? "" : "\n"));
 
271
      return SVN_NO_ERROR;
279
272
    }
280
273
 
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));
291
284
 
292
285
  if (! no_newline)
293
 
    SVN_INT_ERR(svn_cmdline_fputs("\n", stdout, pool));
 
286
    SVN_ERR(svn_cmdline_fputs("\n", stdout, pool));
 
287
 
 
288
  return SVN_NO_ERROR;
 
289
}
 
290
 
 
291
int
 
292
main(int argc, const char *argv[])
 
293
{
 
294
  apr_pool_t *pool;
 
295
  int exit_code = EXIT_SUCCESS;
 
296
  svn_error_t *err;
 
297
 
 
298
  /* Initialize the app. */
 
299
  if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS)
 
300
    return EXIT_FAILURE;
 
301
 
 
302
  /* Create our top-level pool.  Use a separate mutexless allocator,
 
303
   * given this application is single threaded.
 
304
   */
 
305
  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
 
306
 
 
307
  err = sub_main(&exit_code, argc, argv, pool);
 
308
 
 
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));
 
312
 
 
313
  if (err)
 
314
    {
 
315
      exit_code = EXIT_FAILURE;
 
316
      svn_cmdline_handle_exit_error(err, NULL, "svnversion: ");
 
317
    }
294
318
 
295
319
  svn_pool_destroy(pool);
296
 
 
297
 
  /* Flush stdout to make sure that the user will see any printing errors. */
298
 
  SVN_INT_ERR(svn_cmdline_fflush(stdout));
299
 
 
300
 
  return EXIT_SUCCESS;
 
320
  return exit_code;
301
321
}