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

« back to all changes in this revision

Viewing changes to subversion/svnversion/main.c

  • Committer: Package Import Robot
  • Author(s): James McCoy, Peter Samuelson, James McCoy
  • Date: 2014-01-12 19:48:33 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20140112194833-w3axfwksn296jn5x
Tags: 1.8.5-1
[ Peter Samuelson ]
* New upstream release.  (Closes: #725787) Rediff patches:
  - Remove apr-abi1 (applied upstream), rename apr-abi2 to apr-abi
  - Remove loosen-sqlite-version-check (shouldn't be needed)
  - Remove java-osgi-metadata (applied upstream)
  - svnmucc prompts for a changelog if none is provided. (Closes: #507430)
  - Remove fix-bdb-version-detection, upstream uses "apu-config --dbm-libs"
  - Remove ruby-test-wc (applied upstream)
  - Fix “svn diff -r N file” when file has svn:mime-type set.
    (Closes: #734163)
  - Support specifying an encoding for mod_dav_svn's environment in which
    hooks are run.  (Closes: #601544)
  - Fix ordering of “svnadmin dump” paths with certain APR versions.
    (Closes: #687291)
  - Provide a better error message when authentication fails with an
    svn+ssh:// URL.  (Closes: #273874)
  - Updated Polish translations.  (Closes: #690815)

[ James McCoy ]
* Remove all traces of libneon, replaced by libserf.
* patches/sqlite_3.8.x_workaround: Upstream fix for wc-queries-test test
  failurse.
* Run configure with --with-apache-libexecdir, which allows removing part of
  patches/rpath.
* Re-enable auth-test as upstream has fixed the problem of picking up
  libraries from the environment rather than the build tree.
  (Closes: #654172)
* Point LD_LIBRARY_PATH at the built auth libraries when running the svn
  command during the build.  (Closes: #678224)
* Add a NEWS entry describing how to configure mod_dav_svn to understand
  UTF-8.  (Closes: #566148)
* Remove ancient transitional package, libsvn-ruby.
* Enable compatibility with Sqlite3 versions back to Wheezy.
* Enable hardening flags.  (Closes: #734918)
* patches/build-fixes: Enable verbose build logs.
* Build against the default ruby version.  (Closes: #722393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * ====================================================================
3
 
 *    Licensed to the Apache Software Foundation (ASF) under one
4
 
 *    or more contributor license agreements.  See the NOTICE file
5
 
 *    distributed with this work for additional information
6
 
 *    regarding copyright ownership.  The ASF licenses this file
7
 
 *    to you under the Apache License, Version 2.0 (the
8
 
 *    "License"); you may not use this file except in compliance
9
 
 *    with the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 *    Unless required by applicable law or agreed to in writing,
14
 
 *    software distributed under the License is distributed on an
15
 
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 
 *    KIND, either express or implied.  See the License for the
17
 
 *    specific language governing permissions and limitations
18
 
 *    under the License.
19
 
 * ====================================================================
20
 
 */
21
 
 
22
 
#include "svn_cmdline.h"
23
 
#include "svn_dirent_uri.h"
24
 
#include "svn_pools.h"
25
 
#include "svn_wc.h"
26
 
#include "svn_utf.h"
27
 
#include "svn_opt.h"
28
 
#include "svn_version.h"
29
 
 
30
 
#include "private/svn_opt_private.h"
31
 
 
32
 
#include "svn_private_config.h"
33
 
 
34
 
#define SVNVERSION_OPT_VERSION SVN_OPT_FIRST_LONGOPT_ID
35
 
 
36
 
 
37
 
static svn_error_t *
38
 
version(svn_boolean_t quiet, apr_pool_t *pool)
39
 
{
40
 
  return svn_opt_print_help3(NULL, "svnversion", TRUE, quiet, NULL, NULL,
41
 
                             NULL, NULL, NULL, NULL, pool);
42
 
}
43
 
 
44
 
static void
45
 
usage(apr_pool_t *pool)
46
 
{
47
 
  svn_error_clear(svn_cmdline_fprintf
48
 
                  (stderr, pool, _("Type 'svnversion --help' for usage.\n")));
49
 
  exit(1);
50
 
}
51
 
 
52
 
 
53
 
static void
54
 
help(const apr_getopt_option_t *options, apr_pool_t *pool)
55
 
{
56
 
  svn_error_clear
57
 
    (svn_cmdline_fprintf
58
 
     (stdout, pool,
59
 
      _("usage: svnversion [OPTIONS] [WC_PATH [TRAIL_URL]]\n\n"
60
 
        "  Produce a compact 'version number' for the working copy path\n"
61
 
        "  WC_PATH.  TRAIL_URL is the trailing portion of the URL used to\n"
62
 
        "  determine if WC_PATH itself is switched (detection of switches\n"
63
 
        "  within WC_PATH does not rely on TRAIL_URL).  The version number\n"
64
 
        "  is written to standard output.  For example:\n"
65
 
        "\n"
66
 
        "    $ svnversion . /repos/svn/trunk\n"
67
 
        "    4168\n"
68
 
        "\n"
69
 
        "  The version number will be a single number if the working\n"
70
 
        "  copy is single revision, unmodified, not switched and with\n"
71
 
        "  an URL that matches the TRAIL_URL argument.  If the working\n"
72
 
        "  copy is unusual the version number will be more complex:\n"
73
 
        "\n"
74
 
        "   4123:4168     mixed revision working copy\n"
75
 
        "   4168M         modified working copy\n"
76
 
        "   4123S         switched working copy\n"
77
 
        "   4123P         partial working copy, from a sparse checkout\n"
78
 
        "   4123:4168MS   mixed revision, modified, switched working copy\n"
79
 
        "\n"
80
 
        "  If WC_PATH is an unversioned path, the program will output\n"
81
 
        "  'Unversioned directory' or 'Unversioned file'.  If WC_PATH is\n"
82
 
        "  an added or copied or moved path, the program will output\n"
83
 
        "  'Uncommitted local addition, copy or move'.\n"
84
 
        "\n"
85
 
        "  If invoked without arguments WC_PATH will be the current directory.\n"
86
 
        "\n"
87
 
        "Valid options:\n")));
88
 
  while (options->description)
89
 
    {
90
 
      const char *optstr;
91
 
      svn_opt_format_option(&optstr, options, TRUE, pool);
92
 
      svn_error_clear(svn_cmdline_fprintf(stdout, pool, "  %s\n", optstr));
93
 
      ++options;
94
 
    }
95
 
  svn_error_clear(svn_cmdline_fprintf(stdout, pool, "\n"));
96
 
  exit(0);
97
 
}
98
 
 
99
 
 
100
 
/* Version compatibility check */
101
 
static svn_error_t *
102
 
check_lib_versions(void)
103
 
{
104
 
  static const svn_version_checklist_t checklist[] =
105
 
    {
106
 
      { "svn_subr",   svn_subr_version },
107
 
      { "svn_wc",     svn_wc_version },
108
 
      { NULL, NULL }
109
 
    };
110
 
 
111
 
  SVN_VERSION_DEFINE(my_version);
112
 
  return svn_ver_check_list(&my_version, checklist);
113
 
}
114
 
 
115
 
/*
116
 
 * Why is this not an svn subcommand?  I have this vague idea that it could
117
 
 * be run as part of the build process, with the output embedded in the svn
118
 
 * program.  Obviously we don't want to have to run svn when building svn.
119
 
 */
120
 
int
121
 
main(int argc, const char *argv[])
122
 
{
123
 
  const char *wc_path, *trail_url;
124
 
  const char *local_abspath;
125
 
  apr_allocator_t *allocator;
126
 
  apr_pool_t *pool;
127
 
  svn_wc_revision_status_t *res;
128
 
  svn_boolean_t no_newline = FALSE, committed = FALSE;
129
 
  svn_error_t *err;
130
 
  apr_getopt_t *os;
131
 
  svn_wc_context_t *wc_ctx;
132
 
  svn_boolean_t quiet = FALSE;
133
 
  svn_boolean_t is_version = FALSE;
134
 
  const apr_getopt_option_t options[] =
135
 
    {
136
 
      {"no-newline", 'n', 0, N_("do not output the trailing newline")},
137
 
      {"committed",  'c', 0, N_("last changed rather than current revisions")},
138
 
      {"help", 'h', 0, N_("display this help")},
139
 
      {"version", SVNVERSION_OPT_VERSION, 0,
140
 
       N_("show program version information")},
141
 
      {"quiet",         'q', 0,
142
 
       N_("no progress (only errors) to stderr")},
143
 
      {0,             0,  0,  0}
144
 
    };
145
 
 
146
 
  /* Initialize the app. */
147
 
  if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS)
148
 
    return EXIT_FAILURE;
149
 
 
150
 
  /* Create our top-level pool.  Use a separate mutexless allocator,
151
 
   * given this application is single threaded.
152
 
   */
153
 
  if (apr_allocator_create(&allocator))
154
 
    return EXIT_FAILURE;
155
 
 
156
 
  apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
157
 
 
158
 
  pool = svn_pool_create_ex(NULL, allocator);
159
 
  apr_allocator_owner_set(allocator, pool);
160
 
 
161
 
  /* Check library versions */
162
 
  err = check_lib_versions();
163
 
  if (err)
164
 
    return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
165
 
 
166
 
#if defined(WIN32) || defined(__CYGWIN__)
167
 
  /* Set the working copy administrative directory name. */
168
 
  if (getenv("SVN_ASP_DOT_NET_HACK"))
169
 
    {
170
 
      err = svn_wc_set_adm_dir("_svn", pool);
171
 
      if (err)
172
 
        return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
173
 
    }
174
 
#endif
175
 
 
176
 
  err = svn_cmdline__getopt_init(&os, argc, argv, pool);
177
 
  if (err)
178
 
    return svn_cmdline_handle_exit_error(err, pool, "svnversion: ");
179
 
 
180
 
  os->interleave = 1;
181
 
  while (1)
182
 
    {
183
 
      int opt;
184
 
      const char *arg;
185
 
      apr_status_t status = apr_getopt_long(os, options, &opt, &arg);
186
 
      if (APR_STATUS_IS_EOF(status))
187
 
        break;
188
 
      if (status != APR_SUCCESS)
189
 
        {
190
 
          usage(pool);
191
 
          return EXIT_FAILURE;
192
 
        }
193
 
      switch (opt)
194
 
        {
195
 
        case 'n':
196
 
          no_newline = TRUE;
197
 
          break;
198
 
        case 'c':
199
 
          committed = TRUE;
200
 
          break;
201
 
        case 'q':
202
 
          quiet = TRUE;
203
 
          break;
204
 
        case 'h':
205
 
          help(options, pool);
206
 
          break;
207
 
        case SVNVERSION_OPT_VERSION:
208
 
          is_version = TRUE;
209
 
          break;
210
 
        default:
211
 
          usage(pool);
212
 
          return EXIT_FAILURE;
213
 
        }
214
 
    }
215
 
 
216
 
  if (is_version)
217
 
    {
218
 
      SVN_INT_ERR(version(quiet, pool));
219
 
      exit(0);
220
 
    }
221
 
  if (os->ind > argc || os->ind < argc - 2)
222
 
    {
223
 
      usage(pool);
224
 
      return EXIT_FAILURE;
225
 
    }
226
 
 
227
 
  SVN_INT_ERR(svn_utf_cstring_to_utf8(&wc_path,
228
 
                                      (os->ind < argc) ? os->argv[os->ind] 
229
 
                                                       : ".",
230
 
                                      pool));
231
 
 
232
 
  SVN_INT_ERR(svn_opt__arg_canonicalize_path(&wc_path, wc_path, pool));
233
 
  SVN_INT_ERR(svn_dirent_get_absolute(&local_abspath, wc_path, pool));
234
 
  SVN_INT_ERR(svn_wc_context_create(&wc_ctx, NULL, pool, pool));
235
 
 
236
 
  if (os->ind+1 < argc)
237
 
    SVN_INT_ERR(svn_utf_cstring_to_utf8(&trail_url, os->argv[os->ind+1],
238
 
                                        pool));
239
 
  else
240
 
    trail_url = NULL;
241
 
 
242
 
  err = svn_wc_revision_status2(&res, wc_ctx, local_abspath, trail_url,
243
 
                                committed, NULL, NULL, pool, pool);
244
 
 
245
 
  if (err && (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND
246
 
              || err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY))
247
 
    {
248
 
      svn_node_kind_t kind;
249
 
      svn_boolean_t special;
250
 
 
251
 
      svn_error_clear(err);
252
 
 
253
 
      SVN_INT_ERR(svn_io_check_special_path(local_abspath, &kind, &special,
254
 
                                            pool));
255
 
 
256
 
      if (special)
257
 
        SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned symlink%s"),
258
 
                                       no_newline ? "" : "\n"));
259
 
      else if (kind == svn_node_dir)
260
 
        SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned directory%s"),
261
 
                                       no_newline ? "" : "\n"));
262
 
      else if (kind == svn_node_file)
263
 
        SVN_INT_ERR(svn_cmdline_printf(pool, _("Unversioned file%s"),
264
 
                                       no_newline ? "" : "\n"));
265
 
      else
266
 
        {
267
 
          SVN_INT_ERR(svn_cmdline_fprintf(stderr, pool,
268
 
                                          kind == svn_node_none
269
 
                                           ? _("'%s' doesn't exist\n")
270
 
                                           : _("'%s' is of unknown type\n"),
271
 
                                          svn_dirent_local_style(local_abspath,
272
 
                                                                 pool)));
273
 
          svn_pool_destroy(pool);
274
 
          return EXIT_FAILURE;
275
 
        }
276
 
      svn_pool_destroy(pool);
277
 
      return EXIT_SUCCESS;
278
 
    }
279
 
 
280
 
  SVN_INT_ERR(err);
281
 
 
282
 
  if (! SVN_IS_VALID_REVNUM(res->min_rev))
283
 
    {
284
 
      /* Local uncommitted modifications, no revision info was found. */
285
 
      SVN_INT_ERR(svn_cmdline_printf(pool, _("Uncommitted local addition, "
286
 
                                             "copy or move%s"),
287
 
                                             no_newline ? "" : "\n"));
288
 
      svn_pool_destroy(pool);
289
 
      return EXIT_SUCCESS;
290
 
    }
291
 
 
292
 
  /* Build compact '123[:456]M?S?' string. */
293
 
  SVN_INT_ERR(svn_cmdline_printf(pool, "%ld", res->min_rev));
294
 
  if (res->min_rev != res->max_rev)
295
 
    SVN_INT_ERR(svn_cmdline_printf(pool, ":%ld", res->max_rev));
296
 
  if (res->modified)
297
 
    SVN_INT_ERR(svn_cmdline_fputs("M", stdout, pool));
298
 
  if (res->switched)
299
 
    SVN_INT_ERR(svn_cmdline_fputs("S", stdout, pool));
300
 
  if (res->sparse_checkout)
301
 
    SVN_INT_ERR(svn_cmdline_fputs("P", stdout, pool));
302
 
 
303
 
  if (! no_newline)
304
 
    SVN_INT_ERR(svn_cmdline_fputs("\n", stdout, pool));
305
 
 
306
 
  svn_pool_destroy(pool);
307
 
 
308
 
  /* Flush stdout to make sure that the user will see any printing errors. */
309
 
  SVN_INT_ERR(svn_cmdline_fflush(stdout));
310
 
 
311
 
  return EXIT_SUCCESS;
312
 
}