1/*
2 * svn.c:  Subversion command line client main file.
3 *
4 * ====================================================================
5 *    Licensed to the Apache Software Foundation (ASF) under one
6 *    or more contributor license agreements.  See the NOTICE file
7 *    distributed with this work for additional information
8 *    regarding copyright ownership.  The ASF licenses this file
9 *    to you under the Apache License, Version 2.0 (the
10 *    "License"); you may not use this file except in compliance
11 *    with the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 *    Unless required by applicable law or agreed to in writing,
16 *    software distributed under the License is distributed on an
17 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 *    KIND, either express or implied.  See the License for the
19 *    specific language governing permissions and limitations
20 *    under the License.
21 * ====================================================================
22 */
23
24/* ==================================================================== */
25
26
27
28/*** Includes. ***/
29
30#include <string.h>
31#include <assert.h>
32
33#include <apr_strings.h>
34#include <apr_tables.h>
35#include <apr_general.h>
36#include <apr_signal.h>
37
38#include "svn_cmdline.h"
39#include "svn_pools.h"
40#include "svn_wc.h"
41#include "svn_client.h"
42#include "svn_config.h"
43#include "svn_string.h"
44#include "svn_dirent_uri.h"
45#include "svn_path.h"
46#include "svn_delta.h"
47#include "svn_diff.h"
48#include "svn_error.h"
49#include "svn_io.h"
50#include "svn_opt.h"
51#include "svn_utf.h"
52#include "svn_auth.h"
53#include "svn_hash.h"
54#include "svn_version.h"
55#include "cl.h"
56
57#include "private/svn_opt_private.h"
58#include "private/svn_cmdline_private.h"
59#include "private/svn_subr_private.h"
60
61#include "svn_private_config.h"
62
63
64/*** Option Processing ***/
65
66/* Add an identifier here for long options that don't have a short
67   option. Options that have both long and short options should just
68   use the short option letter as identifier.  */
69typedef enum svn_cl__longopt_t {
70  opt_auth_password = SVN_OPT_FIRST_LONGOPT_ID,
71  opt_auth_username,
72  opt_autoprops,
73  opt_changelist,
74  opt_config_dir,
75  opt_config_options,
76  /* diff options */
77  opt_diff_cmd,
78  opt_internal_diff,
79  opt_no_diff_added,
80  opt_no_diff_deleted,
81  opt_show_copies_as_adds,
82  opt_notice_ancestry,
83  opt_summarize,
84  opt_use_git_diff_format,
85  opt_ignore_properties,
86  opt_properties_only,
87  opt_patch_compatible,
88  /* end of diff options */
89  opt_dry_run,
90  opt_editor_cmd,
91  opt_encoding,
92  opt_force_log,
93  opt_force,
94  opt_keep_changelists,
95  opt_ignore_ancestry,
96  opt_ignore_externals,
97  opt_incremental,
98  opt_merge_cmd,
99  opt_native_eol,
100  opt_new_cmd,
101  opt_no_auth_cache,
102  opt_no_autoprops,
103  opt_no_ignore,
104  opt_no_unlock,
105  opt_non_interactive,
106  opt_force_interactive,
107  opt_old_cmd,
108  opt_record_only,
109  opt_relocate,
110  opt_remove,
111  opt_revprop,
112  opt_stop_on_copy,
113  opt_strict,
114  opt_targets,
115  opt_depth,
116  opt_set_depth,
117  opt_version,
118  opt_xml,
119  opt_keep_local,
120  opt_with_revprop,
121  opt_with_all_revprops,
122  opt_with_no_revprops,
123  opt_parents,
124  opt_accept,
125  opt_show_revs,
126  opt_reintegrate,
127  opt_trust_server_cert,
128  opt_strip,
129  opt_ignore_keywords,
130  opt_reverse_diff,
131  opt_ignore_whitespace,
132  opt_diff,
133  opt_allow_mixed_revisions,
134  opt_include_externals,
135  opt_show_inherited_props,
136  opt_search,
137  opt_search_and
138} svn_cl__longopt_t;
139
140
141/* Option codes and descriptions for the command line client.
142 *
143 * The entire list must be terminated with an entry of nulls.
144 */
145const apr_getopt_option_t svn_cl__options[] =
146{
147  {"force",         opt_force, 0, N_("force operation to run")},
148  {"force-log",     opt_force_log, 0,
149                    N_("force validity of log message source")},
150  {"help",          'h', 0, N_("show help on a subcommand")},
151  {NULL,            '?', 0, N_("show help on a subcommand")},
152  {"message",       'm', 1, N_("specify log message ARG")},
153  {"quiet",         'q', 0, N_("print nothing, or only summary information")},
154  {"recursive",     'R', 0, N_("descend recursively, same as --depth=infinity")},
155  {"non-recursive", 'N', 0, N_("obsolete; try --depth=files or --depth=immediates")},
156  {"change",        'c', 1,
157                    N_("the change made by revision ARG (like -r ARG-1:ARG)\n"
158                       "                             "
159                       "If ARG is negative this is like -r ARG:ARG-1\n"
160                       "                             "
161                       "If ARG is of the form ARG1-ARG2 then this is like\n"
162                       "                             "
163                       "ARG1:ARG2, where ARG1 is inclusive")},
164  {"revision",      'r', 1,
165                    N_("ARG (some commands also take ARG1:ARG2 range)\n"
166                       "                             "
167                       "A revision argument can be one of:\n"
168                       "                             "
169                       "   NUMBER       revision number\n"
170                       "                             "
171                       "   '{' DATE '}' revision at start of the date\n"
172                       "                             "
173                       "   'HEAD'       latest in repository\n"
174                       "                             "
175                       "   'BASE'       base rev of item's working copy\n"
176                       "                             "
177                       "   'COMMITTED'  last commit at or before BASE\n"
178                       "                             "
179                       "   'PREV'       revision just before COMMITTED")},
180  {"file",          'F', 1, N_("read log message from file ARG")},
181  {"incremental",   opt_incremental, 0,
182                    N_("give output suitable for concatenation")},
183  {"encoding",      opt_encoding, 1,
184                    N_("treat value as being in charset encoding ARG")},
185  {"version",       opt_version, 0, N_("show program version information")},
186  {"verbose",       'v', 0, N_("print extra information")},
187  {"show-updates",  'u', 0, N_("display update information")},
188  {"username",      opt_auth_username, 1, N_("specify a username ARG")},
189  {"password",      opt_auth_password, 1, N_("specify a password ARG")},
190  {"extensions",    'x', 1,
191                    N_("Specify differencing options for external diff or\n"
192                       "                             "
193                       "internal diff or blame. Default: '-u'. Options are\n"
194                       "                             "
195                       "separated by spaces. Internal diff and blame take:\n"
196                       "                             "
197                       "  -u, --unified: Show 3 lines of unified context\n"
198                       "                             "
199                       "  -b, --ignore-space-change: Ignore changes in\n"
200                       "                             "
201                       "    amount of white space\n"
202                       "                             "
203                       "  -w, --ignore-all-space: Ignore all white space\n"
204                       "                             "
205                       "  --ignore-eol-style: Ignore changes in EOL style\n"
206                       "                             "
207                       "  -p, --show-c-function: Show C function name")},
208  {"targets",       opt_targets, 1,
209                    N_("pass contents of file ARG as additional args")},
210  {"depth",         opt_depth, 1,
211                    N_("limit operation by depth ARG ('empty', 'files',\n"
212                       "                             "
213                       "'immediates', or 'infinity')")},
214  {"set-depth",     opt_set_depth, 1,
215                    N_("set new working copy depth to ARG ('exclude',\n"
216                       "                             "
217                       "'empty', 'files', 'immediates', or 'infinity')")},
218  {"xml",           opt_xml, 0, N_("output in XML")},
219  {"strict",        opt_strict, 0, N_("use strict semantics")},
220  {"stop-on-copy",  opt_stop_on_copy, 0,
221                    N_("do not cross copies while traversing history")},
222  {"no-ignore",     opt_no_ignore, 0,
223                    N_("disregard default and svn:ignore and\n"
224                       "                             "
225                       "svn:global-ignores property ignores")},
226  {"no-auth-cache", opt_no_auth_cache, 0,
227                    N_("do not cache authentication tokens")},
228  {"trust-server-cert", opt_trust_server_cert, 0,
229                    N_("accept SSL server certificates from unknown\n"
230                       "                             "
231                       "certificate authorities without prompting (but only\n"
232                       "                             "
233                       "with '--non-interactive')") },
234  {"non-interactive", opt_non_interactive, 0,
235                    N_("do no interactive prompting (default is to prompt\n"
236                       "                             "
237                       "only if standard input is a terminal device)")},
238  {"force-interactive", opt_force_interactive, 0,
239                    N_("do interactive prompting even if standard input\n"
240                       "                             "
241                       "is not a terminal device")},
242  {"dry-run",       opt_dry_run, 0,
243                    N_("try operation but make no changes")},
244  {"ignore-ancestry", opt_ignore_ancestry, 0,
245                    N_("disable merge tracking; diff nodes as if related")},
246  {"ignore-externals", opt_ignore_externals, 0,
247                    N_("ignore externals definitions")},
248  {"diff3-cmd",     opt_merge_cmd, 1, N_("use ARG as merge command")},
249  {"editor-cmd",    opt_editor_cmd, 1, N_("use ARG as external editor")},
250  {"record-only",   opt_record_only, 0,
251                    N_("merge only mergeinfo differences")},
252  {"old",           opt_old_cmd, 1, N_("use ARG as the older target")},
253  {"new",           opt_new_cmd, 1, N_("use ARG as the newer target")},
254  {"revprop",       opt_revprop, 0,
255                    N_("operate on a revision property (use with -r)")},
256  {"relocate",      opt_relocate, 0, N_("relocate via URL-rewriting")},
257  {"config-dir",    opt_config_dir, 1,
258                    N_("read user configuration files from directory ARG")},
259  {"config-option", opt_config_options, 1,
260                    N_("set user configuration option in the format:\n"
261                       "                             "
262                       "    FILE:SECTION:OPTION=[VALUE]\n"
263                       "                             "
264                       "For example:\n"
265                       "                             "
266                       "    servers:global:http-library=serf")},
267  {"auto-props",    opt_autoprops, 0, N_("enable automatic properties")},
268  {"no-auto-props", opt_no_autoprops, 0, N_("disable automatic properties")},
269  {"native-eol",    opt_native_eol, 1,
270                    N_("use a different EOL marker than the standard\n"
271                       "                             "
272                       "system marker for files with the svn:eol-style\n"
273                       "                             "
274                       "property set to 'native'.\n"
275                       "                             "
276                       "ARG may be one of 'LF', 'CR', 'CRLF'")},
277  {"limit",         'l', 1, N_("maximum number of log entries")},
278  {"no-unlock",     opt_no_unlock, 0, N_("don't unlock the targets")},
279  {"remove",         opt_remove, 0, N_("remove changelist association")},
280  {"changelist",    opt_changelist, 1,
281                    N_("operate only on members of changelist ARG")},
282  {"keep-changelists", opt_keep_changelists, 0,
283                    N_("don't delete changelists after commit")},
284  {"keep-local",    opt_keep_local, 0, N_("keep path in working copy")},
285  {"with-all-revprops",  opt_with_all_revprops, 0,
286                    N_("retrieve all revision properties")},
287  {"with-no-revprops",  opt_with_no_revprops, 0,
288                    N_("retrieve no revision properties")},
289  {"with-revprop",  opt_with_revprop, 1,
290                    N_("set revision property ARG in new revision\n"
291                       "                             "
292                       "using the name[=value] format")},
293  {"parents",       opt_parents, 0, N_("make intermediate directories")},
294  {"use-merge-history", 'g', 0,
295                    N_("use/display additional information from merge\n"
296                       "                             "
297                       "history")},
298  {"accept",        opt_accept, 1,
299                    N_("specify automatic conflict resolution action\n"
300                       "                             "
301                       "('postpone', 'working', 'base', 'mine-conflict',\n"
302                       "                             "
303                       "'theirs-conflict', 'mine-full', 'theirs-full',\n"
304                       "                             "
305                       "'edit', 'launch')\n"
306                       "                             "
307                       "(shorthand: 'p', 'mc', 'tc', 'mf', 'tf', 'e', 'l')"
308                       )},
309  {"show-revs",     opt_show_revs, 1,
310                    N_("specify which collection of revisions to display\n"
311                       "                             "
312                       "('merged', 'eligible')")},
313  {"reintegrate",   opt_reintegrate, 0,
314                    N_("deprecated")},
315  {"strip",         opt_strip, 1,
316                    N_("number of leading path components to strip from\n"
317                       "                             "
318                       "paths parsed from the patch file. --strip 0\n"
319                       "                             "
320                       "is the default and leaves paths unmodified.\n"
321                       "                             "
322                       "--strip 1 would change the path\n"
323                       "                             "
324                       "'doc/fudge/crunchy.html' to 'fudge/crunchy.html'.\n"
325                       "                             "
326                       "--strip 2 would leave just 'crunchy.html'\n"
327                       "                             "
328                       "The expected component separator is '/' on all\n"
329                       "                             "
330                       "platforms. A leading '/' counts as one component.")},
331  {"ignore-keywords", opt_ignore_keywords, 0,
332                    N_("don't expand keywords")},
333  {"reverse-diff", opt_reverse_diff, 0,
334                    N_("apply the unidiff in reverse")},
335  {"ignore-whitespace", opt_ignore_whitespace, 0,
336                       N_("ignore whitespace during pattern matching")},
337  {"diff", opt_diff, 0, N_("produce diff output")}, /* maps to show_diff */
338  /* diff options */
339  {"diff-cmd",      opt_diff_cmd, 1, N_("use ARG as diff command")},
340  {"internal-diff", opt_internal_diff, 0,
341                       N_("override diff-cmd specified in config file")},
342  {"no-diff-added", opt_no_diff_added, 0,
343                    N_("do not print differences for added files")},
344  {"no-diff-deleted", opt_no_diff_deleted, 0,
345                    N_("do not print differences for deleted files")},
346  {"show-copies-as-adds", opt_show_copies_as_adds, 0,
347                    N_("don't diff copied or moved files with their source")},
348  {"notice-ancestry", opt_notice_ancestry, 0,
349                    N_("diff unrelated nodes as delete and add")},
350  {"summarize",     opt_summarize, 0, N_("show a summary of the results")},
351  {"git", opt_use_git_diff_format, 0,
352                       N_("use git's extended diff format")},
353  {"ignore-properties", opt_ignore_properties, 0,
354                    N_("ignore properties during the operation")},
355  {"properties-only", opt_properties_only, 0,
356                       N_("show only properties during the operation")},
357  {"patch-compatible", opt_patch_compatible, 0,
358                       N_("generate diff suitable for generic third-party\n"
359                       "                             "
360                       "patch tools; currently the same as\n"
361                       "                             "
362                       "--show-copies-as-adds --ignore-properties"
363                       )},
364  /* end of diff options */
365  {"allow-mixed-revisions", opt_allow_mixed_revisions, 0,
366                       N_("Allow operation on mixed-revision working copy.\n"
367                       "                             "
368                       "Use of this option is not recommended!\n"
369                       "                             "
370                       "Please run 'svn update' instead.")},
371  {"include-externals", opt_include_externals, 0,
372                       N_("Also commit file and dir externals reached by\n"
373                       "                             "
374                       "recursion. This does not include externals with a\n"
375                       "                             "
376                       "fixed revision. (See the svn:externals property)")},
377  {"show-inherited-props", opt_show_inherited_props, 0,
378                       N_("retrieve target's inherited properties")},
379  {"search", opt_search, 1,
380                       N_("use ARG as search pattern (glob syntax)")},
381  {"search-and", opt_search_and, 1,
382                       N_("combine ARG with the previous search pattern")},
383
384  /* Long-opt Aliases
385   *
386   * These have NULL desriptions, but an option code that matches some
387   * other option (whose description should probably mention its aliases).
388  */
389
390  {"cl",            opt_changelist, 1, NULL},
391
392  {0,               0, 0, 0},
393};
394
395
396
397/*** Command dispatch. ***/
398
399/* Our array of available subcommands.
400 *
401 * The entire list must be terminated with an entry of nulls.
402 *
403 * In most of the help text "PATH" is used where a working copy path is
404 * required, "URL" where a repository URL is required and "TARGET" when
405 * either a path or a url can be used.  Hmm, should this be part of the
406 * help text?
407 */
408
409/* Options that apply to all commands.  (While not every command may
410   currently require authentication or be interactive, allowing every
411   command to take these arguments allows scripts to just pass them
412   willy-nilly to every invocation of 'svn') . */
413const int svn_cl__global_options[] =
414{ opt_auth_username, opt_auth_password, opt_no_auth_cache, opt_non_interactive,
415  opt_force_interactive, opt_trust_server_cert, opt_config_dir,
416  opt_config_options, 0
417};
418
419/* Options for giving a log message.  (Some of these also have other uses.)
420 */
421#define SVN_CL__LOG_MSG_OPTIONS 'm', 'F', \
422                                opt_force_log, \
423                                opt_editor_cmd, \
424                                opt_encoding, \
425                                opt_with_revprop
426
427const svn_opt_subcommand_desc2_t svn_cl__cmd_table[] =
428{
429  { "add", svn_cl__add, {0}, N_
430    ("Put files and directories under version control, scheduling\n"
431     "them for addition to repository.  They will be added in next commit.\n"
432     "usage: add PATH...\n"),
433    {opt_targets, 'N', opt_depth, 'q', opt_force, opt_no_ignore, opt_autoprops,
434     opt_no_autoprops, opt_parents },
435     {{opt_parents, N_("add intermediate parents")}} },
436
437  { "blame", svn_cl__blame, {"praise", "annotate", "ann"}, N_
438    ("Output the content of specified files or\n"
439     "URLs with revision and author information in-line.\n"
440     "usage: blame TARGET[@REV]...\n"
441     "\n"
442     "  If specified, REV determines in which revision the target is first\n"
443     "  looked up.\n"),
444    {'r', 'v', 'g', opt_incremental, opt_xml, 'x', opt_force} },
445
446  { "cat", svn_cl__cat, {0}, N_
447    ("Output the content of specified files or URLs.\n"
448     "usage: cat TARGET[@REV]...\n"
449     "\n"
450     "  If specified, REV determines in which revision the target is first\n"
451     "  looked up.\n"),
452    {'r'} },
453
454  { "changelist", svn_cl__changelist, {"cl"}, N_
455    ("Associate (or dissociate) changelist CLNAME with the named files.\n"
456     "usage: 1. changelist CLNAME PATH...\n"
457     "       2. changelist --remove PATH...\n"),
458    { 'q', 'R', opt_depth, opt_remove, opt_targets, opt_changelist} },
459
460  { "checkout", svn_cl__checkout, {"co"}, N_
461    ("Check out a working copy from a repository.\n"
462     "usage: checkout URL[@REV]... [PATH]\n"
463     "\n"
464     "  If specified, REV determines in which revision the URL is first\n"
465     "  looked up.\n"
466     "\n"
467     "  If PATH is omitted, the basename of the URL will be used as\n"
468     "  the destination. If multiple URLs are given each will be checked\n"
469     "  out into a sub-directory of PATH, with the name of the sub-directory\n"
470     "  being the basename of the URL.\n"
471     "\n"
472     "  If --force is used, unversioned obstructing paths in the working\n"
473     "  copy destination do not automatically cause the check out to fail.\n"
474     "  If the obstructing path is the same type (file or directory) as the\n"
475     "  corresponding path in the repository it becomes versioned but its\n"
476     "  contents are left 'as-is' in the working copy.  This means that an\n"
477     "  obstructing directory's unversioned children may also obstruct and\n"
478     "  become versioned.  For files, any content differences between the\n"
479     "  obstruction and the repository are treated like a local modification\n"
480     "  to the working copy.  All properties from the repository are applied\n"
481     "  to the obstructing path.\n"
482     "\n"
483     "  See also 'svn help update' for a list of possible characters\n"
484     "  reporting the action taken.\n"),
485    {'r', 'q', 'N', opt_depth, opt_force, opt_ignore_externals} },
486
487  { "cleanup", svn_cl__cleanup, {0}, N_
488    ("Recursively clean up the working copy, removing write locks, resuming\n"
489     "unfinished operations, etc.\n"
490     "usage: cleanup [WCPATH...]\n"
491     "\n"
492     "  Finish any unfinished business in the working copy at WCPATH, and remove\n"
493     "  write locks (shown as 'L' by the 'svn status' command) from the working\n"
494     "  copy. Usually, this is only necessary if a Subversion client has crashed\n"
495     "  while using the working copy, leaving it in an unusable state.\n"
496     "\n"
497     "  WARNING: There is no mechanism that will protect write locks still\n"
498     "           being used by other Subversion clients. Running this command\n"
499     "           while another client is using the working copy can corrupt\n"
500     "           the working copy beyond repair!\n"),
501    {opt_merge_cmd} },
502
503  { "commit", svn_cl__commit, {"ci"},
504    N_("Send changes from your working copy to the repository.\n"
505       "usage: commit [PATH...]\n"
506       "\n"
507       "  A log message must be provided, but it can be empty.  If it is not\n"
508       "  given by a --message or --file option, an editor will be started.\n"
509       "  If any targets are (or contain) locked items, those will be\n"
510       "  unlocked after a successful commit.\n"),
511    {'q', 'N', opt_depth, opt_targets, opt_no_unlock, SVN_CL__LOG_MSG_OPTIONS,
512     opt_changelist, opt_keep_changelists, opt_include_externals} },
513
514  { "copy", svn_cl__copy, {"cp"}, N_
515    ("Copy files and directories in a working copy or repository.\n"
516     "usage: copy SRC[@REV]... DST\n"
517     "\n"
518     "  SRC and DST can each be either a working copy (WC) path or URL:\n"
519     "    WC  -> WC:   copy and schedule for addition (with history)\n"
520     "    WC  -> URL:  immediately commit a copy of WC to URL\n"
521     "    URL -> WC:   check out URL into WC, schedule for addition\n"
522     "    URL -> URL:  complete server-side copy;  used to branch and tag\n"
523     "  All the SRCs must be of the same type. When copying multiple sources,\n"
524     "  they will be added as children of DST, which must be a directory.\n"
525     "\n"
526     "  WARNING: For compatibility with previous versions of Subversion,\n"
527     "  copies performed using two working copy paths (WC -> WC) will not\n"
528     "  contact the repository.  As such, they may not, by default, be able\n"
529     "  to propagate merge tracking information from the source of the copy\n"
530     "  to the destination.\n"),
531    {'r', 'q', opt_ignore_externals, opt_parents, SVN_CL__LOG_MSG_OPTIONS} },
532
533  { "delete", svn_cl__delete, {"del", "remove", "rm"}, N_
534    ("Remove files and directories from version control.\n"
535     "usage: 1. delete PATH...\n"
536     "       2. delete URL...\n"
537     "\n"
538     "  1. Each item specified by a PATH is scheduled for deletion upon\n"
539     "    the next commit.  Files, and directories that have not been\n"
540     "    committed, are immediately removed from the working copy\n"
541     "    unless the --keep-local option is given.\n"
542     "    PATHs that are, or contain, unversioned or modified items will\n"
543     "    not be removed unless the --force or --keep-local option is given.\n"
544     "\n"
545     "  2. Each item specified by a URL is deleted from the repository\n"
546     "    via an immediate commit.\n"),
547    {opt_force, 'q', opt_targets, SVN_CL__LOG_MSG_OPTIONS, opt_keep_local} },
548
549  { "diff", svn_cl__diff, {"di"}, N_
550    ("Display local changes or differences between two revisions or paths.\n"
551     "usage: 1. diff\n"
552     "       2. diff [-c M | -r N[:M]] [TARGET[@REV]...]\n"
553     "       3. diff [-r N[:M]] --old=OLD-TGT[@OLDREV] [--new=NEW-TGT[@NEWREV]] \\\n"
554     "               [PATH...]\n"
555     "       4. diff OLD-URL[@OLDREV] NEW-URL[@NEWREV]\n"
556     "       5. diff OLD-URL[@OLDREV] NEW-PATH[@NEWREV]\n"
557     "       6. diff OLD-PATH[@OLDREV] NEW-URL[@NEWREV]\n"
558     "\n"
559     "  1. Use just 'svn diff' to display local modifications in a working copy.\n"
560     "\n"
561     "  2. Display the changes made to TARGETs as they are seen in REV between\n"
562     "     two revisions.  TARGETs may be all working copy paths or all URLs.\n"
563     "     If TARGETs are working copy paths, N defaults to BASE and M to the\n"
564     "     working copy; if URLs, N must be specified and M defaults to HEAD.\n"
565     "     The '-c M' option is equivalent to '-r N:M' where N = M-1.\n"
566     "     Using '-c -M' does the reverse: '-r M:N' where N = M-1.\n"
567     "\n"
568     "  3. Display the differences between OLD-TGT as it was seen in OLDREV and\n"
569     "     NEW-TGT as it was seen in NEWREV.  PATHs, if given, are relative to\n"
570     "     OLD-TGT and NEW-TGT and restrict the output to differences for those\n"
571     "     paths.  OLD-TGT and NEW-TGT may be working copy paths or URL[@REV].\n"
572     "     NEW-TGT defaults to OLD-TGT if not specified.  -r N makes OLDREV default\n"
573     "     to N, -r N:M makes OLDREV default to N and NEWREV default to M.\n"
574     "     If OLDREV or NEWREV are not specified, they default to WORKING for\n"
575     "     working copy targets and to HEAD for URL targets.\n"
576     "\n"
577     "     Either or both OLD-TGT and NEW-TGT may also be paths to unversioned\n"
578     "     targets. Revisions cannot be specified for unversioned targets.\n"
579     "     Both targets must be of the same node kind (file or directory).\n"
580     "     Diffing unversioned targets against URL targets is not supported.\n"
581     "\n"
582     "  4. Shorthand for 'svn diff --old=OLD-URL[@OLDREV] --new=NEW-URL[@NEWREV]'\n"
583     "  5. Shorthand for 'svn diff --old=OLD-URL[@OLDREV] --new=NEW-PATH[@NEWREV]'\n"
584     "  6. Shorthand for 'svn diff --old=OLD-PATH[@OLDREV] --new=NEW-URL[@NEWREV]'\n"),
585    {'r', 'c', opt_old_cmd, opt_new_cmd, 'N', opt_depth, opt_diff_cmd,
586     opt_internal_diff, 'x', opt_no_diff_added, opt_no_diff_deleted,
587     opt_ignore_properties, opt_properties_only,
588     opt_show_copies_as_adds, opt_notice_ancestry, opt_summarize, opt_changelist,
589     opt_force, opt_xml, opt_use_git_diff_format, opt_patch_compatible} },
590  { "export", svn_cl__export, {0}, N_
591    ("Create an unversioned copy of a tree.\n"
592     "usage: 1. export [-r REV] URL[@PEGREV] [PATH]\n"
593     "       2. export [-r REV] PATH1[@PEGREV] [PATH2]\n"
594     "\n"
595     "  1. Exports a clean directory tree from the repository specified by\n"
596     "     URL, at revision REV if it is given, otherwise at HEAD, into\n"
597     "     PATH. If PATH is omitted, the last component of the URL is used\n"
598     "     for the local directory name.\n"
599     "\n"
600     "  2. Exports a clean directory tree from the working copy specified by\n"
601     "     PATH1, at revision REV if it is given, otherwise at WORKING, into\n"
602     "     PATH2.  If PATH2 is omitted, the last component of the PATH1 is used\n"
603     "     for the local directory name. If REV is not specified, all local\n"
604     "     changes will be preserved.  Files not under version control will\n"
605     "     not be copied.\n"
606     "\n"
607     "  If specified, PEGREV determines in which revision the target is first\n"
608     "  looked up.\n"),
609    {'r', 'q', 'N', opt_depth, opt_force, opt_native_eol, opt_ignore_externals,
610     opt_ignore_keywords} },
611
612  { "help", svn_cl__help, {"?", "h"}, N_
613    ("Describe the usage of this program or its subcommands.\n"
614     "usage: help [SUBCOMMAND...]\n"),
615    {0} },
616  /* This command is also invoked if we see option "--help", "-h" or "-?". */
617
618  { "import", svn_cl__import, {0}, N_
619    ("Commit an unversioned file or tree into the repository.\n"
620     "usage: import [PATH] URL\n"
621     "\n"
622     "  Recursively commit a copy of PATH to URL.\n"
623     "  If PATH is omitted '.' is assumed.\n"
624     "  Parent directories are created as necessary in the repository.\n"
625     "  If PATH is a directory, the contents of the directory are added\n"
626     "  directly under URL.\n"
627     "  Unversionable items such as device files and pipes are ignored\n"
628     "  if --force is specified.\n"),
629    {'q', 'N', opt_depth, opt_autoprops, opt_force, opt_no_autoprops,
630     SVN_CL__LOG_MSG_OPTIONS, opt_no_ignore} },
631
632  { "info", svn_cl__info, {0}, N_
633    ("Display information about a local or remote item.\n"
634     "usage: info [TARGET[@REV]...]\n"
635     "\n"
636     "  Print information about each TARGET (default: '.').\n"
637     "  TARGET may be either a working-copy path or URL.  If specified, REV\n"
638     "  determines in which revision the target is first looked up.\n"),
639    {'r', 'R', opt_depth, opt_targets, opt_incremental, opt_xml, opt_changelist}
640  },
641
642  { "list", svn_cl__list, {"ls"}, N_
643    ("List directory entries in the repository.\n"
644     "usage: list [TARGET[@REV]...]\n"
645     "\n"
646     "  List each TARGET file and the contents of each TARGET directory as\n"
647     "  they exist in the repository.  If TARGET is a working copy path, the\n"
648     "  corresponding repository URL will be used. If specified, REV determines\n"
649     "  in which revision the target is first looked up.\n"
650     "\n"
651     "  The default TARGET is '.', meaning the repository URL of the current\n"
652     "  working directory.\n"
653     "\n"
654     "  With --verbose, the following fields will be shown for each item:\n"
655     "\n"
656     "    Revision number of the last commit\n"
657     "    Author of the last commit\n"
658     "    If locked, the letter 'O'.  (Use 'svn info URL' to see details)\n"
659     "    Size (in bytes)\n"
660     "    Date and time of the last commit\n"),
661    {'r', 'v', 'R', opt_depth, opt_incremental, opt_xml,
662     opt_include_externals },
663    {{opt_include_externals, N_("include externals definitions")}} },
664
665  { "lock", svn_cl__lock, {0}, N_
666    ("Lock working copy paths or URLs in the repository, so that\n"
667     "no other user can commit changes to them.\n"
668     "usage: lock TARGET...\n"
669     "\n"
670     "  Use --force to steal the lock from another user or working copy.\n"),
671    { opt_targets, 'm', 'F', opt_force_log, opt_encoding, opt_force },
672    {{'F', N_("read lock comment from file ARG")},
673     {'m', N_("specify lock comment ARG")},
674     {opt_force_log, N_("force validity of lock comment source")}} },
675
676  { "log", svn_cl__log, {0}, N_
677    ("Show the log messages for a set of revision(s) and/or path(s).\n"
678     "usage: 1. log [PATH][@REV]\n"
679     "       2. log URL[@REV] [PATH...]\n"
680     "\n"
681     "  1. Print the log messages for the URL corresponding to PATH\n"
682     "     (default: '.'). If specified, REV is the revision in which the\n"
683     "     URL is first looked up, and the default revision range is REV:1.\n"
684     "     If REV is not specified, the default revision range is BASE:1,\n"
685     "     since the URL might not exist in the HEAD revision.\n"
686     "\n"
687     "  2. Print the log messages for the PATHs (default: '.') under URL.\n"
688     "     If specified, REV is the revision in which the URL is first\n"
689     "     looked up, and the default revision range is REV:1; otherwise,\n"
690     "     the URL is looked up in HEAD, and the default revision range is\n"
691     "     HEAD:1.\n"
692     "\n"
693     "  Multiple '-c' or '-r' options may be specified (but not a\n"
694     "  combination of '-c' and '-r' options), and mixing of forward and\n"
695     "  reverse ranges is allowed.\n"
696     "\n"
697     "  With -v, also print all affected paths with each log message.\n"
698     "  With -q, don't print the log message body itself (note that this is\n"
699     "  compatible with -v).\n"
700     "\n"
701     "  Each log message is printed just once, even if more than one of the\n"
702     "  affected paths for that revision were explicitly requested.  Logs\n"
703     "  follow copy history by default.  Use --stop-on-copy to disable this\n"
704     "  behavior, which can be useful for determining branchpoints.\n"
705     "\n"
706     "  The --depth option is only valid in combination with the --diff option\n"
707     "  and limits the scope of the displayed diff to the specified depth.\n"
708     "\n"
709     "  If the --search option is used, log messages are displayed only if the\n"
710     "  provided search pattern matches any of the author, date, log message\n"
711     "  text (unless --quiet is used), or, if the --verbose option is also\n"
712     "  provided, a changed path.\n"
713     "  The search pattern may include \"glob syntax\" wildcards:\n"
714     "      ?      matches any single character\n"
715     "      *      matches a sequence of arbitrary characters\n"
716     "      [abc]  matches any of the characters listed inside the brackets\n"
717     "  If multiple --search options are provided, a log message is shown if\n"
718     "  it matches any of the provided search patterns. If the --search-and\n"
719     "  option is used, that option's argument is combined with the pattern\n"
720     "  from the previous --search or --search-and option, and a log message\n"
721     "  is shown only if it matches the combined search pattern.\n"
722     "  If --limit is used in combination with --search, --limit restricts the\n"
723     "  number of log messages searched, rather than restricting the output\n"
724     "  to a particular number of matching log messages.\n"
725     "\n"
726     "  Examples:\n"
727     "\n"
728     "    Show the latest 5 log messages for the current working copy\n"
729     "    directory and display paths changed in each commit:\n"
730     "      svn log -l 5 -v\n"
731     "\n"
732     "    Show the log for bar.c as of revision 42:\n"
733     "      svn log bar.c@42\n"
734     "\n"
735     "    Show log messages and diffs for each commit to foo.c:\n"
736     "      svn log --diff http://www.example.com/repo/project/foo.c\n"
737     "    (Because the above command uses a full URL it does not require\n"
738     "     a working copy.)\n"
739     "\n"
740     "    Show log messages for the children foo.c and bar.c of the directory\n"
741     "    '/trunk' as it appeared in revision 50, using the ^/ URL shortcut:\n"
742     "      svn log ^/trunk@50 foo.c bar.c\n"
743     "\n"
744     "    Show the log messages for any incoming changes to foo.c during the\n"
745     "    next 'svn update':\n"
746     "      svn log -r BASE:HEAD foo.c\n"
747     "\n"
748     "    Show the log message for the revision in which /branches/foo\n"
749     "    was created:\n"
750     "      svn log --stop-on-copy --limit 1 -r0:HEAD ^/branches/foo\n"),
751    {'r', 'q', 'v', 'g', 'c', opt_targets, opt_stop_on_copy, opt_incremental,
752     opt_xml, 'l', opt_with_all_revprops, opt_with_no_revprops, opt_with_revprop,
753     opt_depth, opt_diff, opt_diff_cmd, opt_internal_diff, 'x', opt_search,
754     opt_search_and, },
755    {{opt_with_revprop, N_("retrieve revision property ARG")},
756     {'c', N_("the change made in revision ARG")}} },
757
758  { "merge", svn_cl__merge, {0}, N_
759    ( /* For this large section, let's keep it unindented for easier
760       * viewing/editing. It has been vim-treated with a textwidth=75 and 'gw'
761       * (with quotes and newlines removed). */
762"Merge changes into a working copy.\n"
763"usage: 1. merge SOURCE[@REV] [TARGET_WCPATH]\n"
764"          (the 'complete' merge)\n"
765"       2. merge [-c M[,N...] | -r N:M ...] SOURCE[@REV] [TARGET_WCPATH]\n"
766"          (the 'cherry-pick' merge)\n"
767"       3. merge SOURCE1[@REV1] SOURCE2[@REV2] [TARGET_WCPATH]\n"
768"          (the '2-URL' merge)\n"
769"\n"
770"  1. This form, with one source path and no revision range, is called\n"
771"     a 'complete' merge:\n"
772"\n"
773"       svn merge SOURCE[@REV] [TARGET_WCPATH]\n"
774"\n"
775"     The complete merge is used for the 'sync' and 'reintegrate' merges\n"
776"     in the 'feature branch' pattern described below. It finds all the\n"
777"     changes on the source branch that have not already been merged to the\n"
778"     target branch, and merges them into the working copy. Merge tracking\n"
779"     is used to know which changes have already been merged.\n"
780"\n"
781"     SOURCE specifies the branch from where the changes will be pulled, and\n"
782"     TARGET_WCPATH specifies a working copy of the target branch to which\n"
783"     the changes will be applied. Normally SOURCE and TARGET_WCPATH should\n"
784"     each correspond to the root of a branch. (If you want to merge only a\n"
785"     subtree, then the subtree path must be included in both SOURCE and\n"
786"     TARGET_WCPATH; this is discouraged, to avoid subtree mergeinfo.)\n"
787"\n"
788"     SOURCE is usually a URL. The optional '@REV' specifies both the peg\n"
789"     revision of the URL and the latest revision that will be considered\n"
790"     for merging; if REV is not specified, the HEAD revision is assumed. If\n"
791"     SOURCE is a working copy path, the corresponding URL of the path is\n"
792"     used, and the default value of 'REV' is the base revision (usually the\n"
793"     revision last updated to).\n"
794"\n"
795"     TARGET_WCPATH is a working copy path; if omitted, '.' is generally\n"
796"     assumed. There are some special cases:\n"
797"\n"
798"       - If SOURCE is a URL:\n"
799"\n"
800"           - If the basename of the URL and the basename of '.' are the\n"
801"             same, then the differences are applied to '.'. Otherwise,\n"
802"             if a file with the same basename as that of the URL is found\n"
803"             within '.', then the differences are applied to that file.\n"
804"             In all other cases, the target defaults to '.'.\n"
805"\n"
806"       - If SOURCE is a working copy path:\n"
807"\n"
808"           - If the source is a file, then differences are applied to that\n"
809"             file (useful for reverse-merging earlier changes). Otherwise,\n"
810"             if the source is a directory, then the target defaults to '.'.\n"
811"\n"
812"     In normal usage the working copy should be up to date, at a single\n"
813"     revision, with no local modifications and no switched subtrees.\n"
814"\n"
815"       - The 'Feature Branch' Merging Pattern -\n"
816"\n"
817"     In this commonly used work flow, known also as the 'development\n"
818"     branch' pattern, a developer creates a branch and commits a series of\n"
819"     changes that implement a new feature. The developer periodically\n"
820"     merges all the latest changes from the parent branch so as to keep the\n"
821"     development branch up to date with those changes. When the feature is\n"
822"     complete, the developer performs a merge from the feature branch to\n"
823"     the parent branch to re-integrate the changes.\n"
824"\n"
825"         parent --+----------o------o-o-------------o--\n"
826"                   \\            \\           \\      /\n"
827"                    \\          merge      merge  merge\n"
828"                     \\            \\           \\  /\n"
829"         feature      +--o-o-------o----o-o----o-------\n"
830"\n"
831"     A merge from the parent branch to the feature branch is called a\n"
832"     'sync' or 'catch-up' merge, and a merge from the feature branch to the\n"
833"     parent branch is called a 'reintegrate' merge.\n"
834"\n"
835"       - Sync Merge Example -\n"
836"                                 ............\n"
837"                                .            .\n"
838"         trunk  --+------------L--------------R------\n"
839"                   \\                           \\\n"
840"                    \\                          |\n"
841"                     \\                         v\n"
842"         feature      +------------------------o-----\n"
843"                             r100            r200\n"
844"\n"
845"     Subversion will locate all the changes on 'trunk' that have not yet\n"
846"     been merged into the 'feature' branch. In this case that is a single\n"
847"     range, r100:200. In the diagram above, L marks the left side (trunk@100)\n"
848"     and R marks the right side (trunk@200) of the merge source. The\n"
849"     difference between L and R will be applied to the target working copy\n"
850"     path. In this case, the working copy is a clean checkout of the entire\n"
851"     'feature' branch.\n"
852"\n"
853"     To perform this sync merge, have a clean working copy of the feature\n"
854"     branch and run the following command in its top-level directory:\n"
855"\n"
856"         svn merge ^/trunk\n"
857"\n"
858"     Note that the merge is now only in your local working copy and still\n"
859"     needs to be committed to the repository so that it can be seen by\n"
860"     others. You can review the changes and you may have to resolve\n"
861"     conflicts before you commit the merge.\n"
862"\n"
863"       - Reintegrate Merge Example -\n"
864"\n"
865"     The feature branch was last synced with trunk up to revision X. So the\n"
866"     difference between trunk@X and feature@HEAD contains the complete set\n"
867"     of changes that implement the feature, and no other changes. These\n"
868"     changes are applied to trunk.\n"
869"\n"
870"                    rW                   rX\n"
871"         trunk ------+--------------------L------------------o\n"
872"                      \\                    .                 ^\n"
873"                       \\                    .............   /\n"
874"                        \\                                . /\n"
875"         feature         +--------------------------------R\n"
876"\n"
877"     In the diagram above, L marks the left side (trunk@X) and R marks the\n"
878"     right side (feature@HEAD) of the merge. The difference between the\n"
879"     left and right side is merged into trunk, the target.\n"
880"\n"
881"     To perform the merge, have a clean working copy of trunk and run the\n"
882"     following command in its top-level directory:\n"
883"\n"
884"         svn merge ^/feature\n"
885"\n"
886"     To prevent unnecessary merge conflicts, a reintegrate merge requires\n"
887"     that TARGET_WCPATH is not a mixed-revision working copy, has no local\n"
888"     modifications, and has no switched subtrees.\n"
889"\n"
890"     A reintegrate merge also requires that the source branch is coherently\n"
891"     synced with the target -- in the above example, this means that all\n"
892"     revisions between the branch point W and the last merged revision X\n"
893"     are merged to the feature branch, so that there are no unmerged\n"
894"     revisions in-between.\n"
895"\n"
896"\n"
897"  2. This form is called a 'cherry-pick' merge:\n"
898"\n"
899"       svn merge [-c M[,N...] | -r N:M ...] SOURCE[@REV] [TARGET_WCPATH]\n"
900"\n"
901"     A cherry-pick merge is used to merge specific revisions (or revision\n"
902"     ranges) from one branch to another. By default, this uses merge\n"
903"     tracking to automatically skip any revisions that have already been\n"
904"     merged to the target; you can use the --ignore-ancestry option to\n"
905"     disable such skipping.\n"
906"\n"
907"     SOURCE is usually a URL. The optional '@REV' specifies only the peg\n"
908"     revision of the URL and does not affect the merge range; if REV is not\n"
909"     specified, the HEAD revision is assumed. If SOURCE is a working copy\n"
910"     path, the corresponding URL of the path is used, and the default value\n"
911"     of 'REV' is the base revision (usually the revision last updated to).\n"
912"\n"
913"     TARGET_WCPATH is a working copy path; if omitted, '.' is generally\n"
914"     assumed. The special cases noted above in the 'complete' merge form\n"
915"     also apply here.\n"
916"\n"
917"     The revision ranges to be merged are specified by the '-r' and/or '-c'\n"
918"     options. '-r N:M' refers to the difference in the history of the\n"
919"     source branch between revisions N and M. You can use '-c M' to merge\n"
920"     single revisions: '-c M' is equivalent to '-r <M-1>:M'. Each such\n"
921"     difference is applied to TARGET_WCPATH.\n"
922"\n"
923"     If the mergeinfo in TARGET_WCPATH indicates that revisions within the\n"
924"     range were already merged, changes made in those revisions are not\n"
925"     merged again. If needed, the range is broken into multiple sub-ranges,\n"
926"     and each sub-range is merged separately.\n"
927"\n"
928"     A 'reverse range' can be used to undo changes. For example, when\n"
929"     source and target refer to the same branch, a previously committed\n"
930"     revision can be 'undone'. In a reverse range, N is greater than M in\n"
931"     '-r N:M', or the '-c' option is used with a negative number: '-c -M'\n"
932"     is equivalent to '-r M:<M-1>'. Undoing changes like this is also known\n"
933"     as performing a 'reverse merge'.\n"
934"\n"
935"     Multiple '-c' and/or '-r' options may be specified and mixing of\n"
936"     forward and reverse ranges is allowed.\n"
937"\n"
938"       - Cherry-pick Merge Example -\n"
939"\n"
940"     A bug has been fixed on trunk in revision 50. This fix needs to\n"
941"     be merged from trunk onto the release branch.\n"
942"\n"
943"            1.x-release  +-----------------------o-----\n"
944"                        /                        ^\n"
945"                       /                         |\n"
946"                      /                          |\n"
947"         trunk ------+--------------------------LR-----\n"
948"                                                r50\n"
949"\n"
950"     In the above diagram, L marks the left side (trunk@49) and R marks the\n"
951"     right side (trunk@50) of the merge. The difference between the left\n"
952"     and right side is applied to the target working copy path.\n"
953"\n"
954"     Note that the difference between revision 49 and 50 is exactly those\n"
955"     changes that were committed in revision 50, not including changes\n"
956"     committed in revision 49.\n"
957"\n"
958"     To perform the merge, have a clean working copy of the release branch\n"
959"     and run the following command in its top-level directory; remember\n"
960"     that the default target is '.':\n"
961"\n"
962"         svn merge -c50 ^/trunk\n"
963"\n"
964"     You can also cherry-pick several revisions and/or revision ranges:\n"
965"\n"
966"         svn merge -c50,54,60 -r65:68 ^/trunk\n"
967"\n"
968"\n"
969"  3. This form is called a '2-URL merge':\n"
970"\n"
971"       svn merge SOURCE1[@REV1] SOURCE2[@REV2] [TARGET_WCPATH]\n"
972"\n"
973"     You should use this merge variant only if the other variants do not\n"
974"     apply to your situation, as this variant can be quite complex to\n"
975"     master.\n"
976"\n"
977"     Two source URLs are specified, identifying two trees on the same\n"
978"     branch or on different branches. The trees are compared and the\n"
979"     difference from SOURCE1@REV1 to SOURCE2@REV2 is applied to the\n"
980"     working copy of the target branch at TARGET_WCPATH. The target\n"
981"     branch may be the same as one or both sources, or different again.\n"
982"     The three branches involved can be completely unrelated.\n"
983"\n"
984"     TARGET_WCPATH is a working copy path; if omitted, '.' is generally\n"
985"     assumed. The special cases noted above in the 'complete' merge form\n"
986"     also apply here.\n"
987"\n"
988"     SOURCE1 and/or SOURCE2 can also be specified as a working copy path,\n"
989"     in which case the merge source URL is derived from the working copy.\n"
990"\n"
991"       - 2-URL Merge Example -\n"
992"\n"
993"     Two features have been developed on separate branches called 'foo' and\n"
994"     'bar'. It has since become clear that 'bar' should be combined with\n"
995"     the 'foo' branch for further development before reintegration.\n"
996"\n"
997"     Although both feature branches originate from trunk, they are not\n"
998"     directly related -- one is not a direct copy of the other. A 2-URL\n"
999"     merge is necessary.\n"
1000"\n"
1001"     The 'bar' branch has been synced with trunk up to revision 500.\n"
1002"     (If this revision number is not known, it can be located using the\n"
1003"     'svn log' and/or 'svn mergeinfo' commands.)\n"
1004"     The difference between trunk@500 and bar@HEAD contains the complete\n"
1005"     set of changes related to feature 'bar', and no other changes. These\n"
1006"     changes are applied to the 'foo' branch.\n"
1007"\n"
1008"                           foo  +-----------------------------------o\n"
1009"                               /                                    ^\n"
1010"                              /                                    /\n"
1011"                             /              r500                  /\n"
1012"         trunk ------+------+-----------------L--------->        /\n"
1013"                      \\                        .                /\n"
1014"                       \\                        ............   /\n"
1015"                        \\                                   . /\n"
1016"                    bar  +-----------------------------------R\n"
1017"\n"
1018"     In the diagram above, L marks the left side (trunk@500) and R marks\n"
1019"     the right side (bar@HEAD) of the merge. The difference between the\n"
1020"     left and right side is applied to the target working copy path, in\n"
1021"     this case a working copy of the 'foo' branch.\n"
1022"\n"
1023"     To perform the merge, have a clean working copy of the 'foo' branch\n"
1024"     and run the following command in its top-level directory:\n"
1025"\n"
1026"         svn merge ^/trunk@500 ^/bar\n"
1027"\n"
1028"     The exact changes applied by a 2-URL merge can be previewed with svn's\n"
1029"     diff command, which is a good idea to verify if you do not have the\n"
1030"     luxury of a clean working copy to merge to. In this case:\n"
1031"\n"
1032"         svn diff ^/trunk@500 ^/bar@HEAD\n"
1033"\n"
1034"\n"
1035"  The following applies to all types of merges:\n"
1036"\n"
1037"  To prevent unnecessary merge conflicts, svn merge requires that\n"
1038"  TARGET_WCPATH is not a mixed-revision working copy. Running 'svn update'\n"
1039"  before starting a merge ensures that all items in the working copy are\n"
1040"  based on the same revision.\n"
1041"\n"
1042"  If possible, you should have no local modifications in the merge's target\n"
1043"  working copy prior to the merge, to keep things simpler. It will be\n"
1044"  easier to revert the merge and to understand the branch's history.\n"
1045"\n"
1046"  Switched sub-paths should also be avoided during merging, as they may\n"
1047"  cause incomplete merges and create subtree mergeinfo.\n"
1048"\n"
1049"  For each merged item a line will be printed with characters reporting the\n"
1050"  action taken. These characters have the following meaning:\n"
1051"\n"
1052"    A  Added\n"
1053"    D  Deleted\n"
1054"    U  Updated\n"
1055"    C  Conflict\n"
1056"    G  Merged\n"
1057"    E  Existed\n"
1058"    R  Replaced\n"
1059"\n"
1060"  Characters in the first column report about the item itself.\n"
1061"  Characters in the second column report about properties of the item.\n"
1062"  A 'C' in the third column indicates a tree conflict, while a 'C' in\n"
1063"  the first and second columns indicate textual conflicts in files\n"
1064"  and in property values, respectively.\n"
1065"\n"
1066"    - Merge Tracking -\n"
1067"\n"
1068"  Subversion uses the svn:mergeinfo property to track merge history. This\n"
1069"  property is considered at the start of a merge to determine what to merge\n"
1070"  and it is updated at the conclusion of the merge to describe the merge\n"
1071"  that took place. Mergeinfo is used only if the two sources are on the\n"
1072"  same line of history -- if the first source is an ancestor of the second,\n"
1073"  or vice-versa (i.e. if one has originally been created by copying the\n"
1074"  other). This is verified and enforced when using sync merges and\n"
1075"  reintegrate merges.\n"
1076"\n"
1077"  The --ignore-ancestry option prevents merge tracking and thus ignores\n"
1078"  mergeinfo, neither considering it nor recording it.\n"
1079"\n"
1080"    - Merging from foreign repositories -\n"
1081"\n"
1082"  Subversion does support merging from foreign repositories.\n"
1083"  While all merge source URLs must point to the same repository, the merge\n"
1084"  target working copy may come from a different repository than the source.\n"
1085"  However, there are some caveats. Most notably, copies made in the\n"
1086"  merge source will be transformed into plain additions in the merge\n"
1087"  target. Also, merge-tracking is not supported for merges from foreign\n"
1088"  repositories.\n"),
1089    {'r', 'c', 'N', opt_depth, 'q', opt_force, opt_dry_run, opt_merge_cmd,
1090     opt_record_only, 'x', opt_ignore_ancestry, opt_accept, opt_reintegrate,
1091     opt_allow_mixed_revisions, 'v'} },
1092
1093  { "mergeinfo", svn_cl__mergeinfo, {0}, N_
1094    ("Display merge-related information.\n"
1095     "usage: 1. mergeinfo SOURCE[@REV] [TARGET[@REV]]\n"
1096     "       2. mergeinfo --show-revs=WHICH SOURCE[@REV] [TARGET[@REV]]\n"
1097     "\n"
1098     "  1. Summarize the history of merging between SOURCE and TARGET. The graph\n"
1099     "     shows, from left to right:\n"
1100     "       the youngest common ancestor of the branches;\n"
1101     "       the latest full merge in either direction, and thus the common base\n"
1102     "         that will be used for the next complete merge;\n"
1103     "       the repository path and revision number of the tip of each branch.\n"
1104     "\n"
1105     "  2. Print the revision numbers on SOURCE that have been merged to TARGET\n"
1106     "     (with --show-revs=merged), or that have not been merged to TARGET\n"
1107     "     (with --show-revs=eligible). Print only revisions in which there was\n"
1108     "     at least one change in SOURCE.\n"
1109     "\n"
1110     "     If --revision (-r) is provided, filter the displayed information to\n"
1111     "     show only that which is associated with the revisions within the\n"
1112     "     specified range.  Revision numbers, dates, and the 'HEAD' keyword are\n"
1113     "     valid range values.\n"
1114     "\n"
1115     "  SOURCE and TARGET are the source and target branch URLs, respectively.\n"
1116     "  (If a WC path is given, the corresponding base URL is used.) The default\n"
1117     "  TARGET is the current working directory ('.'). REV specifies the revision\n"
1118     "  to be considered the tip of the branch; the default for SOURCE is HEAD,\n"
1119     "  and the default for TARGET is HEAD for a URL or BASE for a WC path.\n"
1120     "\n"
1121     "  The depth can be 'empty' or 'infinity'; the default is 'empty'.\n"),
1122    {'r', 'R', opt_depth, opt_show_revs} },
1123
1124  { "mkdir", svn_cl__mkdir, {0}, N_
1125    ("Create a new directory under version control.\n"
1126     "usage: 1. mkdir PATH...\n"
1127     "       2. mkdir URL...\n"
1128     "\n"
1129     "  Create version controlled directories.\n"
1130     "\n"
1131     "  1. Each directory specified by a working copy PATH is created locally\n"
1132     "    and scheduled for addition upon the next commit.\n"
1133     "\n"
1134     "  2. Each directory specified by a URL is created in the repository via\n"
1135     "    an immediate commit.\n"
1136     "\n"
1137     "  In both cases, all the intermediate directories must already exist,\n"
1138     "  unless the --parents option is given.\n"),
1139    {'q', opt_parents, SVN_CL__LOG_MSG_OPTIONS} },
1140
1141  { "move", svn_cl__move, {"mv", "rename", "ren"}, N_
1142    ("Move (rename) an item in a working copy or repository.\n"
1143     "usage: move SRC... DST\n"
1144     "\n"
1145     "  SRC and DST can both be working copy (WC) paths or URLs:\n"
1146     "    WC  -> WC:  move an item in a working copy, as a local change to\n"
1147     "                be committed later (with or without further changes)\n"
1148     "    URL -> URL: move an item in the repository directly, immediately\n"
1149     "                creating a new revision in the repository\n"
1150     "  All the SRCs must be of the same type. When moving multiple sources,\n"
1151     "  they will be added as children of DST, which must be a directory.\n"
1152     "\n"
1153     "  SRC and DST of WC -> WC moves must be committed in the same revision.\n"
1154     "  Furthermore, WC -> WC moves will refuse to move a mixed-revision subtree.\n"
1155     "  To avoid unnecessary conflicts, it is recommended to run 'svn update'\n"
1156     "  to update the subtree to a single revision before moving it.\n"
1157     "  The --allow-mixed-revisions option is provided for backward compatibility.\n"
1158     "\n"
1159     "  The --revision option has no use and is deprecated.\n"),
1160    {'r', 'q', opt_force, opt_parents, opt_allow_mixed_revisions,
1161     SVN_CL__LOG_MSG_OPTIONS} },
1162
1163  { "patch", svn_cl__patch, {0}, N_
1164    ("Apply a patch to a working copy.\n"
1165     "usage: patch PATCHFILE [WCPATH]\n"
1166     "\n"
1167     "  Apply a unidiff patch in PATCHFILE to the working copy WCPATH.\n"
1168     "  If WCPATH is omitted, '.' is assumed.\n"
1169     "\n"
1170     "  A unidiff patch suitable for application to a working copy can be\n"
1171     "  produced with the 'svn diff' command or third-party diffing tools.\n"
1172     "  Any non-unidiff content of PATCHFILE is ignored, except for Subversion\n"
1173     "  property diffs as produced by 'svn diff'.\n"
1174     "\n"
1175     "  Changes listed in the patch will either be applied or rejected.\n"
1176     "  If a change does not match at its exact line offset, it may be applied\n"
1177     "  earlier or later in the file if a match is found elsewhere for the\n"
1178     "  surrounding lines of context provided by the patch.\n"
1179     "  A change may also be applied with fuzz, which means that one\n"
1180     "  or more lines of context are ignored when matching the change.\n"
1181     "  If no matching context can be found for a change, the change conflicts\n"
1182     "  and will be written to a reject file with the extension .svnpatch.rej.\n"
1183     "\n"
1184     "  For each patched file a line will be printed with characters reporting\n"
1185     "  the action taken. These characters have the following meaning:\n"
1186     "\n"
1187     "    A  Added\n"
1188     "    D  Deleted\n"
1189     "    U  Updated\n"
1190     "    C  Conflict\n"
1191     "    G  Merged (with local uncommitted changes)\n"
1192     "\n"
1193     "  Changes applied with an offset or fuzz are reported on lines starting\n"
1194     "  with the '>' symbol. You should review such changes carefully.\n"
1195     "\n"
1196     "  If the patch removes all content from a file, that file is scheduled\n"
1197     "  for deletion. If the patch creates a new file, that file is scheduled\n"
1198     "  for addition. Use 'svn revert' to undo deletions and additions you\n"
1199     "  do not agree with.\n"
1200     "\n"
1201     "  Hint: If the patch file was created with Subversion, it will contain\n"
1202     "        the number of a revision N the patch will cleanly apply to\n"
1203     "        (look for lines like '--- foo/bar.txt        (revision N)').\n"
1204     "        To avoid rejects, first update to the revision N using\n"
1205     "        'svn update -r N', apply the patch, and then update back to the\n"
1206     "        HEAD revision. This way, conflicts can be resolved interactively.\n"
1207     ),
1208    {'q', opt_dry_run, opt_strip, opt_reverse_diff,
1209     opt_ignore_whitespace} },
1210
1211  { "propdel", svn_cl__propdel, {"pdel", "pd"}, N_
1212    ("Remove a property from files, dirs, or revisions.\n"
1213     "usage: 1. propdel PROPNAME [PATH...]\n"
1214     "       2. propdel PROPNAME --revprop -r REV [TARGET]\n"
1215     "\n"
1216     "  1. Removes versioned props in working copy.\n"
1217     "  2. Removes unversioned remote prop on repos revision.\n"
1218     "     TARGET only determines which repository to access.\n"),
1219    {'q', 'R', opt_depth, 'r', opt_revprop, opt_changelist} },
1220
1221  { "propedit", svn_cl__propedit, {"pedit", "pe"}, N_
1222    ("Edit a property with an external editor.\n"
1223     "usage: 1. propedit PROPNAME TARGET...\n"
1224     "       2. propedit PROPNAME --revprop -r REV [TARGET]\n"
1225     "\n"
1226     "  1. Edits versioned prop in working copy or repository.\n"
1227     "  2. Edits unversioned remote prop on repos revision.\n"
1228     "     TARGET only determines which repository to access.\n"
1229     "\n"
1230     "  See 'svn help propset' for more on setting properties.\n"),
1231    {'r', opt_revprop, SVN_CL__LOG_MSG_OPTIONS, opt_force} },
1232
1233  { "propget", svn_cl__propget, {"pget", "pg"}, N_
1234    ("Print the value of a property on files, dirs, or revisions.\n"
1235     "usage: 1. propget PROPNAME [TARGET[@REV]...]\n"
1236     "       2. propget PROPNAME --revprop -r REV [TARGET]\n"
1237     "\n"
1238     "  1. Prints versioned props. If specified, REV determines in which\n"
1239     "     revision the target is first looked up.\n"
1240     "  2. Prints unversioned remote prop on repos revision.\n"
1241     "     TARGET only determines which repository to access.\n"
1242     "\n"
1243     "  With --verbose, the target path and the property name are printed on\n"
1244     "  separate lines before each value, like 'svn proplist --verbose'.\n"
1245     "  Otherwise, if there is more than one TARGET or a depth other than\n"
1246     "  'empty', the target path is printed on the same line before each value.\n"
1247     "\n"
1248     "  By default, an extra newline is printed after the property value so that\n"
1249     "  the output looks pretty.  With a single TARGET and depth 'empty', you can\n"
1250     "  use the --strict option to disable this (useful when redirecting a binary\n"
1251     "  property value to a file, for example).\n"),
1252    {'v', 'R', opt_depth, 'r', opt_revprop, opt_strict, opt_xml,
1253     opt_changelist, opt_show_inherited_props },
1254    {{'v', N_("print path, name and value on separate lines")},
1255     {opt_strict, N_("don't print an extra newline")}} },
1256
1257  { "proplist", svn_cl__proplist, {"plist", "pl"}, N_
1258    ("List all properties on files, dirs, or revisions.\n"
1259     "usage: 1. proplist [TARGET[@REV]...]\n"
1260     "       2. proplist --revprop -r REV [TARGET]\n"
1261     "\n"
1262     "  1. Lists versioned props. If specified, REV determines in which\n"
1263     "     revision the target is first looked up.\n"
1264     "  2. Lists unversioned remote props on repos revision.\n"
1265     "     TARGET only determines which repository to access.\n"
1266     "\n"
1267     "  With --verbose, the property values are printed as well, like 'svn propget\n"
1268     "  --verbose'.  With --quiet, the paths are not printed.\n"),
1269    {'v', 'R', opt_depth, 'r', 'q', opt_revprop, opt_xml, opt_changelist,
1270     opt_show_inherited_props },
1271    {{'v', N_("print path, name and value on separate lines")},
1272     {'q', N_("don't print the path")}} },
1273
1274  { "propset", svn_cl__propset, {"pset", "ps"}, N_
1275    ("Set the value of a property on files, dirs, or revisions.\n"
1276     "usage: 1. propset PROPNAME PROPVAL PATH...\n"
1277     "       2. propset PROPNAME --revprop -r REV PROPVAL [TARGET]\n"
1278     "\n"
1279     "  1. Changes a versioned file or directory property in a working copy.\n"
1280     "  2. Changes an unversioned property on a repository revision.\n"
1281     "     (TARGET only determines which repository to access.)\n"
1282     "\n"
1283     "  The value may be provided with the --file option instead of PROPVAL.\n"
1284     "\n"
1285     "  Property names starting with 'svn:' are reserved.  Subversion recognizes\n"
1286     "  the following special versioned properties on a file:\n"
1287     "    svn:keywords   - Keywords to be expanded.  Valid keywords are:\n"
1288     "      URL, HeadURL             - The URL for the head version of the file.\n"
1289     "      Author, LastChangedBy    - The last person to modify the file.\n"
1290     "      Date, LastChangedDate    - The date/time the file was last modified.\n"
1291     "      Rev, Revision,           - The last revision the file changed.\n"
1292     "        LastChangedRevision\n"
1293     "      Id                       - A compressed summary of the previous four.\n"
1294     "      Header                   - Similar to Id but includes the full URL.\n"
1295     "\n"
1296     "      Custom keywords can be defined with a format string separated from\n"
1297     "      the keyword name with '='. Valid format substitutions are:\n"
1298     "        %a   - The author of the revision given by %r.\n"
1299     "        %b   - The basename of the URL of the file.\n"
1300     "        %d   - Short format of the date of the revision given by %r.\n"
1301     "        %D   - Long format of the date of the revision given by %r.\n"
1302     "        %P   - The file's path, relative to the repository root.\n"
1303     "        %r   - The number of the revision which last changed the file.\n"
1304     "        %R   - The URL to the root of the repository.\n"
1305     "        %u   - The URL of the file.\n"
1306     "        %_   - A space (keyword definitions cannot contain a literal space).\n"
1307     "        %%   - A literal '%'.\n"
1308     "        %H   - Equivalent to %P%_%r%_%d%_%a.\n"
1309     "        %I   - Equivalent to %b%_%r%_%d%_%a.\n"
1310     "      Example custom keyword definition: MyKeyword=%r%_%a%_%P\n"
1311     "      Once a custom keyword has been defined for a file, it can be used\n"
1312     "      within the file like any other keyword: $MyKeyword$\n"
1313     "\n"
1314     "    svn:executable - If present, make the file executable.  Use\n"
1315     "      'svn propdel svn:executable PATH...' to clear.\n"
1316     "    svn:eol-style  - One of 'native', 'LF', 'CR', 'CRLF'.\n"
1317     "    svn:mime-type  - The mimetype of the file.  Used to determine\n"
1318     "      whether to merge the file, and how to serve it from Apache.\n"
1319     "      A mimetype beginning with 'text/' (or an absent mimetype) is\n"
1320     "      treated as text.  Anything else is treated as binary.\n"
1321     "    svn:needs-lock - If present, indicates that the file should be locked\n"
1322     "      before it is modified.  Makes the working copy file read-only\n"
1323     "      when it is not locked.  Use 'svn propdel svn:needs-lock PATH...'\n"
1324     "      to clear.\n"
1325     "\n"
1326     "  Subversion recognizes the following special versioned properties on a\n"
1327     "  directory:\n"
1328     "    svn:ignore         - A list of file glob patterns to ignore, one per line.\n"
1329     "    svn:global-ignores - Like svn:ignore, but inheritable.\n"
1330     "    svn:auto-props     - Automatically set properties on files when they are\n"
1331     "      added or imported. Contains key-value pairs, one per line, in the format:\n"
1332     "        PATTERN = PROPNAME=VALUE[;PROPNAME=VALUE ...]\n"
1333     "      Example (where a literal ';' is escaped by adding another ';'):\n"
1334     "        *.html = svn:eol-style=native;svn:mime-type=text/html;; charset=UTF8\n"
1335     "      Applies recursively to all files added or imported under the directory\n"
1336     "      it is set on.  See also [auto-props] in the client configuration file.\n"
1337     "    svn:externals      - A list of module specifiers, one per line, in the\n"
1338     "      following format similar to the syntax of 'svn checkout':\n"
1339     "        [-r REV] URL[@PEG] LOCALPATH\n"
1340     "      Example:\n"
1341     "        http://example.com/repos/zig foo/bar\n"
1342     "      The LOCALPATH is relative to the directory having this property.\n"
1343     "      To pin the external to a known revision, specify the optional REV:\n"
1344     "        -r25 http://example.com/repos/zig foo/bar\n"
1345     "      To unambiguously identify an element at a path which may have been\n"
1346     "      subsequently deleted or renamed, specify the optional PEG revision:\n"
1347     "        -r25 http://example.com/repos/zig@42 foo/bar\n"
1348     "      The URL may be a full URL or a relative URL starting with one of:\n"
1349     "        ../  to the parent directory of the extracted external\n"
1350     "        ^/   to the repository root\n"
1351     "        /    to the server root\n"
1352     "        //   to the URL scheme\n"
1353     "      Use of the following format is discouraged but is supported for\n"
1354     "      interoperability with Subversion 1.4 and earlier clients:\n"
1355     "        LOCALPATH [-r PEG] URL\n"
1356     "      The ambiguous format 'relative_path relative_path' is taken as\n"
1357     "      'relative_url relative_path' with peg revision support.\n"
1358     "      Lines starting with a '#' character are ignored.\n"),
1359    {'F', opt_encoding, 'q', 'r', opt_targets, 'R', opt_depth, opt_revprop,
1360     opt_force, opt_changelist },
1361    {{'F', N_("read property value from file ARG")}} },
1362
1363  { "relocate", svn_cl__relocate, {0}, N_
1364    ("Relocate the working copy to point to a different repository root URL.\n"
1365     "usage: 1. relocate FROM-PREFIX TO-PREFIX [PATH...]\n"
1366     "       2. relocate TO-URL [PATH]\n"
1367     "\n"
1368     "  Rewrite working copy URL metadata to reflect a syntactic change only.\n"
1369     "  This is used when a repository's root URL changes (such as a scheme\n"
1370     "  or hostname change) but your working copy still reflects the same\n"
1371     "  directory within the same repository.\n"
1372     "\n"
1373     "  1. FROM-PREFIX and TO-PREFIX are initial substrings of the working\n"
1374     "     copy's current and new URLs, respectively.  (You may specify the\n"
1375     "     complete old and new URLs if you wish.)  Use 'svn info' to determine\n"
1376     "     the current working copy URL.\n"
1377     "\n"
1378     "  2. TO-URL is the (complete) new repository URL to use for PATH.\n"
1379     "\n"
1380     "  Examples:\n"
1381     "    svn relocate http:// svn:// project1 project2\n"
1382     "    svn relocate http://www.example.com/repo/project \\\n"
1383     "                 svn://svn.example.com/repo/project\n"),
1384    {opt_ignore_externals} },
1385
1386  { "resolve", svn_cl__resolve, {0}, N_
1387    ("Resolve conflicts on working copy files or directories.\n"
1388     "usage: resolve [PATH...]\n"
1389     "\n"
1390     "  By default, perform interactive conflict resolution on PATH.\n"
1391     "  In this mode, the command is recursive by default (depth 'infinity').\n"
1392     "\n"
1393     "  The --accept=ARG option prevents interactive prompting and forces\n"
1394     "  conflicts on PATH to be resolved in the manner specified by ARG.\n"
1395     "  In this mode, the command is not recursive by default (depth 'empty').\n"),
1396    {opt_targets, 'R', opt_depth, 'q', opt_accept},
1397    {{opt_accept, N_("specify automatic conflict resolution source\n"
1398                     "                             "
1399                     "('base', 'working', 'mine-conflict',\n"
1400                     "                             "
1401                     "'theirs-conflict', 'mine-full', 'theirs-full')")}} },
1402
1403  { "resolved", svn_cl__resolved, {0}, N_
1404    ("Remove 'conflicted' state on working copy files or directories.\n"
1405     "usage: resolved PATH...\n"
1406     "\n"
1407     "  Note:  this subcommand does not semantically resolve conflicts or\n"
1408     "  remove conflict markers; it merely removes the conflict-related\n"
1409     "  artifact files and allows PATH to be committed again.  It has been\n"
1410     "  deprecated in favor of running 'svn resolve --accept working'.\n"),
1411    {opt_targets, 'R', opt_depth, 'q'} },
1412
1413  { "revert", svn_cl__revert, {0}, N_
1414    ("Restore pristine working copy state (undo local changes).\n"
1415     "usage: revert PATH...\n"
1416     "\n"
1417     "  Revert changes in the working copy at or within PATH, and remove\n"
1418     "  conflict markers as well, if any.\n"
1419     "\n"
1420     "  This subcommand does not revert already committed changes.\n"
1421     "  For information about undoing already committed changes, search\n"
1422     "  the output of 'svn help merge' for 'undo'.\n"),
1423    {opt_targets, 'R', opt_depth, 'q', opt_changelist} },
1424
1425  { "status", svn_cl__status, {"stat", "st"}, N_
1426    ("Print the status of working copy files and directories.\n"
1427     "usage: status [PATH...]\n"
1428     "\n"
1429     "  With no args, print only locally modified items (no network access).\n"
1430     "  With -q, print only summary information about locally modified items.\n"
1431     "  With -u, add working revision and server out-of-date information.\n"
1432     "  With -v, print full revision information on every item.\n"
1433     "\n"
1434     "  The first seven columns in the output are each one character wide:\n"
1435     "    First column: Says if item was added, deleted, or otherwise changed\n"
1436     "      ' ' no modifications\n"
1437     "      'A' Added\n"
1438     "      'C' Conflicted\n"
1439     "      'D' Deleted\n"
1440     "      'I' Ignored\n"
1441     "      'M' Modified\n"
1442     "      'R' Replaced\n"
1443     "      'X' an unversioned directory created by an externals definition\n"
1444     "      '?' item is not under version control\n"
1445     "      '!' item is missing (removed by non-svn command) or incomplete\n"
1446     "      '~' versioned item obstructed by some item of a different kind\n"
1447     "    Second column: Modifications of a file's or directory's properties\n"
1448     "      ' ' no modifications\n"
1449     "      'C' Conflicted\n"
1450     "      'M' Modified\n"
1451     "    Third column: Whether the working copy is locked for writing by\n"
1452     "                  another Subversion client modifying the working copy\n"
1453     "      ' ' not locked for writing\n"
1454     "      'L' locked for writing\n"
1455     "    Fourth column: Scheduled commit will contain addition-with-history\n"
1456     "      ' ' no history scheduled with commit\n"
1457     "      '+' history scheduled with commit\n"
1458     "    Fifth column: Whether the item is switched or a file external\n"
1459     "      ' ' normal\n"
1460     "      'S' the item has a Switched URL relative to the parent\n"
1461     "      'X' a versioned file created by an eXternals definition\n"
1462     "    Sixth column: Whether the item is locked in repository for exclusive commit\n"
1463     "      (without -u)\n"
1464     "      ' ' not locked by this working copy\n"
1465     "      'K' locked by this working copy, but lock might be stolen or broken\n"
1466     "      (with -u)\n"
1467     "      ' ' not locked in repository, not locked by this working copy\n"
1468     "      'K' locked in repository, lock owned by this working copy\n"
1469     "      'O' locked in repository, lock owned by another working copy\n"
1470     "      'T' locked in repository, lock owned by this working copy was stolen\n"
1471     "      'B' not locked in repository, lock owned by this working copy is broken\n"
1472     "    Seventh column: Whether the item is the victim of a tree conflict\n"
1473     "      ' ' normal\n"
1474     "      'C' tree-Conflicted\n"
1475     "    If the item is a tree conflict victim, an additional line is printed\n"
1476     "    after the item's status line, explaining the nature of the conflict.\n"
1477     "\n"
1478     "  The out-of-date information appears in the ninth column (with -u):\n"
1479     "      '*' a newer revision exists on the server\n"
1480     "      ' ' the working copy is up to date\n"
1481     "\n"
1482     "  Remaining fields are variable width and delimited by spaces:\n"
1483     "    The working revision (with -u or -v; '-' if the item is copied)\n"
1484     "    The last committed revision and last committed author (with -v)\n"
1485     "    The working copy path is always the final field, so it can\n"
1486     "      include spaces.\n"
1487     "\n"
1488     "  The presence of a question mark ('?') where a working revision, last\n"
1489     "  committed revision, or last committed author was expected indicates\n"
1490     "  that the information is unknown or irrelevant given the state of the\n"
1491     "  item (for example, when the item is the result of a copy operation).\n"
1492     "  The question mark serves as a visual placeholder to facilitate parsing.\n"
1493     "\n"
1494     "  Example output:\n"
1495     "    svn status wc\n"
1496     "     M      wc/bar.c\n"
1497     "    A  +    wc/qax.c\n"
1498     "\n"
1499     "    svn status -u wc\n"
1500     "     M             965   wc/bar.c\n"
1501     "            *      965   wc/foo.c\n"
1502     "    A  +             -   wc/qax.c\n"
1503     "    Status against revision:   981\n"
1504     "\n"
1505     "    svn status --show-updates --verbose wc\n"
1506     "     M             965      938 kfogel       wc/bar.c\n"
1507     "            *      965      922 sussman      wc/foo.c\n"
1508     "    A  +             -      687 joe          wc/qax.c\n"
1509     "                   965      687 joe          wc/zig.c\n"
1510     "    Status against revision:   981\n"
1511     "\n"
1512     "    svn status\n"
1513     "     M      wc/bar.c\n"
1514     "    !     C wc/qaz.c\n"
1515     "          >   local missing, incoming edit upon update\n"
1516     "    D       wc/qax.c\n"),
1517    { 'u', 'v', 'N', opt_depth, 'q', opt_no_ignore, opt_incremental, opt_xml,
1518      opt_ignore_externals, opt_changelist},
1519    {{'q', N_("don't print unversioned items")}} },
1520
1521  { "switch", svn_cl__switch, {"sw"}, N_
1522    ("Update the working copy to a different URL within the same repository.\n"
1523     "usage: 1. switch URL[@PEGREV] [PATH]\n"
1524     "       2. switch --relocate FROM-PREFIX TO-PREFIX [PATH...]\n"
1525     "\n"
1526     "  1. Update the working copy to mirror a new URL within the repository.\n"
1527     "     This behavior is similar to 'svn update', and is the way to\n"
1528     "     move a working copy to a branch or tag within the same repository.\n"
1529     "     If specified, PEGREV determines in which revision the target is first\n"
1530     "     looked up.\n"
1531     "\n"
1532     "     If --force is used, unversioned obstructing paths in the working\n"
1533     "     copy do not automatically cause a failure if the switch attempts to\n"
1534     "     add the same path.  If the obstructing path is the same type (file\n"
1535     "     or directory) as the corresponding path in the repository it becomes\n"
1536     "     versioned but its contents are left 'as-is' in the working copy.\n"
1537     "     This means that an obstructing directory's unversioned children may\n"
1538     "     also obstruct and become versioned.  For files, any content differences\n"
1539     "     between the obstruction and the repository are treated like a local\n"
1540     "     modification to the working copy.  All properties from the repository\n"
1541     "     are applied to the obstructing path.\n"
1542     "\n"
1543     "     Use the --set-depth option to set a new working copy depth on the\n"
1544     "     targets of this operation.\n"
1545     "\n"
1546     "     By default, Subversion will refuse to switch a working copy path to\n"
1547     "     a new URL with which it shares no common version control ancestry.\n"
1548     "     Use the '--ignore-ancestry' option to override this sanity check.\n"
1549     "\n"
1550     "  2. The '--relocate' option is deprecated. This syntax is equivalent to\n"
1551     "     'svn relocate FROM-PREFIX TO-PREFIX [PATH]'.\n"
1552     "\n"
1553     "  See also 'svn help update' for a list of possible characters\n"
1554     "  reporting the action taken.\n"
1555     "\n"
1556     "  Examples:\n"
1557     "    svn switch ^/branches/1.x-release\n"
1558     "    svn switch --relocate http:// svn://\n"
1559     "    svn switch --relocate http://www.example.com/repo/project \\\n"
1560     "                          svn://svn.example.com/repo/project\n"),
1561    { 'r', 'N', opt_depth, opt_set_depth, 'q', opt_merge_cmd, opt_relocate,
1562      opt_ignore_externals, opt_ignore_ancestry, opt_force, opt_accept},
1563    {{opt_ignore_ancestry,
1564      N_("allow switching to a node with no common ancestor")}}
1565  },
1566
1567  { "unlock", svn_cl__unlock, {0}, N_
1568    ("Unlock working copy paths or URLs.\n"
1569     "usage: unlock TARGET...\n"
1570     "\n"
1571     "  Use --force to break the lock.\n"),
1572    { opt_targets, opt_force } },
1573
1574  { "update", svn_cl__update, {"up"},  N_
1575    ("Bring changes from the repository into the working copy.\n"
1576     "usage: update [PATH...]\n"
1577     "\n"
1578     "  If no revision is given, bring working copy up-to-date with HEAD rev.\n"
1579     "  Else synchronize working copy to revision given by -r.\n"
1580     "\n"
1581     "  For each updated item a line will be printed with characters reporting\n"
1582     "  the action taken. These characters have the following meaning:\n"
1583     "\n"
1584     "    A  Added\n"
1585     "    D  Deleted\n"
1586     "    U  Updated\n"
1587     "    C  Conflict\n"
1588     "    G  Merged\n"
1589     "    E  Existed\n"
1590     "    R  Replaced\n"
1591     "\n"
1592     "  Characters in the first column report about the item itself.\n"
1593     "  Characters in the second column report about properties of the item.\n"
1594     "  A 'B' in the third column signifies that the lock for the file has\n"
1595     "  been broken or stolen.\n"
1596     "  A 'C' in the fourth column indicates a tree conflict, while a 'C' in\n"
1597     "  the first and second columns indicate textual conflicts in files\n"
1598     "  and in property values, respectively.\n"
1599     "\n"
1600     "  If --force is used, unversioned obstructing paths in the working\n"
1601     "  copy do not automatically cause a failure if the update attempts to\n"
1602     "  add the same path.  If the obstructing path is the same type (file\n"
1603     "  or directory) as the corresponding path in the repository it becomes\n"
1604     "  versioned but its contents are left 'as-is' in the working copy.\n"
1605     "  This means that an obstructing directory's unversioned children may\n"
1606     "  also obstruct and become versioned.  For files, any content differences\n"
1607     "  between the obstruction and the repository are treated like a local\n"
1608     "  modification to the working copy.  All properties from the repository\n"
1609     "  are applied to the obstructing path.  Obstructing paths are reported\n"
1610     "  in the first column with code 'E'.\n"
1611     "\n"
1612     "  If the specified update target is missing from the working copy but its\n"
1613     "  immediate parent directory is present, checkout the target into its\n"
1614     "  parent directory at the specified depth.  If --parents is specified,\n"
1615     "  create any missing parent directories of the target by checking them\n"
1616     "  out, too, at depth=empty.\n"
1617     "\n"
1618     "  Use the --set-depth option to set a new working copy depth on the\n"
1619     "  targets of this operation.\n"),
1620    {'r', 'N', opt_depth, opt_set_depth, 'q', opt_merge_cmd, opt_force,
1621     opt_ignore_externals, opt_changelist, opt_editor_cmd, opt_accept,
1622     opt_parents} },
1623
1624  { "upgrade", svn_cl__upgrade, {0}, N_
1625    ("Upgrade the metadata storage format for a working copy.\n"
1626     "usage: upgrade [WCPATH...]\n"
1627     "\n"
1628     "  Local modifications are preserved.\n"),
1629    { 'q' } },
1630
1631  { NULL, NULL, {0}, NULL, {0} }
1632};
1633
1634
1635/* Version compatibility check */
1636static svn_error_t *
1637check_lib_versions(void)
1638{
1639  static const svn_version_checklist_t checklist[] =
1640    {
1641      { "svn_subr",   svn_subr_version },
1642      { "svn_client", svn_client_version },
1643      { "svn_wc",     svn_wc_version },
1644      { "svn_ra",     svn_ra_version },
1645      { "svn_delta",  svn_delta_version },
1646      { "svn_diff",   svn_diff_version },
1647      { NULL, NULL }
1648    };
1649  SVN_VERSION_DEFINE(my_version);
1650
1651  return svn_ver_check_list2(&my_version, checklist, svn_ver_equal);
1652}
1653
1654
1655/* A flag to see if we've been cancelled by the client or not. */
1656static volatile sig_atomic_t cancelled = FALSE;
1657
1658/* A signal handler to support cancellation. */
1659static void
1660signal_handler(int signum)
1661{
1662  apr_signal(signum, SIG_IGN);
1663  cancelled = TRUE;
1664}
1665
1666/* Our cancellation callback. */
1667svn_error_t *
1668svn_cl__check_cancel(void *baton)
1669{
1670  if (cancelled)
1671    return svn_error_create(SVN_ERR_CANCELLED, NULL, _("Caught signal"));
1672  else
1673    return SVN_NO_ERROR;
1674}
1675
1676/* Add a --search argument to OPT_STATE.
1677 * These options start a new search pattern group. */
1678static void
1679add_search_pattern_group(svn_cl__opt_state_t *opt_state,
1680                         const char *pattern,
1681                         apr_pool_t *result_pool)
1682{
1683  apr_array_header_t *group = NULL;
1684
1685  if (opt_state->search_patterns == NULL)
1686    opt_state->search_patterns = apr_array_make(result_pool, 1,
1687                                                sizeof(apr_array_header_t *));
1688
1689  group = apr_array_make(result_pool, 1, sizeof(const char *));
1690  APR_ARRAY_PUSH(group, const char *) = pattern;
1691  APR_ARRAY_PUSH(opt_state->search_patterns, apr_array_header_t *) = group;
1692}
1693
1694/* Add a --search-and argument to OPT_STATE.
1695 * These patterns are added to an existing pattern group, if any. */
1696static void
1697add_search_pattern_to_latest_group(svn_cl__opt_state_t *opt_state,
1698                                   const char *pattern,
1699                                   apr_pool_t *result_pool)
1700{
1701  apr_array_header_t *group;
1702
1703  if (opt_state->search_patterns == NULL)
1704    {
1705      add_search_pattern_group(opt_state, pattern, result_pool);
1706      return;
1707    }
1708
1709  group = APR_ARRAY_IDX(opt_state->search_patterns,
1710                        opt_state->search_patterns->nelts - 1,
1711                        apr_array_header_t *);
1712  APR_ARRAY_PUSH(group, const char *) = pattern;
1713}
1714
1715
1716/*** Main. ***/
1717
1718/* Report and clear the error ERR, and return EXIT_FAILURE. Suppress the
1719 * error message if it is SVN_ERR_IO_PIPE_WRITE_ERROR. */
1720#define EXIT_ERROR(err)                                                 \
1721  svn_cmdline_handle_exit_error(err, NULL, "svn: ")
1722
1723/* A redefinition of the public SVN_INT_ERR macro, that suppresses the
1724 * error message if it is SVN_ERR_IO_PIPE_WRITE_ERROR. */
1725#undef SVN_INT_ERR
1726#define SVN_INT_ERR(expr)                                        \
1727  do {                                                           \
1728    svn_error_t *svn_err__temp = (expr);                         \
1729    if (svn_err__temp)                                           \
1730      return EXIT_ERROR(svn_err__temp);                          \
1731  } while (0)
1732
1733static int
1734sub_main(int argc, const char *argv[], apr_pool_t *pool)
1735{
1736  svn_error_t *err;
1737  int opt_id;
1738  apr_getopt_t *os;
1739  svn_cl__opt_state_t opt_state = { 0, { 0 } };
1740  svn_client_ctx_t *ctx;
1741  apr_array_header_t *received_opts;
1742  int i;
1743  const svn_opt_subcommand_desc2_t *subcommand = NULL;
1744  const char *dash_m_arg = NULL, *dash_F_arg = NULL;
1745  svn_cl__cmd_baton_t command_baton;
1746  svn_auth_baton_t *ab;
1747  svn_config_t *cfg_config;
1748  svn_boolean_t descend = TRUE;
1749  svn_boolean_t interactive_conflicts = FALSE;
1750  svn_boolean_t force_interactive = FALSE;
1751  svn_cl__conflict_stats_t *conflict_stats
1752    = svn_cl__conflict_stats_create(pool);
1753  svn_boolean_t use_notifier = TRUE;
1754  svn_boolean_t reading_file_from_stdin = FALSE;
1755  apr_hash_t *changelists;
1756  apr_hash_t *cfg_hash;
1757
1758  received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));
1759
1760  /* Check library versions */
1761  SVN_INT_ERR(check_lib_versions());
1762
1763#if defined(WIN32) || defined(__CYGWIN__)
1764  /* Set the working copy administrative directory name. */
1765  if (getenv("SVN_ASP_DOT_NET_HACK"))
1766    {
1767      SVN_INT_ERR(svn_wc_set_adm_dir("_svn", pool));
1768    }
1769#endif
1770
1771  /* Initialize the RA library. */
1772  SVN_INT_ERR(svn_ra_initialize(pool));
1773
1774  /* Init our changelists hash. */
1775  changelists = apr_hash_make(pool);
1776
1777  /* Begin processing arguments. */
1778  opt_state.start_revision.kind = svn_opt_revision_unspecified;
1779  opt_state.end_revision.kind = svn_opt_revision_unspecified;
1780  opt_state.revision_ranges =
1781    apr_array_make(pool, 0, sizeof(svn_opt_revision_range_t *));
1782  opt_state.depth = svn_depth_unknown;
1783  opt_state.set_depth = svn_depth_unknown;
1784  opt_state.accept_which = svn_cl__accept_unspecified;
1785  opt_state.show_revs = svn_cl__show_revs_invalid;
1786
1787  /* No args?  Show usage. */
1788  if (argc <= 1)
1789    {
1790      SVN_INT_ERR(svn_cl__help(NULL, NULL, pool));
1791      return EXIT_FAILURE;
1792    }
1793
1794  /* Else, parse options. */
1795  SVN_INT_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
1796
1797  os->interleave = 1;
1798  while (1)
1799    {
1800      const char *opt_arg;
1801      const char *utf8_opt_arg;
1802
1803      /* Parse the next option. */
1804      apr_status_t apr_err = apr_getopt_long(os, svn_cl__options, &opt_id,
1805                                             &opt_arg);
1806      if (APR_STATUS_IS_EOF(apr_err))
1807        break;
1808      else if (apr_err)
1809        {
1810          SVN_INT_ERR(svn_cl__help(NULL, NULL, pool));
1811          return EXIT_FAILURE;
1812        }
1813
1814      /* Stash the option code in an array before parsing it. */
1815      APR_ARRAY_PUSH(received_opts, int) = opt_id;
1816
1817      switch (opt_id) {
1818      case 'l':
1819        {
1820          err = svn_cstring_atoi(&opt_state.limit, opt_arg);
1821          if (err)
1822            {
1823              err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, err,
1824                                     _("Non-numeric limit argument given"));
1825              return EXIT_ERROR(err);
1826            }
1827          if (opt_state.limit <= 0)
1828            {
1829              err = svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
1830                                    _("Argument to --limit must be positive"));
1831              return EXIT_ERROR(err);
1832            }
1833        }
1834        break;
1835      case 'm':
1836        /* Note that there's no way here to detect if the log message
1837           contains a zero byte -- if it does, then opt_arg will just
1838           be shorter than the user intended.  Oh well. */
1839        opt_state.message = apr_pstrdup(pool, opt_arg);
1840        dash_m_arg = opt_arg;
1841        break;
1842      case 'c':
1843        {
1844          apr_array_header_t *change_revs =
1845            svn_cstring_split(opt_arg, ", \n\r\t\v", TRUE, pool);
1846
1847          if (opt_state.old_target)
1848            {
1849              err = svn_error_create
1850                (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1851                 _("Can't specify -c with --old"));
1852              return EXIT_ERROR(err);
1853            }
1854
1855          for (i = 0; i < change_revs->nelts; i++)
1856            {
1857              char *end;
1858              svn_revnum_t changeno, changeno_end;
1859              const char *change_str =
1860                APR_ARRAY_IDX(change_revs, i, const char *);
1861              const char *s = change_str;
1862              svn_boolean_t is_negative;
1863
1864              /* Check for a leading minus to allow "-c -r42".
1865               * The is_negative flag is used to handle "-c -42" and "-c -r42".
1866               * The "-c r-42" case is handled by strtol() returning a
1867               * negative number. */
1868              is_negative = (*s == '-');
1869              if (is_negative)
1870                s++;
1871
1872              /* Allow any number of 'r's to prefix a revision number. */
1873              while (*s == 'r')
1874                s++;
1875              changeno = changeno_end = strtol(s, &end, 10);
1876              if (end != s && *end == '-')
1877                {
1878                  if (changeno < 0 || is_negative)
1879                    {
1880                      err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR,
1881                                              NULL,
1882                                              _("Negative number in range (%s)"
1883                                                " not supported with -c"),
1884                                              change_str);
1885                      return EXIT_ERROR(err);
1886                    }
1887                  s = end + 1;
1888                  while (*s == 'r')
1889                    s++;
1890                  changeno_end = strtol(s, &end, 10);
1891                }
1892              if (end == change_str || *end != '\0')
1893                {
1894                  err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1895                                          _("Non-numeric change argument (%s) "
1896                                            "given to -c"), change_str);
1897                  return EXIT_ERROR(err);
1898                }
1899
1900              if (changeno == 0)
1901                {
1902                  err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1903                                         _("There is no change 0"));
1904                  return EXIT_ERROR(err);
1905                }
1906
1907              if (is_negative)
1908                changeno = -changeno;
1909
1910              /* Figure out the range:
1911                    -c N  -> -r N-1:N
1912                    -c -N -> -r N:N-1
1913                    -c M-N -> -r M-1:N for M < N
1914                    -c M-N -> -r M:N-1 for M > N
1915                    -c -M-N -> error (too confusing/no valid use case)
1916              */
1917              if (changeno > 0)
1918                {
1919                  if (changeno <= changeno_end)
1920                    changeno--;
1921                  else
1922                    changeno_end--;
1923                }
1924              else
1925                {
1926                  changeno = -changeno;
1927                  changeno_end = changeno - 1;
1928                }
1929
1930              opt_state.used_change_arg = TRUE;
1931              APR_ARRAY_PUSH(opt_state.revision_ranges,
1932                             svn_opt_revision_range_t *)
1933                = svn_opt__revision_range_from_revnums(changeno, changeno_end,
1934                                                       pool);
1935            }
1936        }
1937        break;
1938      case 'r':
1939        opt_state.used_revision_arg = TRUE;
1940        if (svn_opt_parse_revision_to_range(opt_state.revision_ranges,
1941                                            opt_arg, pool) != 0)
1942          {
1943            SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
1944            err = svn_error_createf
1945                (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1946                 _("Syntax error in revision argument '%s'"),
1947                 utf8_opt_arg);
1948            return EXIT_ERROR(err);
1949          }
1950        break;
1951      case 'v':
1952        opt_state.verbose = TRUE;
1953        break;
1954      case 'u':
1955        opt_state.update = TRUE;
1956        break;
1957      case 'h':
1958      case '?':
1959        opt_state.help = TRUE;
1960        break;
1961      case 'q':
1962        opt_state.quiet = TRUE;
1963        break;
1964      case opt_incremental:
1965        opt_state.incremental = TRUE;
1966        break;
1967      case 'F':
1968        SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
1969        SVN_INT_ERR(svn_stringbuf_from_file2(&(opt_state.filedata),
1970                                             utf8_opt_arg, pool));
1971        reading_file_from_stdin = (strcmp(utf8_opt_arg, "-") == 0);
1972        dash_F_arg = opt_arg;
1973        break;
1974      case opt_targets:
1975        {
1976          svn_stringbuf_t *buffer, *buffer_utf8;
1977
1978          /* We need to convert to UTF-8 now, even before we divide
1979             the targets into an array, because otherwise we wouldn't
1980             know what delimiter to use for svn_cstring_split().  */
1981
1982          SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
1983          SVN_INT_ERR(svn_stringbuf_from_file2(&buffer, utf8_opt_arg, pool));
1984          SVN_INT_ERR(svn_utf_stringbuf_to_utf8(&buffer_utf8, buffer, pool));
1985          opt_state.targets = svn_cstring_split(buffer_utf8->data, "\n\r",
1986                                                TRUE, pool);
1987        }
1988        break;
1989      case opt_force:
1990        opt_state.force = TRUE;
1991        break;
1992      case opt_force_log:
1993        opt_state.force_log = TRUE;
1994        break;
1995      case opt_dry_run:
1996        opt_state.dry_run = TRUE;
1997        break;
1998      case opt_revprop:
1999        opt_state.revprop = TRUE;
2000        break;
2001      case 'R':
2002        opt_state.depth = svn_depth_infinity;
2003        break;
2004      case 'N':
2005        descend = FALSE;
2006        break;
2007      case opt_depth:
2008        err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
2009        if (err)
2010          return EXIT_ERROR
2011            (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, err,
2012                               _("Error converting depth "
2013                                 "from locale to UTF-8")));
2014        opt_state.depth = svn_depth_from_word(utf8_opt_arg);
2015        if (opt_state.depth == svn_depth_unknown
2016            || opt_state.depth == svn_depth_exclude)
2017          {
2018            return EXIT_ERROR
2019              (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2020                                 _("'%s' is not a valid depth; try "
2021                                   "'empty', 'files', 'immediates', "
2022                                   "or 'infinity'"),
2023                                 utf8_opt_arg));
2024          }
2025        break;
2026      case opt_set_depth:
2027        err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
2028        if (err)
2029          return EXIT_ERROR
2030            (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, err,
2031                               _("Error converting depth "
2032                                 "from locale to UTF-8")));
2033        opt_state.set_depth = svn_depth_from_word(utf8_opt_arg);
2034        /* svn_depth_exclude is okay for --set-depth. */
2035        if (opt_state.set_depth == svn_depth_unknown)
2036          {
2037            return EXIT_ERROR
2038              (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2039                                 _("'%s' is not a valid depth; try "
2040                                   "'exclude', 'empty', 'files', "
2041                                   "'immediates', or 'infinity'"),
2042                                 utf8_opt_arg));
2043          }
2044        break;
2045      case opt_version:
2046        opt_state.version = TRUE;
2047        break;
2048      case opt_auth_username:
2049        SVN_INT_ERR(svn_utf_cstring_to_utf8(&opt_state.auth_username,
2050                                            opt_arg, pool));
2051        break;
2052      case opt_auth_password:
2053        SVN_INT_ERR(svn_utf_cstring_to_utf8(&opt_state.auth_password,
2054                                            opt_arg, pool));
2055        break;
2056      case opt_encoding:
2057        opt_state.encoding = apr_pstrdup(pool, opt_arg);
2058        break;
2059      case opt_xml:
2060        opt_state.xml = TRUE;
2061        break;
2062      case opt_stop_on_copy:
2063        opt_state.stop_on_copy = TRUE;
2064        break;
2065      case opt_strict:
2066        opt_state.strict = TRUE;
2067        break;
2068      case opt_no_ignore:
2069        opt_state.no_ignore = TRUE;
2070        break;
2071      case opt_no_auth_cache:
2072        opt_state.no_auth_cache = TRUE;
2073        break;
2074      case opt_non_interactive:
2075        opt_state.non_interactive = TRUE;
2076        break;
2077      case opt_force_interactive:
2078        force_interactive = TRUE;
2079        break;
2080      case opt_trust_server_cert:
2081        opt_state.trust_server_cert = TRUE;
2082        break;
2083      case opt_no_diff_added:
2084        opt_state.diff.no_diff_added = TRUE;
2085        break;
2086      case opt_no_diff_deleted:
2087        opt_state.diff.no_diff_deleted = TRUE;
2088        break;
2089      case opt_ignore_properties:
2090        opt_state.diff.ignore_properties = TRUE;
2091        break;
2092      case opt_show_copies_as_adds:
2093        opt_state.diff.show_copies_as_adds = TRUE;
2094        break;
2095      case opt_notice_ancestry:
2096        opt_state.diff.notice_ancestry = TRUE;
2097        break;
2098      case opt_ignore_ancestry:
2099        opt_state.ignore_ancestry = TRUE;
2100        break;
2101      case opt_ignore_externals:
2102        opt_state.ignore_externals = TRUE;
2103        break;
2104      case opt_relocate:
2105        opt_state.relocate = TRUE;
2106        break;
2107      case 'x':
2108        SVN_INT_ERR(svn_utf_cstring_to_utf8(&opt_state.extensions,
2109                                            opt_arg, pool));
2110        break;
2111      case opt_diff_cmd:
2112        opt_state.diff.diff_cmd = apr_pstrdup(pool, opt_arg);
2113        break;
2114      case opt_merge_cmd:
2115        opt_state.merge_cmd = apr_pstrdup(pool, opt_arg);
2116        break;
2117      case opt_record_only:
2118        opt_state.record_only = TRUE;
2119        break;
2120      case opt_editor_cmd:
2121        opt_state.editor_cmd = apr_pstrdup(pool, opt_arg);
2122        break;
2123      case opt_old_cmd:
2124        if (opt_state.used_change_arg)
2125          {
2126            err = svn_error_create
2127              (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2128               _("Can't specify -c with --old"));
2129            return EXIT_ERROR(err);
2130          }
2131        opt_state.old_target = apr_pstrdup(pool, opt_arg);
2132        break;
2133      case opt_new_cmd:
2134        opt_state.new_target = apr_pstrdup(pool, opt_arg);
2135        break;
2136      case opt_config_dir:
2137        {
2138          const char *path_utf8;
2139          SVN_INT_ERR(svn_utf_cstring_to_utf8(&path_utf8, opt_arg, pool));
2140          opt_state.config_dir = svn_dirent_internal_style(path_utf8, pool);
2141        }
2142        break;
2143      case opt_config_options:
2144        if (!opt_state.config_options)
2145          opt_state.config_options =
2146                   apr_array_make(pool, 1,
2147                                  sizeof(svn_cmdline__config_argument_t*));
2148
2149        SVN_INT_ERR(svn_utf_cstring_to_utf8(&opt_arg, opt_arg, pool));
2150        SVN_INT_ERR(svn_cmdline__parse_config_option(opt_state.config_options,
2151                                                     opt_arg, pool));
2152        break;
2153      case opt_autoprops:
2154        opt_state.autoprops = TRUE;
2155        break;
2156      case opt_no_autoprops:
2157        opt_state.no_autoprops = TRUE;
2158        break;
2159      case opt_native_eol:
2160        if ( !strcmp("LF", opt_arg) || !strcmp("CR", opt_arg) ||
2161             !strcmp("CRLF", opt_arg))
2162          opt_state.native_eol = apr_pstrdup(pool, opt_arg);
2163        else
2164          {
2165            SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
2166            err = svn_error_createf
2167                (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2168                 _("Syntax error in native-eol argument '%s'"),
2169                 utf8_opt_arg);
2170            return EXIT_ERROR(err);
2171          }
2172        break;
2173      case opt_no_unlock:
2174        opt_state.no_unlock = TRUE;
2175        break;
2176      case opt_summarize:
2177        opt_state.diff.summarize = TRUE;
2178        break;
2179      case opt_remove:
2180        opt_state.remove = TRUE;
2181        break;
2182      case opt_changelist:
2183        SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
2184        opt_state.changelist = utf8_opt_arg;
2185        if (opt_state.changelist[0] == '\0')
2186          {
2187            err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2188                                   _("Changelist names must not be empty"));
2189            return EXIT_ERROR(err);
2190          }
2191        svn_hash_sets(changelists, opt_state.changelist, (void *)1);
2192        break;
2193      case opt_keep_changelists:
2194        opt_state.keep_changelists = TRUE;
2195        break;
2196      case opt_keep_local:
2197        opt_state.keep_local = TRUE;
2198        break;
2199      case opt_with_all_revprops:
2200        /* If --with-all-revprops is specified along with one or more
2201         * --with-revprops options, --with-all-revprops takes precedence. */
2202        opt_state.all_revprops = TRUE;
2203        break;
2204      case opt_with_no_revprops:
2205        opt_state.no_revprops = TRUE;
2206        break;
2207      case opt_with_revprop:
2208        SVN_INT_ERR(svn_opt_parse_revprop(&opt_state.revprop_table,
2209                                          opt_arg, pool));
2210        break;
2211      case opt_parents:
2212        opt_state.parents = TRUE;
2213        break;
2214      case 'g':
2215        opt_state.use_merge_history = TRUE;
2216        break;
2217      case opt_accept:
2218        opt_state.accept_which = svn_cl__accept_from_word(opt_arg);
2219        if (opt_state.accept_which == svn_cl__accept_invalid)
2220          return EXIT_ERROR
2221            (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2222                               _("'%s' is not a valid --accept value"),
2223                               opt_arg));
2224        break;
2225      case opt_show_revs:
2226        opt_state.show_revs = svn_cl__show_revs_from_word(opt_arg);
2227        if (opt_state.show_revs == svn_cl__show_revs_invalid)
2228          return EXIT_ERROR
2229            (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2230                               _("'%s' is not a valid --show-revs value"),
2231                               opt_arg));
2232        break;
2233      case opt_reintegrate:
2234        opt_state.reintegrate = TRUE;
2235        break;
2236      case opt_strip:
2237        {
2238          err = svn_cstring_atoi(&opt_state.strip, opt_arg);
2239          if (err)
2240            {
2241              err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, err,
2242                                      _("Invalid strip count '%s'"), opt_arg);
2243              return EXIT_ERROR(err);
2244            }
2245          if (opt_state.strip < 0)
2246            {
2247              err = svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
2248                                     _("Argument to --strip must be positive"));
2249              return EXIT_ERROR(err);
2250            }
2251        }
2252        break;
2253      case opt_ignore_keywords:
2254        opt_state.ignore_keywords = TRUE;
2255        break;
2256      case opt_reverse_diff:
2257        opt_state.reverse_diff = TRUE;
2258        break;
2259      case opt_ignore_whitespace:
2260          opt_state.ignore_whitespace = TRUE;
2261          break;
2262      case opt_diff:
2263          opt_state.show_diff = TRUE;
2264          break;
2265      case opt_internal_diff:
2266        opt_state.diff.internal_diff = TRUE;
2267        break;
2268      case opt_patch_compatible:
2269        opt_state.diff.patch_compatible = TRUE;
2270        break;
2271      case opt_use_git_diff_format:
2272        opt_state.diff.use_git_diff_format = TRUE;
2273        break;
2274      case opt_allow_mixed_revisions:
2275        opt_state.allow_mixed_rev = TRUE;
2276        break;
2277      case opt_include_externals:
2278        opt_state.include_externals = TRUE;
2279        break;
2280      case opt_show_inherited_props:
2281        opt_state.show_inherited_props = TRUE;
2282        break;
2283      case opt_properties_only:
2284        opt_state.diff.properties_only = TRUE;
2285        break;
2286      case opt_search:
2287        add_search_pattern_group(&opt_state, opt_arg, pool);
2288        break;
2289      case opt_search_and:
2290        add_search_pattern_to_latest_group(&opt_state, opt_arg, pool);
2291      default:
2292        /* Hmmm. Perhaps this would be a good place to squirrel away
2293           opts that commands like svn diff might need. Hmmm indeed. */
2294        break;
2295      }
2296    }
2297
2298  /* The --non-interactive and --force-interactive options are mutually
2299   * exclusive. */
2300  if (opt_state.non_interactive && force_interactive)
2301    {
2302      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2303                             _("--non-interactive and --force-interactive "
2304                               "are mutually exclusive"));
2305      return EXIT_ERROR(err);
2306    }
2307  else
2308    opt_state.non_interactive = !svn_cmdline__be_interactive(
2309                                  opt_state.non_interactive,
2310                                  force_interactive);
2311
2312  /* Turn our hash of changelists into an array of unique ones. */
2313  SVN_INT_ERR(svn_hash_keys(&(opt_state.changelists), changelists, pool));
2314
2315  /* ### This really belongs in libsvn_client.  The trouble is,
2316     there's no one place there to run it from, no
2317     svn_client_init().  We'd have to add it to all the public
2318     functions that a client might call.  It's unmaintainable to do
2319     initialization from within libsvn_client itself, but it seems
2320     burdensome to demand that all clients call svn_client_init()
2321     before calling any other libsvn_client function... On the other
2322     hand, the alternative is effectively to demand that they call
2323     svn_config_ensure() instead, so maybe we should have a generic
2324     init function anyway.  Thoughts?  */
2325  SVN_INT_ERR(svn_config_ensure(opt_state.config_dir, pool));
2326
2327  /* If the user asked for help, then the rest of the arguments are
2328     the names of subcommands to get help on (if any), or else they're
2329     just typos/mistakes.  Whatever the case, the subcommand to
2330     actually run is svn_cl__help(). */
2331  if (opt_state.help)
2332    subcommand = svn_opt_get_canonical_subcommand2(svn_cl__cmd_table, "help");
2333
2334  /* If we're not running the `help' subcommand, then look for a
2335     subcommand in the first argument. */
2336  if (subcommand == NULL)
2337    {
2338      if (os->ind >= os->argc)
2339        {
2340          if (opt_state.version)
2341            {
2342              /* Use the "help" subcommand to handle the "--version" option. */
2343              static const svn_opt_subcommand_desc2_t pseudo_cmd =
2344                { "--version", svn_cl__help, {0}, "",
2345                  {opt_version,    /* must accept its own option */
2346                   'q',            /* brief output */
2347                   'v',            /* verbose output */
2348                   opt_config_dir  /* all commands accept this */
2349                  } };
2350
2351              subcommand = &pseudo_cmd;
2352            }
2353          else
2354            {
2355              svn_error_clear
2356                (svn_cmdline_fprintf(stderr, pool,
2357                                     _("Subcommand argument required\n")));
2358              svn_error_clear(svn_cl__help(NULL, NULL, pool));
2359              return EXIT_FAILURE;
2360            }
2361        }
2362      else
2363        {
2364          const char *first_arg = os->argv[os->ind++];
2365          subcommand = svn_opt_get_canonical_subcommand2(svn_cl__cmd_table,
2366                                                         first_arg);
2367          if (subcommand == NULL)
2368            {
2369              const char *first_arg_utf8;
2370              SVN_INT_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8,
2371                                                  first_arg, pool));
2372              svn_error_clear
2373                (svn_cmdline_fprintf(stderr, pool,
2374                                     _("Unknown subcommand: '%s'\n"),
2375                                     first_arg_utf8));
2376              svn_error_clear(svn_cl__help(NULL, NULL, pool));
2377
2378              /* Be kind to people who try 'svn undo'. */
2379              if (strcmp(first_arg_utf8, "undo") == 0)
2380                {
2381                  svn_error_clear
2382                    (svn_cmdline_fprintf(stderr, pool,
2383                                         _("Undo is done using either the "
2384                                           "'svn revert' or the 'svn merge' "
2385                                           "command.\n")));
2386                }
2387
2388              return EXIT_FAILURE;
2389            }
2390        }
2391    }
2392
2393  /* Check that the subcommand wasn't passed any inappropriate options. */
2394  for (i = 0; i < received_opts->nelts; i++)
2395    {
2396      opt_id = APR_ARRAY_IDX(received_opts, i, int);
2397
2398      /* All commands implicitly accept --help, so just skip over this
2399         when we see it. Note that we don't want to include this option
2400         in their "accepted options" list because it would be awfully
2401         redundant to display it in every commands' help text. */
2402      if (opt_id == 'h' || opt_id == '?')
2403        continue;
2404
2405      if (! svn_opt_subcommand_takes_option3(subcommand, opt_id,
2406                                             svn_cl__global_options))
2407        {
2408          const char *optstr;
2409          const apr_getopt_option_t *badopt =
2410            svn_opt_get_option_from_code2(opt_id, svn_cl__options,
2411                                          subcommand, pool);
2412          svn_opt_format_option(&optstr, badopt, FALSE, pool);
2413          if (subcommand->name[0] == '-')
2414            svn_error_clear(svn_cl__help(NULL, NULL, pool));
2415          else
2416            svn_error_clear
2417              (svn_cmdline_fprintf
2418               (stderr, pool, _("Subcommand '%s' doesn't accept option '%s'\n"
2419                                "Type 'svn help %s' for usage.\n"),
2420                subcommand->name, optstr, subcommand->name));
2421          return EXIT_FAILURE;
2422        }
2423    }
2424
2425  /* Only merge and log support multiple revisions/revision ranges. */
2426  if (subcommand->cmd_func != svn_cl__merge
2427      && subcommand->cmd_func != svn_cl__log)
2428    {
2429      if (opt_state.revision_ranges->nelts > 1)
2430        {
2431          err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2432                                 _("Multiple revision arguments "
2433                                   "encountered; can't specify -c twice, "
2434                                   "or both -c and -r"));
2435          return EXIT_ERROR(err);
2436        }
2437    }
2438
2439  /* Disallow simultaneous use of both --depth and --set-depth. */
2440  if ((opt_state.depth != svn_depth_unknown)
2441      && (opt_state.set_depth != svn_depth_unknown))
2442    {
2443      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2444                             _("--depth and --set-depth are mutually "
2445                               "exclusive"));
2446      return EXIT_ERROR(err);
2447    }
2448
2449  /* Disallow simultaneous use of both --with-all-revprops and
2450     --with-no-revprops.  */
2451  if (opt_state.all_revprops && opt_state.no_revprops)
2452    {
2453      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2454                             _("--with-all-revprops and --with-no-revprops "
2455                               "are mutually exclusive"));
2456      return EXIT_ERROR(err);
2457    }
2458
2459  /* Disallow simultaneous use of both --with-revprop and
2460     --with-no-revprops.  */
2461  if (opt_state.revprop_table && opt_state.no_revprops)
2462    {
2463      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2464                             _("--with-revprop and --with-no-revprops "
2465                               "are mutually exclusive"));
2466      return EXIT_ERROR(err);
2467    }
2468
2469  /* Disallow simultaneous use of both -m and -F, when they are
2470     both used to pass a commit message or lock comment.  ('propset'
2471     takes the property value, not a commit message, from -F.)
2472   */
2473  if (opt_state.filedata && opt_state.message
2474      && subcommand->cmd_func != svn_cl__propset)
2475    {
2476      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2477                             _("--message (-m) and --file (-F) "
2478                               "are mutually exclusive"));
2479      return EXIT_ERROR(err);
2480    }
2481
2482  /* --trust-server-cert can only be used with --non-interactive */
2483  if (opt_state.trust_server_cert && !opt_state.non_interactive)
2484    {
2485      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2486                             _("--trust-server-cert requires "
2487                               "--non-interactive"));
2488      return EXIT_ERROR(err);
2489    }
2490
2491  /* Disallow simultaneous use of both --diff-cmd and
2492     --internal-diff.  */
2493  if (opt_state.diff.diff_cmd && opt_state.diff.internal_diff)
2494    {
2495      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2496                             _("--diff-cmd and --internal-diff "
2497                               "are mutually exclusive"));
2498      return EXIT_ERROR(err);
2499    }
2500
2501  /* Ensure that 'revision_ranges' has at least one item, and make
2502     'start_revision' and 'end_revision' match that item. */
2503  if (opt_state.revision_ranges->nelts == 0)
2504    {
2505      svn_opt_revision_range_t *range = apr_palloc(pool, sizeof(*range));
2506      range->start.kind = svn_opt_revision_unspecified;
2507      range->end.kind = svn_opt_revision_unspecified;
2508      APR_ARRAY_PUSH(opt_state.revision_ranges,
2509                     svn_opt_revision_range_t *) = range;
2510    }
2511  opt_state.start_revision = APR_ARRAY_IDX(opt_state.revision_ranges, 0,
2512                                           svn_opt_revision_range_t *)->start;
2513  opt_state.end_revision = APR_ARRAY_IDX(opt_state.revision_ranges, 0,
2514                                         svn_opt_revision_range_t *)->end;
2515
2516  err = svn_config_get_config(&cfg_hash, opt_state.config_dir, pool);
2517  if (err)
2518    {
2519      /* Fallback to default config if the config directory isn't readable
2520         or is not a directory. */
2521      if (APR_STATUS_IS_EACCES(err->apr_err)
2522          || SVN__APR_STATUS_IS_ENOTDIR(err->apr_err))
2523        {
2524          svn_config_t *empty_cfg;
2525
2526          svn_handle_warning2(stderr, err, "svn: ");
2527          svn_error_clear(err);
2528          cfg_hash = apr_hash_make(pool);
2529          SVN_INT_ERR(svn_config_create2(&empty_cfg, FALSE, FALSE, pool));
2530          svn_hash_sets(cfg_hash, SVN_CONFIG_CATEGORY_CONFIG, empty_cfg);
2531          SVN_INT_ERR(svn_config_create2(&empty_cfg, FALSE, FALSE, pool));
2532          svn_hash_sets(cfg_hash, SVN_CONFIG_CATEGORY_SERVERS, empty_cfg);
2533        }
2534      else
2535        return EXIT_ERROR(err);
2536    }
2537
2538  /* Relocation is infinite-depth only. */
2539  if (opt_state.relocate)
2540    {
2541      if (opt_state.depth != svn_depth_unknown)
2542        {
2543          err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
2544                                 _("--relocate and --depth are mutually "
2545                                   "exclusive"));
2546          return EXIT_ERROR(err);
2547        }
2548      if (! descend)
2549        {
2550          err = svn_error_create(
2551                    SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
2552                    _("--relocate and --non-recursive (-N) are mutually "
2553                      "exclusive"));
2554          return EXIT_ERROR(err);
2555        }
2556    }
2557
2558  /* Only a few commands can accept a revision range; the rest can take at
2559     most one revision number. */
2560  if (subcommand->cmd_func != svn_cl__blame
2561      && subcommand->cmd_func != svn_cl__diff
2562      && subcommand->cmd_func != svn_cl__log
2563      && subcommand->cmd_func != svn_cl__mergeinfo
2564      && subcommand->cmd_func != svn_cl__merge)
2565    {
2566      if (opt_state.end_revision.kind != svn_opt_revision_unspecified)
2567        {
2568          err = svn_error_create(SVN_ERR_CLIENT_REVISION_RANGE, NULL, NULL);
2569          return EXIT_ERROR(err);
2570        }
2571    }
2572
2573  /* -N has a different meaning depending on the command */
2574  if (!descend)
2575    {
2576      if (subcommand->cmd_func == svn_cl__status)
2577        {
2578          opt_state.depth = svn_depth_immediates;
2579        }
2580      else if (subcommand->cmd_func == svn_cl__revert
2581               || subcommand->cmd_func == svn_cl__add
2582               || subcommand->cmd_func == svn_cl__commit)
2583        {
2584          /* In pre-1.5 Subversion, some commands treated -N like
2585             --depth=empty, so force that mapping here.  Anyway, with
2586             revert it makes sense to be especially conservative,
2587             since revert can lose data. */
2588          opt_state.depth = svn_depth_empty;
2589        }
2590      else
2591        {
2592          opt_state.depth = svn_depth_files;
2593        }
2594    }
2595
2596  cfg_config = svn_hash_gets(cfg_hash, SVN_CONFIG_CATEGORY_CONFIG);
2597
2598  /* Update the options in the config */
2599  if (opt_state.config_options)
2600    {
2601      svn_error_clear(
2602          svn_cmdline__apply_config_options(cfg_hash,
2603                                            opt_state.config_options,
2604                                            "svn: ", "--config-option"));
2605    }
2606
2607#if !defined(SVN_CL_NO_EXCLUSIVE_LOCK)
2608  {
2609    const char *exclusive_clients_option;
2610    apr_array_header_t *exclusive_clients;
2611
2612    svn_config_get(cfg_config, &exclusive_clients_option,
2613                   SVN_CONFIG_SECTION_WORKING_COPY,
2614                   SVN_CONFIG_OPTION_SQLITE_EXCLUSIVE_CLIENTS,
2615                   NULL);
2616    exclusive_clients = svn_cstring_split(exclusive_clients_option,
2617                                          " ,", TRUE, pool);
2618    for (i = 0; i < exclusive_clients->nelts; ++i)
2619      {
2620        const char *exclusive_client = APR_ARRAY_IDX(exclusive_clients, i,
2621                                                     const char *);
2622
2623        /* This blocks other clients from accessing the wc.db so it must
2624           be explicitly enabled.*/
2625        if (!strcmp(exclusive_client, "svn"))
2626          svn_config_set(cfg_config,
2627                         SVN_CONFIG_SECTION_WORKING_COPY,
2628                         SVN_CONFIG_OPTION_SQLITE_EXCLUSIVE,
2629                         "true");
2630      }
2631  }
2632#endif
2633
2634  /* Create a client context object. */
2635  command_baton.opt_state = &opt_state;
2636  SVN_INT_ERR(svn_client_create_context2(&ctx, cfg_hash, pool));
2637  command_baton.ctx = ctx;
2638
2639  /* If we're running a command that could result in a commit, verify
2640     that any log message we were given on the command line makes
2641     sense (unless we've also been instructed not to care).  This may
2642     access the working copy so do it after setting the locking mode. */
2643  if ((! opt_state.force_log)
2644      && (subcommand->cmd_func == svn_cl__commit
2645          || subcommand->cmd_func == svn_cl__copy
2646          || subcommand->cmd_func == svn_cl__delete
2647          || subcommand->cmd_func == svn_cl__import
2648          || subcommand->cmd_func == svn_cl__mkdir
2649          || subcommand->cmd_func == svn_cl__move
2650          || subcommand->cmd_func == svn_cl__lock
2651          || subcommand->cmd_func == svn_cl__propedit))
2652    {
2653      /* If the -F argument is a file that's under revision control,
2654         that's probably not what the user intended. */
2655      if (dash_F_arg)
2656        {
2657          svn_node_kind_t kind;
2658          const char *local_abspath;
2659          const char *fname_utf8 = svn_dirent_internal_style(dash_F_arg, pool);
2660
2661          err = svn_dirent_get_absolute(&local_abspath, fname_utf8, pool);
2662
2663          if (!err)
2664            {
2665              err = svn_wc_read_kind2(&kind, ctx->wc_ctx, local_abspath, TRUE,
2666                                      FALSE, pool);
2667
2668              if (!err && kind != svn_node_none && kind != svn_node_unknown)
2669                {
2670                  if (subcommand->cmd_func != svn_cl__lock)
2671                    {
2672                      err = svn_error_create(
2673                         SVN_ERR_CL_LOG_MESSAGE_IS_VERSIONED_FILE, NULL,
2674                         _("Log message file is a versioned file; "
2675                           "use '--force-log' to override"));
2676                    }
2677                  else
2678                    {
2679                      err = svn_error_create(
2680                         SVN_ERR_CL_LOG_MESSAGE_IS_VERSIONED_FILE, NULL,
2681                         _("Lock comment file is a versioned file; "
2682                           "use '--force-log' to override"));
2683                    }
2684                  return EXIT_ERROR(err);
2685                }
2686            }
2687          svn_error_clear(err);
2688        }
2689
2690      /* If the -m argument is a file at all, that's probably not what
2691         the user intended. */
2692      if (dash_m_arg)
2693        {
2694          apr_finfo_t finfo;
2695          if (apr_stat(&finfo, dash_m_arg,
2696                       APR_FINFO_MIN, pool) == APR_SUCCESS)
2697            {
2698              if (subcommand->cmd_func != svn_cl__lock)
2699                {
2700                  err = svn_error_create
2701                    (SVN_ERR_CL_LOG_MESSAGE_IS_PATHNAME, NULL,
2702                     _("The log message is a pathname "
2703                       "(was -F intended?); use '--force-log' to override"));
2704                }
2705              else
2706                {
2707                  err = svn_error_create
2708                    (SVN_ERR_CL_LOG_MESSAGE_IS_PATHNAME, NULL,
2709                     _("The lock comment is a pathname "
2710                       "(was -F intended?); use '--force-log' to override"));
2711                }
2712              return EXIT_ERROR(err);
2713            }
2714        }
2715    }
2716
2717  /* XXX: Only diff_cmd for now, overlay rest later and stop passing
2718     opt_state altogether? */
2719  if (opt_state.diff.diff_cmd)
2720    svn_config_set(cfg_config, SVN_CONFIG_SECTION_HELPERS,
2721                   SVN_CONFIG_OPTION_DIFF_CMD, opt_state.diff.diff_cmd);
2722  if (opt_state.merge_cmd)
2723    svn_config_set(cfg_config, SVN_CONFIG_SECTION_HELPERS,
2724                   SVN_CONFIG_OPTION_DIFF3_CMD, opt_state.merge_cmd);
2725  if (opt_state.diff.internal_diff)
2726    svn_config_set(cfg_config, SVN_CONFIG_SECTION_HELPERS,
2727                   SVN_CONFIG_OPTION_DIFF_CMD, NULL);
2728
2729  /* Check for mutually exclusive args --auto-props and --no-auto-props */
2730  if (opt_state.autoprops && opt_state.no_autoprops)
2731    {
2732      err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
2733                             _("--auto-props and --no-auto-props are "
2734                               "mutually exclusive"));
2735      return EXIT_ERROR(err);
2736    }
2737
2738  /* Update auto-props-enable option, and populate the MIME types map,
2739     for add/import commands */
2740  if (subcommand->cmd_func == svn_cl__add
2741      || subcommand->cmd_func == svn_cl__import)
2742    {
2743      const char *mimetypes_file;
2744      svn_config_get(cfg_config, &mimetypes_file,
2745                     SVN_CONFIG_SECTION_MISCELLANY,
2746                     SVN_CONFIG_OPTION_MIMETYPES_FILE, FALSE);
2747      if (mimetypes_file && *mimetypes_file)
2748        {
2749          SVN_INT_ERR(svn_io_parse_mimetypes_file(&(ctx->mimetypes_map),
2750                                                  mimetypes_file, pool));
2751        }
2752
2753      if (opt_state.autoprops)
2754        {
2755          svn_config_set_bool(cfg_config, SVN_CONFIG_SECTION_MISCELLANY,
2756                              SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS, TRUE);
2757        }
2758      if (opt_state.no_autoprops)
2759        {
2760          svn_config_set_bool(cfg_config, SVN_CONFIG_SECTION_MISCELLANY,
2761                              SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS, FALSE);
2762        }
2763    }
2764
2765  /* Update the 'keep-locks' runtime option */
2766  if (opt_state.no_unlock)
2767    svn_config_set_bool(cfg_config, SVN_CONFIG_SECTION_MISCELLANY,
2768                        SVN_CONFIG_OPTION_NO_UNLOCK, TRUE);
2769
2770  /* Set the log message callback function.  Note that individual
2771     subcommands will populate the ctx->log_msg_baton3. */
2772  ctx->log_msg_func3 = svn_cl__get_log_message;
2773
2774  /* Set up the notifier.
2775
2776     In general, we use it any time we aren't in --quiet mode.  'svn
2777     status' is unique, though, in that we don't want it in --quiet mode
2778     unless we're also in --verbose mode.  When in --xml mode,
2779     though, we never want it.  */
2780  if (opt_state.quiet)
2781    use_notifier = FALSE;
2782  if ((subcommand->cmd_func == svn_cl__status) && opt_state.verbose)
2783    use_notifier = TRUE;
2784  if (opt_state.xml)
2785    use_notifier = FALSE;
2786  if (use_notifier)
2787    {
2788      SVN_INT_ERR(svn_cl__get_notifier(&ctx->notify_func2, &ctx->notify_baton2,
2789                                       conflict_stats, pool));
2790    }
2791
2792  /* Set up our cancellation support. */
2793  ctx->cancel_func = svn_cl__check_cancel;
2794  apr_signal(SIGINT, signal_handler);
2795#ifdef SIGBREAK
2796  /* SIGBREAK is a Win32 specific signal generated by ctrl-break. */
2797  apr_signal(SIGBREAK, signal_handler);
2798#endif
2799#ifdef SIGHUP
2800  apr_signal(SIGHUP, signal_handler);
2801#endif
2802#ifdef SIGTERM
2803  apr_signal(SIGTERM, signal_handler);
2804#endif
2805
2806#ifdef SIGPIPE
2807  /* Disable SIGPIPE generation for the platforms that have it. */
2808  apr_signal(SIGPIPE, SIG_IGN);
2809#endif
2810
2811#ifdef SIGXFSZ
2812  /* Disable SIGXFSZ generation for the platforms that have it, otherwise
2813   * working with large files when compiled against an APR that doesn't have
2814   * large file support will crash the program, which is uncool. */
2815  apr_signal(SIGXFSZ, SIG_IGN);
2816#endif
2817
2818  /* Set up Authentication stuff. */
2819  SVN_INT_ERR(svn_cmdline_create_auth_baton(&ab,
2820                                            opt_state.non_interactive,
2821                                            opt_state.auth_username,
2822                                            opt_state.auth_password,
2823                                            opt_state.config_dir,
2824                                            opt_state.no_auth_cache,
2825                                            opt_state.trust_server_cert,
2826                                            cfg_config,
2827                                            ctx->cancel_func,
2828                                            ctx->cancel_baton,
2829                                            pool));
2830
2831  ctx->auth_baton = ab;
2832
2833  if (opt_state.non_interactive)
2834    {
2835      if (opt_state.accept_which == svn_cl__accept_edit)
2836        return EXIT_ERROR(
2837                 svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2838                                   _("--accept=%s incompatible with"
2839                                     " --non-interactive"),
2840                                   SVN_CL__ACCEPT_EDIT));
2841
2842      if (opt_state.accept_which == svn_cl__accept_launch)
2843        return EXIT_ERROR(
2844                 svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
2845                                   _("--accept=%s incompatible with"
2846                                     " --non-interactive"),
2847                                   SVN_CL__ACCEPT_LAUNCH));
2848
2849      /* The default action when we're non-interactive is to postpone
2850       * conflict resolution. */
2851      if (opt_state.accept_which == svn_cl__accept_unspecified)
2852        opt_state.accept_which = svn_cl__accept_postpone;
2853    }
2854
2855  /* Check whether interactive conflict resolution is disabled by
2856   * the configuration file. If no --accept option was specified
2857   * we postpone all conflicts in this case. */
2858  SVN_INT_ERR(svn_config_get_bool(cfg_config, &interactive_conflicts,
2859                                  SVN_CONFIG_SECTION_MISCELLANY,
2860                                  SVN_CONFIG_OPTION_INTERACTIVE_CONFLICTS,
2861                                  TRUE));
2862  if (!interactive_conflicts)
2863    {
2864      /* Make 'svn resolve' non-interactive. */
2865      if (subcommand->cmd_func == svn_cl__resolve)
2866        opt_state.non_interactive = TRUE;
2867
2868      /* We're not resolving conflicts interactively. If no --accept option
2869       * was provided the default behaviour is to postpone all conflicts. */
2870      if (opt_state.accept_which == svn_cl__accept_unspecified)
2871        opt_state.accept_which = svn_cl__accept_postpone;
2872    }
2873
2874  /* Install the default conflict handler. */
2875  {
2876    svn_cl__interactive_conflict_baton_t *b;
2877
2878    ctx->conflict_func = NULL;
2879    ctx->conflict_baton = NULL;
2880
2881    ctx->conflict_func2 = svn_cl__conflict_func_interactive;
2882    SVN_INT_ERR(svn_cl__get_conflict_func_interactive_baton(
2883                &b,
2884                opt_state.accept_which,
2885                ctx->config, opt_state.editor_cmd, conflict_stats,
2886                ctx->cancel_func, ctx->cancel_baton, pool));
2887    ctx->conflict_baton2 = b;
2888  }
2889
2890  /* And now we finally run the subcommand. */
2891  err = (*subcommand->cmd_func)(os, &command_baton, pool);
2892  if (err)
2893    {
2894      /* For argument-related problems, suggest using the 'help'
2895         subcommand. */
2896      if (err->apr_err == SVN_ERR_CL_INSUFFICIENT_ARGS
2897          || err->apr_err == SVN_ERR_CL_ARG_PARSING_ERROR)
2898        {
2899          err = svn_error_quick_wrap(
2900                  err, apr_psprintf(pool,
2901                                    _("Try 'svn help %s' for more information"),
2902                                    subcommand->name));
2903        }
2904      if (err->apr_err == SVN_ERR_WC_UPGRADE_REQUIRED)
2905        {
2906          err = svn_error_quick_wrap(err,
2907                                     _("Please see the 'svn upgrade' command"));
2908        }
2909
2910      if (err->apr_err == SVN_ERR_AUTHN_FAILED && opt_state.non_interactive)
2911        {
2912          err = svn_error_quick_wrap(err,
2913                                     _("Authentication failed and interactive"
2914                                       " prompting is disabled; see the"
2915                                       " --force-interactive option"));
2916          if (reading_file_from_stdin)
2917            err = svn_error_quick_wrap(err,
2918                                       _("Reading file from standard input "
2919                                         "because of -F option; this can "
2920                                         "interfere with interactive "
2921                                         "prompting"));
2922        }
2923
2924      /* Tell the user about 'svn cleanup' if any error on the stack
2925         was about locked working copies. */
2926      if (svn_error_find_cause(err, SVN_ERR_WC_LOCKED))
2927        {
2928          err = svn_error_quick_wrap(
2929                  err, _("Run 'svn cleanup' to remove locks "
2930                         "(type 'svn help cleanup' for details)"));
2931        }
2932
2933      if (err->apr_err == SVN_ERR_SQLITE_BUSY)
2934        {
2935          err = svn_error_quick_wrap(err,
2936                                     _("Another process is blocking the "
2937                                       "working copy database, or the "
2938                                       "underlying filesystem does not "
2939                                       "support file locking; if the working "
2940                                       "copy is on a network filesystem, make "
2941                                       "sure file locking has been enabled "
2942                                       "on the file server"));
2943        }
2944
2945      if (svn_error_find_cause(err, SVN_ERR_RA_CANNOT_CREATE_TUNNEL) &&
2946          (opt_state.auth_username || opt_state.auth_password))
2947        {
2948          err = svn_error_quick_wrap(
2949                  err, _("When using svn+ssh:// URLs, keep in mind that the "
2950                         "--username and --password options are ignored "
2951                         "because authentication is performed by SSH, not "
2952                         "Subversion"));
2953        }
2954
2955      /* Ensure that stdout is flushed, so the user will see any write errors.
2956         This makes sure that output is not silently lost. */
2957      err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
2958
2959      return EXIT_ERROR(err);
2960    }
2961  else
2962    {
2963      /* Ensure that stdout is flushed, so the user will see any write errors.
2964         This makes sure that output is not silently lost. */
2965      SVN_INT_ERR(svn_cmdline_fflush(stdout));
2966
2967      return EXIT_SUCCESS;
2968    }
2969}
2970
2971int
2972main(int argc, const char *argv[])
2973{
2974  apr_pool_t *pool;
2975  int exit_code;
2976
2977  /* Initialize the app. */
2978  if (svn_cmdline_init("svn", stderr) != EXIT_SUCCESS)
2979    return EXIT_FAILURE;
2980
2981  /* Create our top-level pool.  Use a separate mutexless allocator,
2982   * given this application is single threaded.
2983   */
2984  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
2985
2986  exit_code = sub_main(argc, argv, pool);
2987
2988  svn_pool_destroy(pool);
2989  return exit_code;
2990}
2991