Fix typo in help text.
[svn.git] / subversion / svn / main.c
blobb3473794cce0438777ea48727375edfe91871ab9
1 /*
2 * main.c: Subversion command line client.
4 * ====================================================================
5 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ==================================================================== */
23 /*** Includes. ***/
25 #include <string.h>
26 #include <assert.h>
28 #include <apr_strings.h>
29 #include <apr_tables.h>
30 #include <apr_general.h>
31 #include <apr_signal.h>
33 #include "svn_cmdline.h"
34 #include "svn_pools.h"
35 #include "svn_wc.h"
36 #include "svn_client.h"
37 #include "svn_config.h"
38 #include "svn_string.h"
39 #include "svn_path.h"
40 #include "svn_delta.h"
41 #include "svn_diff.h"
42 #include "svn_error.h"
43 #include "svn_io.h"
44 #include "svn_opt.h"
45 #include "svn_utf.h"
46 #include "svn_auth.h"
47 #include "svn_hash.h"
48 #include "cl.h"
50 #include "svn_private_config.h"
53 /*** Option Processing ***/
55 /* Add an identifier here for long options that don't have a short
56 option. Options that have both long and short options should just
57 use the short option letter as identifier. */
58 typedef enum {
59 opt_ancestor_path = SVN_OPT_FIRST_LONGOPT_ID,
60 opt_auth_password,
61 opt_auth_username,
62 opt_autoprops,
63 opt_changelist,
64 opt_config_dir,
65 opt_diff_cmd,
66 opt_dry_run,
67 opt_editor_cmd,
68 opt_encoding,
69 opt_force_log,
70 opt_force,
71 opt_keep_changelists,
72 opt_ignore_ancestry,
73 opt_ignore_externals,
74 opt_incremental,
75 opt_merge_cmd,
76 opt_native_eol,
77 opt_new_cmd,
78 opt_no_auth_cache,
79 opt_no_autoprops,
80 opt_no_diff_deleted,
81 opt_no_ignore,
82 opt_no_unlock,
83 opt_non_interactive,
84 opt_notice_ancestry,
85 opt_old_cmd,
86 opt_record_only,
87 opt_relocate,
88 opt_remove,
89 opt_revprop,
90 opt_stop_on_copy,
91 opt_strict,
92 opt_summarize,
93 opt_targets,
94 opt_depth,
95 opt_set_depth,
96 opt_version,
97 opt_xml,
98 opt_keep_local,
99 opt_with_revprop,
100 opt_with_all_revprops,
101 opt_parents,
102 opt_accept,
103 opt_from_source,
104 opt_reintegrate
105 } svn_cl__longopt_t;
107 /* Option codes and descriptions for the command line client.
109 * The entire list must be terminated with an entry of nulls.
111 const apr_getopt_option_t svn_cl__options[] =
113 {"force", opt_force, 0, N_("force operation to run")},
114 {"force-log", opt_force_log, 0,
115 N_("force validity of log message source")},
116 {"help", 'h', 0, N_("show help on a subcommand")},
117 {NULL, '?', 0, N_("show help on a subcommand")},
118 {"message", 'm', 1, N_("specify log message ARG")},
119 {"quiet", 'q', 0, N_("print nothing, or only summary information")},
120 {"recursive", 'R', 0, N_("descend recursively, same as --depth=infinity")},
121 {"non-recursive", 'N', 0, N_("obsolete; try --depth=files or --depth=immediates")},
122 {"change", 'c', 1, N_
123 ("the change made by revision ARG (like -r ARG-1:ARG)\n"
124 " If ARG is negative this is like -r ARG:ARG-1")
126 {"revision", 'r', 1, N_
127 ("ARG (some commands also take ARG1:ARG2 range)\n"
128 " A revision argument can be one of:\n"
129 " NUMBER revision number\n"
130 " '{' DATE '}' revision at start of the date\n"
131 " 'HEAD' latest in repository\n"
132 " 'BASE' base rev of item's working copy\n"
133 " 'COMMITTED' last commit at or before BASE\n"
134 " 'PREV' revision just before COMMITTED")
135 /* spacing corresponds to svn_opt_format_option */
137 {"file", 'F', 1, N_("read log message from file ARG")},
138 {"incremental", opt_incremental, 0,
139 N_("give output suitable for concatenation")},
140 #ifndef AS400
141 {"encoding", opt_encoding, 1,
142 N_("treat value as being in charset encoding ARG")},
143 #endif
144 {"version", opt_version, 0, N_("show program version information")},
145 {"verbose", 'v', 0, N_("print extra information")},
146 {"show-updates", 'u', 0, N_("display update information")},
147 {"username", opt_auth_username, 1, N_("specify a username ARG")},
148 {"password", opt_auth_password, 1, N_("specify a password ARG")},
149 #ifndef AS400
150 {"extensions", 'x', 1,
151 N_("Default: '-u'. When Subversion is invoking an\n"
153 " external diff program, ARG is simply passed along\n"
155 " to the program. But when Subversion is using its\n"
157 " default internal diff implementation, or when\n"
159 " Subversion is displaying blame annotations, ARG\n"
161 " could be any of the following:\n"
163 " -u (--unified):\n"
165 " Output 3 lines of unified context.\n"
167 " -b (--ignore-space-change):\n"
169 " Ignore changes in the amount of white space.\n"
171 " -w (--ignore-all-space):\n"
173 " Ignore all white space.\n"
175 " --ignore-eol-style:\n"
177 " Ignore changes in EOL style\n"
179 " -p (--show-c-function):\n"
181 " Show C function name in diff output.")},
182 #endif
183 {"targets", opt_targets, 1,
184 N_("pass contents of file ARG as additional args")},
185 {"depth", opt_depth, 1,
186 N_("limit operation by depth ARG ('empty', 'files',\n"
188 "'immediates', or 'infinity')")},
189 {"set-depth", opt_set_depth, 1,
190 N_("set new working copy depth to ARG ('empty',\n"
192 "'files', 'immediates', or 'infinity')")},
193 {"xml", opt_xml, 0, N_("output in XML")},
194 {"strict", opt_strict, 0, N_("use strict semantics")},
195 {"stop-on-copy", opt_stop_on_copy, 0,
196 N_("do not cross copies while traversing history")},
197 {"no-ignore", opt_no_ignore, 0,
198 N_("disregard default and svn:ignore property ignores")},
199 {"no-auth-cache", opt_no_auth_cache, 0,
200 N_("do not cache authentication tokens")},
201 {"non-interactive", opt_non_interactive, 0,
202 N_("do no interactive prompting")},
203 {"dry-run", opt_dry_run, 0,
204 N_("try operation but make no changes")},
205 {"no-diff-deleted", opt_no_diff_deleted, 0,
206 N_("do not print differences for deleted files")},
207 {"notice-ancestry", opt_notice_ancestry, 0,
208 N_("notice ancestry when calculating differences")},
209 {"ignore-ancestry", opt_ignore_ancestry, 0,
210 N_("ignore ancestry when calculating merges")},
211 {"ignore-externals", opt_ignore_externals, 0,
212 N_("ignore externals definitions")},
213 #ifndef AS400
214 {"diff-cmd", opt_diff_cmd, 1, N_("use ARG as diff command")},
215 {"diff3-cmd", opt_merge_cmd, 1, N_("use ARG as merge command")},
216 {"editor-cmd", opt_editor_cmd, 1, N_("use ARG as external editor")},
217 #endif
218 {"record-only", opt_record_only, 0,
219 N_("mark revisions as merged (use with -r)")},
220 {"old", opt_old_cmd, 1, N_("use ARG as the older target")},
221 {"new", opt_new_cmd, 1, N_("use ARG as the newer target")},
222 {"revprop", opt_revprop, 0,
223 N_("operate on a revision property (use with -r)")},
224 {"relocate", opt_relocate, 0, N_("relocate via URL-rewriting")},
225 {"config-dir", opt_config_dir, 1,
226 N_("read user configuration files from directory ARG")},
227 {"auto-props", opt_autoprops, 0, N_("enable automatic properties")},
228 {"no-auto-props", opt_no_autoprops, 0, N_("disable automatic properties")},
229 {"native-eol", opt_native_eol, 1,
230 N_("use a different EOL marker than the standard\n"
232 "system marker for files with the svn:eol-style\n"
234 "property set to 'native'.\n"
236 "ARG may be one of 'LF', 'CR', 'CRLF'")},
237 {"limit", 'l', 1, N_("maximum number of log entries")},
238 {"no-unlock", opt_no_unlock, 0, N_("don't unlock the targets")},
239 {"summarize", opt_summarize, 0, N_("show a summary of the results")},
240 {"remove", opt_remove, 0, N_("remove changelist association")},
241 {"changelist", opt_changelist, 1,
242 N_("operate only on members of changelist ARG\n"
244 "[aliases: --cl]")},
245 {"keep-changelists", opt_keep_changelists, 0,
246 N_("don't delete changelists after commit")},
247 {"keep-local", opt_keep_local, 0, N_("keep path in working copy")},
248 {"with-all-revprops", opt_with_all_revprops, 0,
249 N_("retrieve all revision properties")},
250 {"with-revprop", opt_with_revprop, 1,
251 N_("set revision property ARG in new revision\n"
253 "using the name[=value] format")},
254 {"parents", opt_parents, 0, N_("make intermediate directories")},
255 {"use-merge-history", 'g', 0,
256 N_("use/display additional information from merge\n"
258 "history")},
259 {"accept", opt_accept, 1,
260 N_("specify automatic conflict resolution action\n"
262 "('" SVN_CL__ACCEPT_POSTPONE "',"
263 " '" SVN_CL__ACCEPT_BASE "',"
264 /* These two are not implemented yet, so don't
265 waste the user's time with them. */
266 /* " '" SVN_CL__ACCEPT_MINE_CONFLICT "'," */
267 /* " '" SVN_CL__ACCEPT_THEIRS_CONFLICT "'," */
268 " '" SVN_CL__ACCEPT_MINE_FULL "',"
269 " '" SVN_CL__ACCEPT_THEIRS_FULL "',"
270 "\n "
271 " '" SVN_CL__ACCEPT_EDIT "',"
272 " '" SVN_CL__ACCEPT_LAUNCH "')")},
273 {"from-source", opt_from_source, 1,
274 N_("query a particular merge source URL")},
275 {"reintegrate", opt_reintegrate, 0,
276 N_("lump-merge all of source URL's unmerged changes")},
278 /* Long-opt Aliases
280 * These have NULL desriptions, but an option code that matches some
281 * other option (whose description should probably mention its aliases).
284 {"cl", opt_changelist, 1, NULL},
286 {0, 0, 0, 0},
291 /*** Command dispatch. ***/
293 /* Our array of available subcommands.
295 * The entire list must be terminated with an entry of nulls.
297 * In most of the help text "PATH" is used where a working copy path is
298 * required, "URL" where a repository URL is required and "TARGET" when
299 * either a path or an url can be used. Hmm, should this be part of the
300 * help text?
303 /* Options that apply to all commands. (While not every command may
304 currently require authentication or be interactive, allowing every
305 command to take these arguments allows scripts to just pass them
306 willy-nilly to every invocation of 'svn') . */
307 const int svn_cl__global_options[] =
308 { opt_auth_username, opt_auth_password, opt_no_auth_cache, opt_non_interactive,
309 opt_config_dir, 0
312 /* Options for giving a log message. (Some of these also have other uses.)
314 #define SVN_CL__LOG_MSG_OPTIONS 'm', 'F', \
315 opt_force_log, \
316 opt_editor_cmd, \
317 opt_encoding, \
318 opt_with_revprop
320 const svn_opt_subcommand_desc2_t svn_cl__cmd_table[] =
322 { "add", svn_cl__add, {0}, N_
323 ("Put files and directories under version control, scheduling\n"
324 "them for addition to repository. They will be added in next commit.\n"
325 "usage: add PATH...\n"),
326 {opt_targets, 'N', opt_depth, 'q', opt_force, opt_no_ignore, opt_autoprops,
327 opt_no_autoprops, opt_parents },
328 {{opt_parents, N_("add intermediate parents")}} },
330 { "blame", svn_cl__blame, {"praise", "annotate", "ann"}, N_
331 ("Output the content of specified files or\n"
332 "URLs with revision and author information in-line.\n"
333 "usage: blame TARGET[@REV]...\n"
334 "\n"
335 " If specified, REV determines in which revision the target is first\n"
336 " looked up.\n"),
337 {'r', 'v', 'g', opt_incremental, opt_xml, 'x', opt_force} },
339 { "cat", svn_cl__cat, {0}, N_
340 ("Output the content of specified files or URLs.\n"
341 "usage: cat TARGET[@REV]...\n"
342 "\n"
343 " If specified, REV determines in which revision the target is first\n"
344 " looked up.\n"),
345 {'r'} },
347 { "changelist", svn_cl__changelist, {"cl"}, N_
348 ("Associate (or dissociate) changelist CLNAME with the named files.\n"
349 "usage: 1. changelist CLNAME TARGET...\n"
350 " 2. changelist --remove TARGET...\n"),
351 { 'q', 'R', opt_depth, opt_remove, opt_targets, opt_changelist} },
353 { "checkout", svn_cl__checkout, {"co"}, N_
354 ("Check out a working copy from a repository.\n"
355 "usage: checkout URL[@REV]... [PATH]\n"
356 "\n"
357 " If specified, REV determines in which revision the URL is first\n"
358 " looked up.\n"
359 "\n"
360 " If PATH is omitted, the basename of the URL will be used as\n"
361 " the destination. If multiple URLs are given each will be checked\n"
362 " out into a sub-directory of PATH, with the name of the sub-directory\n"
363 " being the basename of the URL.\n"
364 "\n"
365 " If --force is used, unversioned obstructing paths in the working\n"
366 " copy destination do not automatically cause the check out to fail.\n"
367 " If the obstructing path is the same type (file or directory) as the\n"
368 " corresponding path in the repository it becomes versioned but its\n"
369 " contents are left 'as-is' in the working copy. This means that an\n"
370 " obstructing directory's unversioned children may also obstruct and\n"
371 " become versioned. For files, any content differences between the\n"
372 " obstruction and the repository are treated like a local modification\n"
373 " to the working copy. All properties from the repository are applied\n"
374 " to the obstructing path.\n"),
375 {'r', 'q', 'N', opt_depth, opt_force, opt_ignore_externals, opt_accept} },
377 { "cleanup", svn_cl__cleanup, {0}, N_
378 ("Recursively clean up the working copy, removing locks, resuming\n"
379 "unfinished operations, etc.\n"
380 "usage: cleanup [PATH...]\n"),
381 {opt_merge_cmd} },
383 { "commit", svn_cl__commit, {"ci"},
384 #ifndef AS400
385 N_("Send changes from your working copy to the repository.\n"
386 "usage: commit [PATH...]\n"
387 "\n"
388 " A log message must be provided, but it can be empty. If it is not\n"
389 " given by a --message or --file option, an editor will be started.\n"
390 " If any targets are (or contain) locked items, those will be\n"
391 " unlocked after a successful commit.\n"),
392 #else
393 N_("Send changes from your working copy to the repository.\n"
394 "usage: commit [PATH...]\n"
395 "\n"
396 " A log message must be provided, but it can be empty.\n"
397 " OS400 does not support the starting of an editor,\n"
398 " so --message or --file must be used. If any targets are\n"
399 " (or contain) locked items, those will be unlocked after a\n"
400 " successful commit.\n"),
401 #endif
402 {'q', 'N', opt_depth, opt_targets, opt_no_unlock, SVN_CL__LOG_MSG_OPTIONS,
403 opt_changelist, opt_keep_changelists} },
405 { "copy", svn_cl__copy, {"cp"}, N_
406 ("Duplicate something in working copy or repository, remembering\n"
407 "history.\n"
408 "usage: copy SRC[@REV]... DST\n"
409 "\n"
410 "When copying multiple sources, they will be added as children of DST,\n"
411 "which must be a directory.\n"
412 "\n"
413 " SRC and DST can each be either a working copy (WC) path or URL:\n"
414 " WC -> WC: copy and schedule for addition (with history)\n"
415 " WC -> URL: immediately commit a copy of WC to URL\n"
416 " URL -> WC: check out URL into WC, schedule for addition\n"
417 " URL -> URL: complete server-side copy; used to branch and tag\n"
418 " All the SRCs must be of the same type.\n"
419 "\n"
420 "WARNING: For compatibility with previous versions of Subversion,\n"
421 "copies performed using two working copy paths (WC -> WC) will not\n"
422 "contact the repository. As such, they may not, by default, be able\n"
423 "to propagate merge tracking information from the source of the copy\n"
424 "to the destination.\n"),
425 {'r', 'q', opt_parents, SVN_CL__LOG_MSG_OPTIONS} },
427 { "delete", svn_cl__delete, {"del", "remove", "rm"}, N_
428 ("Remove files and directories from version control.\n"
429 "usage: 1. delete PATH...\n"
430 " 2. delete URL...\n"
431 "\n"
432 " 1. Each item specified by a PATH is scheduled for deletion upon\n"
433 " the next commit. Files, and directories that have not been\n"
434 " committed, are immediately removed from the working copy\n"
435 " unless the --keep-local option is given.\n"
436 " PATHs that are, or contain, unversioned or modified items will\n"
437 " not be removed unless the --force option is given.\n"
438 "\n"
439 " 2. Each item specified by a URL is deleted from the repository\n"
440 " via an immediate commit.\n"),
441 {opt_force, 'q', opt_targets, SVN_CL__LOG_MSG_OPTIONS, opt_keep_local} },
443 { "diff", svn_cl__diff, {"di"}, N_
444 ("Display the differences between two revisions or paths.\n"
445 "usage: 1. diff [-c M | -r N[:M]] [TARGET[@REV]...]\n"
446 " 2. diff [-r N[:M]] --old=OLD-TGT[@OLDREV] [--new=NEW-TGT[@NEWREV]] \\\n"
447 " [PATH...]\n"
448 " 3. diff OLD-URL[@OLDREV] NEW-URL[@NEWREV]\n"
449 "\n"
450 " 1. Display the changes made to TARGETs as they are seen in REV between\n"
451 " two revisions. TARGETs may be all working copy paths or all URLs.\n"
452 " If TARGETs are working copy paths, N defaults to BASE and M to the\n"
453 " working copy; if URLs, N must be specified and M defaults to HEAD.\n"
454 " The '-c M' option is equivalent to '-r N:M' where N = M-1.\n"
455 " Using '-c -M' does the reverse: '-r M:N' where N = M-1.\n"
456 "\n"
457 " 2. Display the differences between OLD-TGT as it was seen in OLDREV and\n"
458 " NEW-TGT as it was seen in NEWREV. PATHs, if given, are relative to\n"
459 " OLD-TGT and NEW-TGT and restrict the output to differences for those\n"
460 " paths. OLD-TGT and NEW-TGT may be working copy paths or URL[@REV].\n"
461 " NEW-TGT defaults to OLD-TGT if not specified. -r N makes OLDREV default\n"
462 " to N, -r N:M makes OLDREV default to N and NEWREV default to M.\n"
463 "\n"
464 " 3. Shorthand for 'svn diff --old=OLD-URL[@OLDREV] --new=NEW-URL[@NEWREV]'\n"
465 "\n"
466 " Use just 'svn diff' to display local modifications in a working copy.\n"),
467 {'r', 'c', opt_old_cmd, opt_new_cmd, 'N', opt_depth, opt_diff_cmd, 'x',
468 opt_no_diff_deleted, opt_notice_ancestry, opt_summarize, opt_changelist,
469 opt_force, opt_xml} },
471 { "export", svn_cl__export, {0}, N_
472 ("Create an unversioned copy of a tree.\n"
473 "usage: 1. export [-r REV] URL[@PEGREV] [PATH]\n"
474 " 2. export [-r REV] PATH1[@PEGREV] [PATH2]\n"
475 "\n"
476 " 1. Exports a clean directory tree from the repository specified by\n"
477 " URL, at revision REV if it is given, otherwise at HEAD, into\n"
478 " PATH. If PATH is omitted, the last component of the URL is used\n"
479 " for the local directory name.\n"
480 "\n"
481 " 2. Exports a clean directory tree from the working copy specified by\n"
482 " PATH1, at revision REV if it is given, otherwise at WORKING, into\n"
483 " PATH2. If PATH2 is omitted, the last component of the PATH1 is used\n"
484 " for the local directory name. If REV is not specified, all local\n"
485 " changes will be preserved. Files not under version control will\n"
486 " not be copied.\n"
487 "\n"
488 " If specified, PEGREV determines in which revision the target is first\n"
489 " looked up.\n"),
490 {'r', 'q', 'N', opt_depth, opt_force, opt_native_eol, opt_ignore_externals} },
492 { "help", svn_cl__help, {"?", "h"}, N_
493 ("Describe the usage of this program or its subcommands.\n"
494 "usage: help [SUBCOMMAND...]\n"),
495 {0} },
496 /* This command is also invoked if we see option "--help", "-h" or "-?". */
498 { "import", svn_cl__import, {0}, N_
499 ("Commit an unversioned file or tree into the repository.\n"
500 "usage: import [PATH] URL\n"
501 "\n"
502 " Recursively commit a copy of PATH to URL.\n"
503 " If PATH is omitted '.' is assumed.\n"
504 " Parent directories are created as necessary in the repository.\n"
505 " If PATH is a directory, the contents of the directory are added\n"
506 " directly under URL.\n"
507 " Unversionable items such as device files and pipes are ignored\n"
508 " if --force is specified.\n"),
509 {'q', 'N', opt_depth, opt_autoprops, opt_force, opt_no_autoprops,
510 SVN_CL__LOG_MSG_OPTIONS, opt_no_ignore} },
512 { "info", svn_cl__info, {0}, N_
513 ("Display information about a local or remote item.\n"
514 "usage: info [TARGET[@REV]...]\n"
515 "\n"
516 " Print information about each TARGET (default: '.')\n"
517 " TARGET may be either a working-copy path or URL. If specified, REV\n"
518 " determines in which revision the target is first looked up.\n"),
519 {'r', 'R', opt_depth, opt_targets, opt_incremental, opt_xml, opt_changelist}
522 { "list", svn_cl__list, {"ls"}, N_
523 ("List directory entries in the repository.\n"
524 "usage: list [TARGET[@REV]...]\n"
525 "\n"
526 " List each TARGET file and the contents of each TARGET directory as\n"
527 " they exist in the repository. If TARGET is a working copy path, the\n"
528 " corresponding repository URL will be used. If specified, REV determines\n"
529 " in which revision the target is first looked up.\n"
530 "\n"
531 " The default TARGET is '.', meaning the repository URL of the current\n"
532 " working directory.\n"
533 "\n"
534 " With --verbose, the following fields will be shown for each item:\n"
535 "\n"
536 " Revision number of the last commit\n"
537 " Author of the last commit\n"
538 " If locked, the letter 'O'. (Use 'svn info URL' to see details)\n"
539 " Size (in bytes)\n"
540 " Date and time of the last commit\n"),
541 {'r', 'v', 'R', opt_depth, opt_incremental, opt_xml} },
543 { "lock", svn_cl__lock, {0}, N_
544 ("Lock working copy paths or URLs in the repository, so that\n"
545 "no other user can commit changes to them.\n"
546 "usage: lock TARGET...\n"
547 "\n"
548 " Use --force to steal the lock from another user or working copy.\n"),
549 { opt_targets, 'm', 'F', opt_force_log, opt_encoding, opt_force },
550 {{'F', N_("read lock comment from file ARG")},
551 {'m', N_("specify lock comment ARG")},
552 {opt_force_log, N_("force validity of lock comment source")}} },
554 { "log", svn_cl__log, {0}, N_
555 ("Show the log messages for a set of revision(s) and/or file(s).\n"
556 "usage: 1. log [PATH]\n"
557 " 2. log URL[@REV] [PATH...]\n"
558 "\n"
559 " 1. Print the log messages for a local PATH (default: '.').\n"
560 " The default revision range is BASE:1.\n"
561 "\n"
562 " 2. Print the log messages for the PATHs (default: '.') under URL.\n"
563 " If specified, REV determines in which revision the URL is first\n"
564 " looked up. The default revision range is HEAD:1.\n"
565 "\n"
566 " With -v, also print all affected paths with each log message.\n"
567 " With -q, don't print the log message body itself (note that this is\n"
568 " compatible with -v).\n"
569 "\n"
570 " Each log message is printed just once, even if more than one of the\n"
571 " affected paths for that revision were explicitly requested. Logs\n"
572 " follow copy history by default. Use --stop-on-copy to disable this\n"
573 " behavior, which can be useful for determining branchpoints.\n"
574 "\n"
575 " Examples:\n"
576 " svn log\n"
577 " svn log foo.c\n"
578 " svn log http://www.example.com/repo/project/foo.c\n"
579 " svn log http://www.example.com/repo/project foo.c bar.c\n"),
580 {'r', 'q', 'v', 'g', 'c', opt_targets, opt_stop_on_copy, opt_incremental,
581 opt_xml, 'l', opt_with_all_revprops, opt_with_revprop},
582 {{opt_with_revprop, N_("retrieve revision property ARG")},
583 {'c', N_("the change made by ARG")}} },
585 { "merge", svn_cl__merge, {0}, N_
586 ("Apply the differences between two sources to a working copy path.\n"
587 "usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]\n"
588 " 2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]\n"
589 " 3. merge [-c M[,N]... | -r N:M...] SOURCE[@REV] [WCPATH]\n"
590 "\n"
591 " 1. In the first form, the source URLs are specified at revisions\n"
592 " N and M. These are the two sources to be compared. The revisions\n"
593 " default to HEAD if omitted.\n"
594 "\n"
595 " 2. In the second form, the URLs corresponding to the source working\n"
596 " copy paths define the sources to be compared. The revisions must\n"
597 " be specified.\n"
598 "\n"
599 " 3. In the third form, SOURCE can be either a URL or a working copy\n"
600 " path (in which case its corresponding URL is used). SOURCE (in\n"
601 " revision REV) is compared as it existed between revisions N and M\n"
602 " for each revision range provided. If REV is not specified, HEAD\n"
603 " is assumed. '-c M' is equivalent to '-r <M-1>:M', and '-c -M'\n"
604 " does the reverse: '-r M:<M-1>'. If no revision ranges are\n"
605 " specified, the default range of 1:HEAD is used. Multiple '-c'\n"
606 " and/or '-r' instances may be specified, and mixing of forward\n"
607 " and reverse ranges is allowed.\n"
608 "\n"
609 " WCPATH is the working copy path that will receive the changes.\n"
610 " If WCPATH is omitted, a default value of '.' is assumed, unless\n"
611 " the sources have identical basenames that match a file within '.':\n"
612 " in which case, the differences will be applied to that file.\n"
613 "\n"
614 " NOTE: Subversion will only internally track metadata about the\n"
615 " merge operation if the two sources are ancestrally related -- if the\n"
616 " first source is an ancestor of the second, or vice-versa. This is\n"
617 " guaranteed to be the case when using the third form listed above.\n"),
618 {'r', 'c', 'N', opt_depth, 'q', opt_force, opt_dry_run, opt_merge_cmd,
619 opt_record_only, 'x', opt_ignore_ancestry, opt_accept, opt_reintegrate} },
621 { "mergeinfo", svn_cl__mergeinfo, {0}, N_
622 ("Query merge-related information.\n"
623 "usage: mergeinfo [TARGET[@REV]...]\n"),
624 {'r', opt_from_source} },
626 { "mkdir", svn_cl__mkdir, {0}, N_
627 ("Create a new directory under version control.\n"
628 "usage: 1. mkdir PATH...\n"
629 " 2. mkdir URL...\n"
630 "\n"
631 " Create version controlled directories.\n"
632 "\n"
633 " 1. Each directory specified by a working copy PATH is created locally\n"
634 " and scheduled for addition upon the next commit.\n"
635 "\n"
636 " 2. Each directory specified by a URL is created in the repository via\n"
637 " an immediate commit.\n"
638 "\n"
639 " In both cases, all the intermediate directories must already exist,\n"
640 " unless the --parents option is given.\n"),
641 {'q', opt_parents, SVN_CL__LOG_MSG_OPTIONS} },
643 { "move", svn_cl__move, {"mv", "rename", "ren"}, N_
644 ("Move and/or rename something in working copy or repository.\n"
645 "usage: move SRC... DST\n"
646 "\n"
647 "When moving multiple sources, they will be added as children of DST,\n"
648 "which must be a directory.\n"
649 "\n"
650 " Note: this subcommand is equivalent to a 'copy' and 'delete'.\n"
651 " Note: the --revision option has no use and is deprecated.\n"
652 "\n"
653 " SRC and DST can both be working copy (WC) paths or URLs:\n"
654 " WC -> WC: move and schedule for addition (with history)\n"
655 " URL -> URL: complete server-side rename.\n"
656 " All the SRCs must be of the same type.\n"),
657 {'r', 'q', opt_force, opt_parents, SVN_CL__LOG_MSG_OPTIONS} },
659 { "propdel", svn_cl__propdel, {"pdel", "pd"}, N_
660 ("Remove a property from files, dirs, or revisions.\n"
661 "usage: 1. propdel PROPNAME [PATH...]\n"
662 " 2. propdel PROPNAME --revprop -r REV [TARGET]\n"
663 "\n"
664 " 1. Removes versioned props in working copy.\n"
665 " 2. Removes unversioned remote prop on repos revision.\n"
666 " TARGET only determines which repository to access.\n"),
667 {'q', 'R', opt_depth, 'r', opt_revprop, opt_changelist} },
669 #ifndef AS400
670 { "propedit", svn_cl__propedit, {"pedit", "pe"}, N_
671 ("Edit a property with an external editor.\n"
672 "usage: 1. propedit PROPNAME TARGET...\n"
673 " 2. propedit PROPNAME --revprop -r REV [TARGET]\n"
674 "\n"
675 " 1. Edits versioned prop in working copy or repository.\n"
676 " 2. Edits unversioned remote prop on repos revision.\n"
677 " TARGET only determines which repository to access.\n"
678 "\n"
679 "See 'svn help propset' for more on property setting.\n"),
680 {'r', opt_revprop, SVN_CL__LOG_MSG_OPTIONS, opt_force} },
681 #endif
683 { "propget", svn_cl__propget, {"pget", "pg"}, N_
684 ("Print the value of a property on files, dirs, or revisions.\n"
685 "usage: 1. propget PROPNAME [TARGET[@REV]...]\n"
686 " 2. propget PROPNAME --revprop -r REV [TARGET]\n"
687 "\n"
688 " 1. Prints versioned props. If specified, REV determines in which\n"
689 " revision the target is first looked up.\n"
690 " 2. Prints unversioned remote prop on repos revision.\n"
691 " TARGET only determines which repository to access.\n"
692 "\n"
693 " By default, this subcommand will add an extra newline to the end\n"
694 " of the property values so that the output looks pretty. Also,\n"
695 " whenever there are multiple paths involved, each property value\n"
696 " is prefixed with the path with which it is associated. Use\n"
697 " the --strict option to disable these beautifications (useful,\n"
698 " for example, when redirecting binary property values to a file).\n"),
699 {'R', opt_depth, 'r', opt_revprop, opt_strict, opt_xml, opt_changelist } },
701 { "proplist", svn_cl__proplist, {"plist", "pl"}, N_
702 ("List all properties on files, dirs, or revisions.\n"
703 "usage: 1. proplist [TARGET[@REV]...]\n"
704 " 2. proplist --revprop -r REV [TARGET]\n"
705 "\n"
706 " 1. Lists versioned props. If specified, REV determines in which\n"
707 " revision the target is first looked up.\n"
708 " 2. Lists unversioned remote props on repos revision.\n"
709 " TARGET only determines which repository to access.\n"),
710 {'v', 'R', opt_depth, 'r', 'q', opt_revprop, opt_xml, opt_changelist } },
712 { "propset", svn_cl__propset, {"pset", "ps"}, N_
713 ("Set the value of a property on files, dirs, or revisions.\n"
714 "usage: 1. propset PROPNAME PROPVAL PATH...\n"
715 " 2. propset PROPNAME --revprop -r REV PROPVAL [TARGET]\n"
716 "\n"
717 " 1. Creates a versioned, local propchange in working copy.\n"
718 " 2. Creates an unversioned, remote propchange on repos revision.\n"
719 " TARGET only determines which repository to access.\n"
720 "\n"
721 " The value may be provided with the --file option instead of PROPVAL.\n"
722 "\n"
723 " Note: svn recognizes the following special versioned properties\n"
724 " but will store any arbitrary properties set:\n"
725 " svn:ignore - A newline separated list of file glob patterns to ignore.\n"
726 " svn:keywords - Keywords to be expanded. Valid keywords are:\n"
727 " URL, HeadURL - The URL for the head version of the object.\n"
728 " Author, LastChangedBy - The last person to modify the file.\n"
729 " Date, LastChangedDate - The date/time the object was last modified.\n"
730 " Rev, Revision, - The last revision the object changed.\n"
731 " LastChangedRevision\n"
732 " Id - A compressed summary of the previous\n"
733 " 4 keywords.\n"
734 " svn:executable - If present, make the file executable. Use\n"
735 " 'svn propdel svn:executable PATH...' to clear.\n"
736 " svn:eol-style - One of 'native', 'LF', 'CR', 'CRLF'.\n"
737 " svn:mime-type - The mimetype of the file. Used to determine\n"
738 " whether to merge the file, and how to serve it from Apache.\n"
739 " A mimetype beginning with 'text/' (or an absent mimetype) is\n"
740 " treated as text. Anything else is treated as binary.\n"
741 " svn:externals - A newline separated list of module specifiers,\n"
742 " each of which consists of a relative directory path, optional\n"
743 " revision flags and an URL. The ordering of the three elements\n"
744 " implements different behavior. Subversion 1.4 and earlier only\n"
745 " support the following formats and the URLs cannot have peg\n"
746 " revisions:\n"
747 " foo http://example.com/repos/zig\n"
748 " foo/bar -r 1234 http://example.com/repos/zag\n"
749 " Subversion 1.5 and greater support the above formats and the\n"
750 " following formats where the URLs may have peg revisions:\n"
751 " http://example.com/repos/zig foo\n"
752 " -r 1234 http://example.com/repos/zig foo/bar\n"
753 " Relative URLs are supported in Subversion 1.5 and greater for\n"
754 " all above formats and are indicated by starting the URL with one\n"
755 " of the following strings\n"
756 " ../ to the parent directory of the extracted external\n"
757 " ^/ to the repository root\n"
758 " // to the scheme\n"
759 " / to the server root\n"
760 " The ambiguous format 'relative_path relative_path' is taken as\n"
761 " 'relative_url relative_path' with peg revision support.\n"
762 " svn:needs-lock - If present, indicates that the file should be locked\n"
763 " before it is modified. Makes the working copy file read-only\n"
764 " when it is not locked. Use 'svn propdel svn:needs-lock PATH...'\n"
765 " to clear.\n"
766 "\n"
767 " The svn:keywords, svn:executable, svn:eol-style, svn:mime-type and\n"
768 " svn:needs-lock properties cannot be set on a directory. A non-recursive\n"
769 " attempt will fail, and a recursive attempt will set the property\n"
770 " only on the file children of the directory.\n"),
771 {'F', opt_encoding, 'q', 'r', opt_targets, 'R', opt_depth, opt_revprop,
772 opt_force, opt_changelist },
773 {{'F', N_("read property value from file ARG")}} },
775 { "resolved", svn_cl__resolved, {0}, N_
776 ("Remove 'conflicted' state on working copy files or directories.\n"
777 "usage: resolved PATH...\n"
778 "\n"
779 " Note: this subcommand does not semantically resolve conflicts or\n"
780 " remove conflict markers; it merely removes the conflict-related\n"
781 " artifact files and allows PATH to be committed again.\n"),
782 {opt_targets, 'R', opt_depth, 'q', opt_accept},
783 {{opt_accept, N_("specify automatic conflict resolution source\n"
785 "('" SVN_CL__ACCEPT_BASE "',"
786 /* These two are not implemented yet, so
787 don't waste the user's time with them. */
788 /* " '" SVN_CL__ACCEPT_MINE_CONFLICT "'," */
789 /* " '" SVN_CL__ACCEPT_THEIRS_CONFLICT "'," */
790 " '" SVN_CL__ACCEPT_MINE_FULL "',"
791 " '" SVN_CL__ACCEPT_THEIRS_FULL "')")}} },
793 { "revert", svn_cl__revert, {0}, N_
794 ("Restore pristine working copy file (undo most local edits).\n"
795 "usage: revert PATH...\n"
796 "\n"
797 " Note: this subcommand does not require network access, and resolves\n"
798 " any conflicted states. However, it does not restore removed directories.\n"),
799 {opt_targets, 'R', opt_depth, 'q', opt_changelist} },
801 { "status", svn_cl__status, {"stat", "st"}, N_
802 ("Print the status of working copy files and directories.\n"
803 "usage: status [PATH...]\n"
804 "\n"
805 " With no args, print only locally modified items (no network access).\n"
806 " With -q, print only summary information about locally modified items.\n"
807 " With -u, add working revision and server out-of-date information.\n"
808 " With -v, print full revision information on every item.\n"
809 "\n"
810 " The first six columns in the output are each one character wide:\n"
811 " First column: Says if item was added, deleted, or otherwise changed\n"
812 " ' ' no modifications\n"
813 " 'A' Added\n"
814 " 'C' Conflicted\n"
815 " 'D' Deleted\n"
816 " 'I' Ignored\n"
817 " 'M' Modified\n"
818 " 'R' Replaced\n"
819 " 'X' item is unversioned, but is used by an externals definition\n"
820 " '?' item is not under version control\n"
821 " '!' item is missing (removed by non-svn command) or incomplete\n"
822 " '~' versioned item obstructed by some item of a different kind\n"
823 " Second column: Modifications of a file's or directory's properties\n"
824 " ' ' no modifications\n"
825 " 'C' Conflicted\n"
826 " 'M' Modified\n"
827 " Third column: Whether the working copy directory is locked\n"
828 " ' ' not locked\n"
829 " 'L' locked\n"
830 " Fourth column: Scheduled commit will contain addition-with-history\n"
831 " ' ' no history scheduled with commit\n"
832 " '+' history scheduled with commit\n"
833 " Fifth column: Whether the item is switched relative to its parent\n"
834 " ' ' normal\n"
835 " 'S' switched\n"
836 " Sixth column: Repository lock token\n"
837 " (without -u)\n"
838 " ' ' no lock token\n"
839 " 'K' lock token present\n"
840 " (with -u)\n"
841 " ' ' not locked in repository, no lock token\n"
842 " 'K' locked in repository, lock toKen present\n"
843 " 'O' locked in repository, lock token in some Other working copy\n"
844 " 'T' locked in repository, lock token present but sTolen\n"
845 " 'B' not locked in repository, lock token present but Broken\n"
846 "\n"
847 " The out-of-date information appears in the eighth column (with -u):\n"
848 " '*' a newer revision exists on the server\n"
849 " ' ' the working copy is up to date\n"
850 "\n"
851 " Remaining fields are variable width and delimited by spaces:\n"
852 " The working revision (with -u or -v)\n"
853 " The last committed revision and last committed author (with -v)\n"
854 " The working copy path is always the final field, so it can\n"
855 " include spaces.\n"
856 "\n"
857 " Example output:\n"
858 " svn status wc\n"
859 " M wc/bar.c\n"
860 " A + wc/qax.c\n"
861 "\n"
862 " svn status -u wc\n"
863 " M 965 wc/bar.c\n"
864 " * 965 wc/foo.c\n"
865 " A + 965 wc/qax.c\n"
866 " Status against revision: 981\n"
867 "\n"
868 " svn status --show-updates --verbose wc\n"
869 " M 965 938 kfogel wc/bar.c\n"
870 " * 965 922 sussman wc/foo.c\n"
871 " A + 965 687 joe wc/qax.c\n"
872 " 965 687 joe wc/zig.c\n"
873 " Status against revision: 981\n"),
874 { 'u', 'v', 'N', opt_depth, 'q', opt_no_ignore, opt_incremental, opt_xml,
875 opt_ignore_externals, opt_changelist} },
877 { "switch", svn_cl__switch, {"sw"}, N_
878 ("Update the working copy to a different URL.\n"
879 "usage: 1. switch URL[@PEGREV] [PATH]\n"
880 " 2. switch --relocate FROM TO [PATH...]\n"
881 "\n"
882 " 1. Update the working copy to mirror a new URL within the repository.\n"
883 " This behaviour is similar to 'svn update', and is the way to\n"
884 " move a working copy to a branch or tag within the same repository.\n"
885 " If specified, PEGREV determines in which revision the target is first\n"
886 " looked up.\n"
887 "\n"
888 " If --force is used, unversioned obstructing paths in the working\n"
889 " copy do not automatically cause a failure if the switch attempts to\n"
890 " add the same path. If the obstructing path is the same type (file\n"
891 " or directory) as the corresponding path in the repository it becomes\n"
892 " versioned but its contents are left 'as-is' in the working copy.\n"
893 " This means that an obstructing directory's unversioned children may\n"
894 " also obstruct and become versioned. For files, any content differences\n"
895 " between the obstruction and the repository are treated like a local\n"
896 " modification to the working copy. All properties from the repository\n"
897 " are applied to the obstructing path.\n"
898 "\n"
899 " Use the --set-depth option to set a new working copy depth on the\n"
900 " targets of this operation. Currently, the depth of a working copy\n"
901 " directory can only be increased (telescoped more deeply); you cannot\n"
902 " make a directory more shallow.\n"
903 "\n"
904 " 2. Rewrite working copy URL metadata to reflect a syntactic change only.\n"
905 " This is used when repository's root URL changes (such as a scheme\n"
906 " or hostname change) but your working copy still reflects the same\n"
907 " directory within the same repository.\n"),
908 { 'r', 'N', opt_depth, opt_set_depth, 'q', opt_merge_cmd, opt_relocate,
909 opt_ignore_externals, opt_force, opt_accept} },
911 { "unlock", svn_cl__unlock, {0}, N_
912 ("Unlock working copy paths or URLs.\n"
913 "usage: unlock TARGET...\n"
914 "\n"
915 " Use --force to break the lock.\n"),
916 { opt_targets, opt_force } },
918 { "update", svn_cl__update, {"up"}, N_
919 ("Bring changes from the repository into the working copy.\n"
920 "usage: update [PATH...]\n"
921 "\n"
922 " If no revision given, bring working copy up-to-date with HEAD rev.\n"
923 " Else synchronize working copy to revision given by -r.\n"
924 "\n"
925 " For each updated item a line will start with a character reporting the\n"
926 " action taken. These characters have the following meaning:\n"
927 "\n"
928 " A Added\n"
929 " D Deleted\n"
930 " U Updated\n"
931 " C Conflict\n"
932 " G Merged\n"
933 " E Existed\n"
934 "\n"
935 " A character in the first column signifies an update to the actual file,\n"
936 " while updates to the file's properties are shown in the second column.\n"
937 " A 'B' in the third column signifies that the lock for the file has\n"
938 " been broken or stolen.\n"
939 "\n"
940 " If --force is used, unversioned obstructing paths in the working\n"
941 " copy do not automatically cause a failure if the update attempts to\n"
942 " add the same path. If the obstructing path is the same type (file\n"
943 " or directory) as the corresponding path in the repository it becomes\n"
944 " versioned but its contents are left 'as-is' in the working copy.\n"
945 " This means that an obstructing directory's unversioned children may\n"
946 " also obstruct and become versioned. For files, any content differences\n"
947 " between the obstruction and the repository are treated like a local\n"
948 " modification to the working copy. All properties from the repository\n"
949 " are applied to the obstructing path. Obstructing paths are reported\n"
950 " in the first column with code 'E'.\n"
951 "\n"
952 " Use the --set-depth option to set a new working copy depth on the\n"
953 " targets of this operation. Currently, the depth of a working copy\n"
954 " directory can only be increased (telescoped more deeply); you cannot\n"
955 " make a directory more shallow.\n"),
956 {'r', 'N', opt_depth, opt_set_depth, 'q', opt_merge_cmd, opt_force,
957 opt_ignore_externals, opt_changelist, opt_editor_cmd, opt_accept} },
959 { NULL, NULL, {0}, NULL, {0} }
963 /* Version compatibility check */
964 static svn_error_t *
965 check_lib_versions(void)
967 static const svn_version_checklist_t checklist[] =
969 { "svn_subr", svn_subr_version },
970 { "svn_client", svn_client_version },
971 { "svn_wc", svn_wc_version },
972 { "svn_ra", svn_ra_version },
973 { "svn_delta", svn_delta_version },
974 { "svn_diff", svn_diff_version },
975 { NULL, NULL }
978 SVN_VERSION_DEFINE(my_version);
979 return svn_ver_check_list(&my_version, checklist);
983 /* A flag to see if we've been cancelled by the client or not. */
984 static volatile sig_atomic_t cancelled = FALSE;
986 /* A signal handler to support cancellation. */
987 static void
988 signal_handler(int signum)
990 apr_signal(signum, SIG_IGN);
991 cancelled = TRUE;
994 /* Our cancellation callback. */
995 svn_error_t *
996 svn_cl__check_cancel(void *baton)
998 if (cancelled)
999 return svn_error_create(SVN_ERR_CANCELLED, NULL, _("Caught signal"));
1000 else
1001 return SVN_NO_ERROR;
1006 /*** Main. ***/
1009 main(int argc, const char *argv[])
1011 svn_error_t *err;
1012 apr_allocator_t *allocator;
1013 apr_pool_t *pool;
1014 int opt_id;
1015 apr_getopt_t *os;
1016 svn_cl__opt_state_t opt_state = { 0, { 0 } };
1017 svn_client_ctx_t *ctx;
1018 apr_array_header_t *received_opts;
1019 int i;
1020 const svn_opt_subcommand_desc2_t *subcommand = NULL;
1021 const char *dash_m_arg = NULL, *dash_F_arg = NULL;
1022 const char *path_utf8;
1023 apr_status_t apr_err;
1024 svn_cl__cmd_baton_t command_baton;
1025 svn_auth_baton_t *ab;
1026 svn_config_t *cfg;
1027 svn_boolean_t descend = TRUE;
1028 svn_boolean_t interactive_conflicts = FALSE;
1029 apr_hash_t *changelists;
1031 /* Initialize the app. */
1032 if (svn_cmdline_init("svn", stderr) != EXIT_SUCCESS)
1033 return EXIT_FAILURE;
1035 /* Create our top-level pool. Use a seperate mutexless allocator,
1036 * given this application is single threaded.
1038 if (apr_allocator_create(&allocator))
1039 return EXIT_FAILURE;
1041 apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
1043 pool = svn_pool_create_ex(NULL, allocator);
1044 apr_allocator_owner_set(allocator, pool);
1046 received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));
1048 /* Check library versions */
1049 err = check_lib_versions();
1050 if (err)
1051 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1053 #if defined(WIN32) || defined(__CYGWIN__)
1054 /* Set the working copy administrative directory name. */
1055 if (getenv("SVN_ASP_DOT_NET_HACK"))
1057 err = svn_wc_set_adm_dir("_svn", pool);
1058 if (err)
1059 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1061 #endif
1063 /* Initialize the RA library. */
1064 err = svn_ra_initialize(pool);
1065 if (err)
1066 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1068 /* Init our changelists hash. */
1069 changelists = apr_hash_make(pool);
1071 /* Begin processing arguments. */
1072 opt_state.start_revision.kind = svn_opt_revision_unspecified;
1073 opt_state.end_revision.kind = svn_opt_revision_unspecified;
1074 opt_state.revision_ranges =
1075 apr_array_make(pool, 0, sizeof(svn_opt_revision_range_t *));
1076 opt_state.depth = svn_depth_unknown;
1077 opt_state.set_depth = svn_depth_unknown;
1078 opt_state.accept_which = svn_cl__accept_invalid;
1080 /* No args? Show usage. */
1081 if (argc <= 1)
1083 svn_cl__help(NULL, NULL, pool);
1084 svn_pool_destroy(pool);
1085 return EXIT_FAILURE;
1088 /* Else, parse options. */
1089 err = svn_cmdline__getopt_init(&os, argc, argv, pool);
1090 if (err)
1091 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1093 os->interleave = 1;
1094 while (1)
1096 const char *opt_arg;
1097 const char *utf8_opt_arg;
1099 /* Parse the next option. */
1100 apr_err = apr_getopt_long(os, svn_cl__options, &opt_id, &opt_arg);
1101 if (APR_STATUS_IS_EOF(apr_err))
1102 break;
1103 else if (apr_err)
1105 svn_cl__help(NULL, NULL, pool);
1106 svn_pool_destroy(pool);
1107 return EXIT_FAILURE;
1110 /* Stash the option code in an array before parsing it. */
1111 APR_ARRAY_PUSH(received_opts, int) = opt_id;
1113 switch (opt_id) {
1114 case 'l':
1116 char *end;
1117 opt_state.limit = strtol(opt_arg, &end, 10);
1118 if (end == opt_arg || *end != '\0')
1120 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1121 _("Non-numeric limit argument given"));
1122 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1124 if (opt_state.limit <= 0)
1126 err = svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
1127 _("Argument to --limit must be positive"));
1128 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1131 break;
1132 case 'm':
1133 /* Note that there's no way here to detect if the log message
1134 contains a zero byte -- if it does, then opt_arg will just
1135 be shorter than the user intended. Oh well. */
1136 opt_state.message = apr_pstrdup(pool, opt_arg);
1137 dash_m_arg = opt_arg;
1138 break;
1139 case 'c':
1141 char *end;
1142 svn_revnum_t changeno;
1143 svn_opt_revision_range_t *range;
1145 if (opt_state.old_target)
1147 err = svn_error_create
1148 (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1149 _("Can't specify -c with --old"));
1150 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1155 changeno = strtol(opt_arg, &end, 10);
1156 if (end == opt_arg || !(*end == '\0' || *end == ',') )
1158 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1159 _("Non-numeric change argument "
1160 "given to -c"));
1161 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1164 if (changeno == 0)
1166 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1167 _("There is no change 0"));
1168 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1170 opt_arg = end + 1;
1172 /* Figure out the range:
1173 -c N -> -r N-1:N
1174 -c -N -> -r N:N-1 */
1175 range = apr_palloc(pool, sizeof(*range));
1176 if (changeno > 0)
1178 range->start.value.number = changeno - 1;
1179 range->end.value.number = changeno;
1181 else
1183 changeno = -changeno;
1184 range->start.value.number = changeno;
1185 range->end.value.number = changeno - 1;
1187 opt_state.used_change_arg = TRUE;
1188 range->start.kind = svn_opt_revision_number;
1189 range->end.kind = svn_opt_revision_number;
1190 APR_ARRAY_PUSH(opt_state.revision_ranges,
1191 svn_opt_revision_range_t *) = range;
1192 } while (*end != '\0');
1194 break;
1195 case 'r':
1196 if (svn_opt_parse_revision_to_range(opt_state.revision_ranges,
1197 opt_arg, pool) != 0)
1199 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1200 if (! err)
1201 err = svn_error_createf
1202 (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1203 _("Syntax error in revision argument '%s'"),
1204 utf8_opt_arg);
1205 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1207 break;
1208 case 'v':
1209 opt_state.verbose = TRUE;
1210 break;
1211 case 'u':
1212 opt_state.update = TRUE;
1213 break;
1214 case 'h':
1215 case '?':
1216 opt_state.help = TRUE;
1217 break;
1218 case 'q':
1219 opt_state.quiet = TRUE;
1220 break;
1221 case opt_incremental:
1222 opt_state.incremental = TRUE;
1223 break;
1224 case 'F':
1225 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1226 if (! err)
1227 err = svn_stringbuf_from_file(&(opt_state.filedata),
1228 utf8_opt_arg, pool);
1229 if (err)
1230 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1231 dash_F_arg = opt_arg;
1232 break;
1233 case opt_targets:
1235 svn_stringbuf_t *buffer, *buffer_utf8;
1237 /* We need to convert to UTF-8 now, even before we divide
1238 the targets into an array, because otherwise we wouldn't
1239 know what delimiter to use for svn_cstring_split(). */
1241 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1243 if (! err)
1244 err = svn_stringbuf_from_file(&buffer, utf8_opt_arg, pool);
1245 if (! err)
1246 err = svn_utf_stringbuf_to_utf8(&buffer_utf8, buffer, pool);
1247 if (err)
1248 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1249 opt_state.targets = svn_cstring_split(buffer_utf8->data, "\n\r",
1250 TRUE, pool);
1252 break;
1253 case opt_force:
1254 opt_state.force = TRUE;
1255 break;
1256 case opt_force_log:
1257 opt_state.force_log = TRUE;
1258 break;
1259 case opt_dry_run:
1260 opt_state.dry_run = TRUE;
1261 break;
1262 case opt_revprop:
1263 opt_state.revprop = TRUE;
1264 break;
1265 case 'R':
1266 opt_state.depth = SVN_DEPTH_INFINITY_OR_FILES(TRUE);
1267 break;
1268 case 'N':
1269 descend = FALSE;
1270 break;
1271 case opt_depth:
1272 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1273 if (err)
1274 return svn_cmdline_handle_exit_error
1275 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1276 _("Error converting depth "
1277 "from locale to UTF8")), pool, "svn: ");
1278 opt_state.depth = svn_depth_from_word(utf8_opt_arg);
1279 if (opt_state.depth == svn_depth_unknown
1280 || opt_state.depth == svn_depth_exclude)
1282 return svn_cmdline_handle_exit_error
1283 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1284 _("'%s' is not a valid depth; try "
1285 "'empty', 'files', 'immediates', "
1286 "or 'infinity'"),
1287 utf8_opt_arg), pool, "svn: ");
1289 break;
1290 case opt_set_depth:
1291 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1292 if (err)
1293 return svn_cmdline_handle_exit_error
1294 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1295 _("Error converting depth "
1296 "from locale to UTF8")), pool, "svn: ");
1297 opt_state.set_depth = svn_depth_from_word(utf8_opt_arg);
1298 if (opt_state.set_depth == svn_depth_unknown
1299 || opt_state.set_depth == svn_depth_exclude)
1301 return svn_cmdline_handle_exit_error
1302 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1303 _("'%s' is not a valid depth; try "
1304 "'empty', 'files', 'immediates', "
1305 "or 'infinity'"),
1306 utf8_opt_arg), pool, "svn: ");
1308 break;
1309 case opt_version:
1310 opt_state.version = TRUE;
1311 break;
1312 case opt_auth_username:
1313 err = svn_utf_cstring_to_utf8(&opt_state.auth_username,
1314 opt_arg, pool);
1315 if (err)
1316 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1317 break;
1318 case opt_auth_password:
1319 err = svn_utf_cstring_to_utf8(&opt_state.auth_password,
1320 opt_arg, pool);
1321 if (err)
1322 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1323 break;
1324 case opt_encoding:
1325 opt_state.encoding = apr_pstrdup(pool, opt_arg);
1326 break;
1327 case opt_xml:
1328 opt_state.xml = TRUE;
1329 break;
1330 case opt_stop_on_copy:
1331 opt_state.stop_on_copy = TRUE;
1332 break;
1333 case opt_strict:
1334 opt_state.strict = TRUE;
1335 break;
1336 case opt_no_ignore:
1337 opt_state.no_ignore = TRUE;
1338 break;
1339 case opt_no_auth_cache:
1340 opt_state.no_auth_cache = TRUE;
1341 break;
1342 case opt_non_interactive:
1343 opt_state.non_interactive = TRUE;
1344 break;
1345 case opt_no_diff_deleted:
1346 opt_state.no_diff_deleted = TRUE;
1347 break;
1348 case opt_notice_ancestry:
1349 opt_state.notice_ancestry = TRUE;
1350 break;
1351 case opt_ignore_ancestry:
1352 opt_state.ignore_ancestry = TRUE;
1353 break;
1354 case opt_ignore_externals:
1355 opt_state.ignore_externals = TRUE;
1356 break;
1357 case opt_relocate:
1358 opt_state.relocate = TRUE;
1359 break;
1360 case 'x':
1361 err = svn_utf_cstring_to_utf8(&opt_state.extensions, opt_arg, pool);
1362 if (err)
1363 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1364 break;
1365 case opt_diff_cmd:
1366 opt_state.diff_cmd = apr_pstrdup(pool, opt_arg);
1367 break;
1368 case opt_merge_cmd:
1369 opt_state.merge_cmd = apr_pstrdup(pool, opt_arg);
1370 break;
1371 case opt_record_only:
1372 opt_state.record_only = TRUE;
1373 break;
1374 case opt_editor_cmd:
1375 opt_state.editor_cmd = apr_pstrdup(pool, opt_arg);
1376 break;
1377 case opt_old_cmd:
1378 if (opt_state.used_change_arg)
1380 err = svn_error_create
1381 (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1382 _("Can't specify -c with --old"));
1383 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1385 opt_state.old_target = apr_pstrdup(pool, opt_arg);
1386 break;
1387 case opt_new_cmd:
1388 opt_state.new_target = apr_pstrdup(pool, opt_arg);
1389 break;
1390 case opt_config_dir:
1391 err = svn_utf_cstring_to_utf8(&path_utf8, opt_arg, pool);
1392 opt_state.config_dir = svn_path_canonicalize(path_utf8, pool);
1393 break;
1394 case opt_autoprops:
1395 opt_state.autoprops = TRUE;
1396 break;
1397 case opt_no_autoprops:
1398 opt_state.no_autoprops = TRUE;
1399 break;
1400 case opt_native_eol:
1401 if ( !strcmp("LF", opt_arg) || !strcmp("CR", opt_arg) ||
1402 !strcmp("CRLF", opt_arg))
1403 opt_state.native_eol = apr_pstrdup(pool, opt_arg);
1404 else
1406 err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
1407 if (! err)
1408 err = svn_error_createf
1409 (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1410 _("Syntax error in native-eol argument '%s'"),
1411 utf8_opt_arg);
1412 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1414 break;
1415 case opt_no_unlock:
1416 opt_state.no_unlock = TRUE;
1417 break;
1418 case opt_summarize:
1419 opt_state.summarize = TRUE;
1420 break;
1421 case opt_remove:
1422 opt_state.remove = TRUE;
1423 break;
1424 case opt_changelist:
1425 opt_state.changelist = apr_pstrdup(pool, opt_arg);
1426 apr_hash_set(changelists, opt_state.changelist,
1427 APR_HASH_KEY_STRING, (void *)1);
1428 break;
1429 case opt_keep_changelists:
1430 opt_state.keep_changelists = TRUE;
1431 break;
1432 case opt_keep_local:
1433 opt_state.keep_local = TRUE;
1434 break;
1435 case opt_with_all_revprops:
1436 /* If --with-all-revprops is specified along with one or more
1437 * --with-revprops options, --with-all-revprops takes precedence. */
1438 opt_state.all_revprops = TRUE;
1439 break;
1440 case opt_with_revprop:
1441 err = svn_opt_parse_revprop(&opt_state.revprop_table, opt_arg, pool);
1442 if (err != SVN_NO_ERROR)
1443 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1444 break;
1445 case opt_parents:
1446 opt_state.parents = TRUE;
1447 break;
1448 case 'g':
1449 opt_state.use_merge_history = TRUE;
1450 break;
1451 case opt_accept:
1452 opt_state.accept_which = svn_cl__accept_from_word(opt_arg);
1453 if (opt_state.accept_which == svn_cl__accept_invalid)
1454 return svn_cmdline_handle_exit_error
1455 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1456 _("'%s' is not a valid accept value"), opt_arg),
1457 pool, "svn: ");
1458 break;
1459 case opt_from_source:
1460 err = svn_utf_cstring_to_utf8(&path_utf8, opt_arg, pool);
1461 if (! svn_path_is_url(path_utf8))
1462 return svn_cmdline_handle_exit_error
1463 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1464 _("'%s' is not a URL"), opt_arg),
1465 pool, "svn: ");
1466 opt_state.from_source = svn_path_canonicalize(path_utf8, pool);
1467 break;
1468 case opt_reintegrate:
1469 opt_state.reintegrate = TRUE;
1470 break;
1471 default:
1472 /* Hmmm. Perhaps this would be a good place to squirrel away
1473 opts that commands like svn diff might need. Hmmm indeed. */
1474 break;
1478 /* Turn our hash of changelists into an array of unique ones. */
1479 err = svn_hash_keys(&(opt_state.changelists), changelists, pool);
1480 if (err)
1481 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1483 /* ### This really belongs in libsvn_client. The trouble is,
1484 there's no one place there to run it from, no
1485 svn_client_init(). We'd have to add it to all the public
1486 functions that a client might call. It's unmaintainable to do
1487 initialization from within libsvn_client itself, but it seems
1488 burdensome to demand that all clients call svn_client_init()
1489 before calling any other libsvn_client function... On the other
1490 hand, the alternative is effectively to demand that they call
1491 svn_config_ensure() instead, so maybe we should have a generic
1492 init function anyway. Thoughts? */
1493 err = svn_config_ensure(opt_state.config_dir, pool);
1494 if (err)
1495 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1497 /* If the user asked for help, then the rest of the arguments are
1498 the names of subcommands to get help on (if any), or else they're
1499 just typos/mistakes. Whatever the case, the subcommand to
1500 actually run is svn_cl__help(). */
1501 if (opt_state.help)
1502 subcommand = svn_opt_get_canonical_subcommand2(svn_cl__cmd_table, "help");
1504 /* If we're not running the `help' subcommand, then look for a
1505 subcommand in the first argument. */
1506 if (subcommand == NULL)
1508 if (os->ind >= os->argc)
1510 if (opt_state.version)
1512 /* Use the "help" subcommand to handle the "--version" option. */
1513 static const svn_opt_subcommand_desc2_t pseudo_cmd =
1514 { "--version", svn_cl__help, {0}, "",
1515 {opt_version, /* must accept its own option */
1516 'q', /* brief output */
1517 opt_config_dir /* all commands accept this */
1518 } };
1520 subcommand = &pseudo_cmd;
1522 else
1524 svn_error_clear
1525 (svn_cmdline_fprintf(stderr, pool,
1526 _("Subcommand argument required\n")));
1527 svn_cl__help(NULL, NULL, pool);
1528 svn_pool_destroy(pool);
1529 return EXIT_FAILURE;
1532 else
1534 const char *first_arg = os->argv[os->ind++];
1535 subcommand = svn_opt_get_canonical_subcommand2(svn_cl__cmd_table,
1536 first_arg);
1537 if (subcommand == NULL)
1539 const char *first_arg_utf8;
1540 err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg, pool);
1541 if (err)
1542 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1543 svn_error_clear
1544 (svn_cmdline_fprintf(stderr, pool,
1545 _("Unknown command: '%s'\n"),
1546 first_arg_utf8));
1547 svn_cl__help(NULL, NULL, pool);
1548 svn_pool_destroy(pool);
1549 return EXIT_FAILURE;
1554 /* Check that the subcommand wasn't passed any inappropriate options. */
1555 for (i = 0; i < received_opts->nelts; i++)
1557 opt_id = APR_ARRAY_IDX(received_opts, i, int);
1559 /* All commands implicitly accept --help, so just skip over this
1560 when we see it. Note that we don't want to include this option
1561 in their "accepted options" list because it would be awfully
1562 redundant to display it in every commands' help text. */
1563 if (opt_id == 'h' || opt_id == '?')
1564 continue;
1566 if (! svn_opt_subcommand_takes_option3(subcommand, opt_id,
1567 svn_cl__global_options))
1569 const char *optstr;
1570 const apr_getopt_option_t *badopt =
1571 svn_opt_get_option_from_code2(opt_id, svn_cl__options,
1572 subcommand, pool);
1573 svn_opt_format_option(&optstr, badopt, FALSE, pool);
1574 if (subcommand->name[0] == '-')
1575 svn_cl__help(NULL, NULL, pool);
1576 else
1577 svn_error_clear
1578 (svn_cmdline_fprintf
1579 (stderr, pool, _("Subcommand '%s' doesn't accept option '%s'\n"
1580 "Type 'svn help %s' for usage.\n"),
1581 subcommand->name, optstr, subcommand->name));
1582 svn_pool_destroy(pool);
1583 return EXIT_FAILURE;
1587 /* Only merge supports multiple revisions/revision ranges. */
1588 if (subcommand->cmd_func != svn_cl__merge)
1590 if (opt_state.revision_ranges->nelts > 1)
1592 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1593 _("Multiple revision arguments "
1594 "encountered; can't specify -c twice, "
1595 "or both -c and -r"));
1596 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1600 /* Merge doesn't support specifying a revision range
1601 when using --reintegrate. */
1602 if (subcommand->cmd_func == svn_cl__merge
1603 && opt_state.revision_ranges->nelts
1604 && opt_state.reintegrate)
1606 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1607 _("-r and -c can't be used with --reintegrate"));
1608 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1611 /* Disallow simultaneous use of both --depth and --set-depth. */
1612 if ((opt_state.depth != svn_depth_unknown)
1613 && (opt_state.set_depth != svn_depth_unknown))
1615 err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1616 _("--depth and --set-depth are mutually "
1617 "exclusive"));
1618 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1621 /* Ensure that 'revision_ranges' has at least one item, and that
1622 'start_revision' and 'end_revision' match that item. */
1623 if (opt_state.revision_ranges->nelts == 0)
1625 svn_opt_revision_range_t *range = apr_palloc(pool, sizeof(*range));
1626 range->start.kind = svn_opt_revision_unspecified;
1627 range->end.kind = svn_opt_revision_unspecified;
1628 APR_ARRAY_PUSH(opt_state.revision_ranges,
1629 svn_opt_revision_range_t *) = range;
1631 opt_state.start_revision = APR_ARRAY_IDX(opt_state.revision_ranges, 0,
1632 svn_opt_revision_range_t *)->start;
1633 opt_state.end_revision = APR_ARRAY_IDX(opt_state.revision_ranges, 0,
1634 svn_opt_revision_range_t *)->end;
1636 /* If we're running a command that could result in a commit, verify
1637 that any log message we were given on the command line makes
1638 sense (unless we've also been instructed not to care). */
1639 if ((! opt_state.force_log)
1640 && (subcommand->cmd_func == svn_cl__commit
1641 || subcommand->cmd_func == svn_cl__copy
1642 || subcommand->cmd_func == svn_cl__delete
1643 || subcommand->cmd_func == svn_cl__import
1644 || subcommand->cmd_func == svn_cl__mkdir
1645 || subcommand->cmd_func == svn_cl__move
1646 || subcommand->cmd_func == svn_cl__lock
1647 || subcommand->cmd_func == svn_cl__propedit))
1649 /* If the -F argument is a file that's under revision control,
1650 that's probably not what the user intended. */
1651 if (dash_F_arg)
1653 svn_wc_adm_access_t *adm_access;
1654 const svn_wc_entry_t *e;
1655 const char *fname_utf8 = svn_path_internal_style(dash_F_arg, pool);
1656 err = svn_wc_adm_probe_open3(&adm_access, NULL, fname_utf8,
1657 FALSE, 0, NULL, NULL, pool);
1658 if (! err)
1659 err = svn_wc_entry(&e, fname_utf8, adm_access, FALSE, pool);
1660 if ((err == SVN_NO_ERROR) && e)
1662 if (subcommand->cmd_func != svn_cl__lock)
1664 err = svn_error_create
1665 (SVN_ERR_CL_LOG_MESSAGE_IS_VERSIONED_FILE, NULL,
1666 _("Log message file is a versioned file; "
1667 "use '--force-log' to override"));
1669 else
1671 err = svn_error_create
1672 (SVN_ERR_CL_LOG_MESSAGE_IS_VERSIONED_FILE, NULL,
1673 _("Lock comment file is a versioned file; "
1674 "use '--force-log' to override"));
1676 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1678 svn_error_clear(err);
1681 /* If the -m argument is a file at all, that's probably not what
1682 the user intended. */
1683 if (dash_m_arg)
1685 apr_finfo_t finfo;
1686 if (apr_stat(&finfo, dash_m_arg,
1687 APR_FINFO_MIN, pool) == APR_SUCCESS)
1689 if (subcommand->cmd_func != svn_cl__lock)
1691 err = svn_error_create
1692 (SVN_ERR_CL_LOG_MESSAGE_IS_PATHNAME, NULL,
1693 _("The log message is a pathname "
1694 "(was -F intended?); use '--force-log' to override"));
1696 else
1698 err = svn_error_create
1699 (SVN_ERR_CL_LOG_MESSAGE_IS_PATHNAME, NULL,
1700 _("The lock comment is a pathname "
1701 "(was -F intended?); use '--force-log' to override"));
1703 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1708 if (opt_state.relocate && (opt_state.depth != svn_depth_unknown))
1710 err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
1711 _("--relocate and --depth are mutually "
1712 "exclusive"));
1713 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1716 /* Only a few commands can accept a revision range; the rest can take at
1717 most one revision number. */
1718 if (subcommand->cmd_func != svn_cl__blame
1719 && subcommand->cmd_func != svn_cl__diff
1720 && subcommand->cmd_func != svn_cl__log
1721 && subcommand->cmd_func != svn_cl__merge)
1723 if (opt_state.end_revision.kind != svn_opt_revision_unspecified)
1725 err = svn_error_create(SVN_ERR_CLIENT_REVISION_RANGE, NULL, NULL);
1726 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1730 /* -N has a different meaning depending on the command */
1731 if (descend == FALSE)
1733 if (subcommand->cmd_func == svn_cl__status)
1735 opt_state.depth = SVN_DEPTH_INFINITY_OR_IMMEDIATES(FALSE);
1737 else if (subcommand->cmd_func == svn_cl__revert
1738 || subcommand->cmd_func == svn_cl__add)
1740 /* In pre-1.5 Subversion, some commands treated -N like
1741 --depth=empty, so . Also, with revert it makes sense to be
1742 especially conservative, since revert can lose data. */
1743 opt_state.depth = svn_depth_empty;
1745 else
1747 opt_state.depth = SVN_DEPTH_INFINITY_OR_FILES(FALSE);
1750 /* Create a client context object. */
1751 command_baton.opt_state = &opt_state;
1752 if ((err = svn_client_create_context(&ctx, pool)))
1753 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1754 command_baton.ctx = ctx;
1756 err = svn_config_get_config(&(ctx->config),
1757 opt_state.config_dir, pool);
1758 if (err)
1760 /* Fallback to default config if the config directory isn't readable. */
1761 if (err->apr_err == APR_EACCES)
1763 svn_handle_warning(stderr, err);
1764 svn_error_clear(err);
1766 else
1767 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1770 cfg = apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG,
1771 APR_HASH_KEY_STRING);
1773 /* Update the options in the config */
1774 /* XXX: Only diff_cmd for now, overlay rest later and stop passing
1775 opt_state altogether? */
1776 if (opt_state.diff_cmd)
1777 svn_config_set(cfg, SVN_CONFIG_SECTION_HELPERS,
1778 SVN_CONFIG_OPTION_DIFF_CMD, opt_state.diff_cmd);
1779 if (opt_state.merge_cmd)
1780 svn_config_set(cfg, SVN_CONFIG_SECTION_HELPERS,
1781 SVN_CONFIG_OPTION_DIFF3_CMD, opt_state.merge_cmd);
1783 /* Check for mutually exclusive args --auto-props and --no-auto-props */
1784 if (opt_state.autoprops && opt_state.no_autoprops)
1786 err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
1787 _("--auto-props and --no-auto-props are "
1788 "mutually exclusive"));
1789 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1792 /* The --reintegrate option is mutually exclusive with both
1793 --ignore-ancestry and --record-only. */
1794 if (opt_state.reintegrate)
1796 if (opt_state.ignore_ancestry)
1798 if (opt_state.record_only)
1800 err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
1801 _("--reintegrate cannot be used with "
1802 "--ignore-ancestry or "
1803 "--record-only"));
1804 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1806 else
1808 err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
1809 _("--reintegrate cannot be used with "
1810 "--ignore-ancestry"));
1811 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1814 else if (opt_state.record_only)
1816 err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
1817 _("--reintegrate cannot be used with "
1818 "--record-only"));
1819 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1823 /* Update auto-props-enable option, and populate the MIME types map,
1824 for add/import commands */
1825 if (subcommand->cmd_func == svn_cl__add
1826 || subcommand->cmd_func == svn_cl__import)
1828 const char *mimetypes_file;
1829 svn_config_get(cfg, &mimetypes_file,
1830 SVN_CONFIG_SECTION_MISCELLANY,
1831 SVN_CONFIG_OPTION_MIMETYPES_FILE, FALSE);
1832 if (mimetypes_file && *mimetypes_file)
1834 if ((err = svn_io_parse_mimetypes_file(&(ctx->mimetypes_map),
1835 mimetypes_file, pool)))
1836 svn_handle_error2(err, stderr, TRUE, "svn: ");
1839 if (opt_state.autoprops)
1841 svn_config_set_bool(cfg, SVN_CONFIG_SECTION_MISCELLANY,
1842 SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS, TRUE);
1844 if (opt_state.no_autoprops)
1846 svn_config_set_bool(cfg, SVN_CONFIG_SECTION_MISCELLANY,
1847 SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS, FALSE);
1851 /* Update the 'keep-locks' runtime option */
1852 if (opt_state.no_unlock)
1853 svn_config_set_bool(cfg, SVN_CONFIG_SECTION_MISCELLANY,
1854 SVN_CONFIG_OPTION_NO_UNLOCK, TRUE);
1856 /* Set the log message callback function. Note that individual
1857 subcommands will populate the ctx->log_msg_baton3. */
1858 ctx->log_msg_func3 = svn_cl__get_log_message;
1860 /* Set up our cancellation support. */
1861 ctx->cancel_func = svn_cl__check_cancel;
1862 apr_signal(SIGINT, signal_handler);
1863 #ifdef SIGBREAK
1864 /* SIGBREAK is a Win32 specific signal generated by ctrl-break. */
1865 apr_signal(SIGBREAK, signal_handler);
1866 #endif
1867 #ifdef SIGHUP
1868 apr_signal(SIGHUP, signal_handler);
1869 #endif
1870 #ifdef SIGTERM
1871 apr_signal(SIGTERM, signal_handler);
1872 #endif
1874 #ifdef SIGPIPE
1875 /* Disable SIGPIPE generation for the platforms that have it. */
1876 apr_signal(SIGPIPE, SIG_IGN);
1877 #endif
1879 #ifdef SIGXFSZ
1880 /* Disable SIGXFSZ generation for the platforms that have it, otherwise
1881 * working with large files when compiled against an APR that doesn't have
1882 * large file support will crash the program, which is uncool. */
1883 apr_signal(SIGXFSZ, SIG_IGN);
1884 #endif
1886 /* Set up Authentication stuff. */
1887 if ((err = svn_cmdline_setup_auth_baton(&ab,
1888 opt_state.non_interactive,
1889 opt_state.auth_username,
1890 opt_state.auth_password,
1891 opt_state.config_dir,
1892 opt_state.no_auth_cache,
1893 cfg,
1894 ctx->cancel_func,
1895 ctx->cancel_baton,
1896 pool)))
1897 svn_handle_error2(err, stderr, TRUE, "svn: ");
1899 ctx->auth_baton = ab;
1901 /* Set up conflict resolution callback. */
1902 if ((err = svn_config_get_bool(cfg, &interactive_conflicts,
1903 SVN_CONFIG_SECTION_MISCELLANY,
1904 SVN_CONFIG_OPTION_INTERACTIVE_CONFLICTS,
1905 TRUE))) /* ### interactivity on by default.
1906 we can change this. */
1907 svn_handle_error2(err, stderr, TRUE, "svn: ");
1909 if ((opt_state.accept_which == svn_cl__accept_invalid
1910 && (!interactive_conflicts || opt_state.non_interactive))
1911 || opt_state.accept_which == svn_cl__accept_postpone)
1913 /* If no --accept option at all and we're non-interactive, we're
1914 leaving the conflicts behind, so don't need the callback. Same if
1915 the user said to postpone. */
1916 ctx->conflict_func = NULL;
1917 ctx->conflict_baton = NULL;
1919 else
1921 svn_cmdline_prompt_baton_t *pb = apr_palloc(pool, sizeof(*pb));
1922 pb->cancel_func = ctx->cancel_func;
1923 pb->cancel_baton = ctx->cancel_baton;
1925 if (opt_state.non_interactive)
1927 if (opt_state.accept_which == svn_cl__accept_edit)
1928 return svn_cmdline_handle_exit_error
1929 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1930 _("--accept=%s incompatible with"
1931 " --non-interactive"), SVN_CL__ACCEPT_EDIT),
1932 pool, "svn: ");
1933 if (opt_state.accept_which == svn_cl__accept_launch)
1934 return svn_cmdline_handle_exit_error
1935 (svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
1936 _("--accept=%s incompatible with"
1937 " --non-interactive"),
1938 SVN_CL__ACCEPT_LAUNCH),
1939 pool, "svn: ");
1942 ctx->conflict_func = svn_cl__conflict_handler;
1943 ctx->conflict_baton = svn_cl__conflict_baton_make(
1944 opt_state.accept_which,
1945 ctx->config,
1946 opt_state.editor_cmd,
1948 pool);
1951 /* And now we finally run the subcommand. */
1952 err = (*subcommand->cmd_func)(os, &command_baton, pool);
1953 if (err)
1955 svn_error_t *tmp_err;
1957 /* For argument-related problems, suggest using the 'help'
1958 subcommand. */
1959 if (err->apr_err == SVN_ERR_CL_INSUFFICIENT_ARGS
1960 || err->apr_err == SVN_ERR_CL_ARG_PARSING_ERROR)
1962 err = svn_error_quick_wrap(err,
1963 _("Try 'svn help' for more info"));
1965 svn_handle_error2(err, stderr, FALSE, "svn: ");
1967 /* Tell the user about 'svn cleanup' if any error on the stack
1968 was about locked working copies. */
1969 for (tmp_err = err; tmp_err; tmp_err = tmp_err->child)
1970 if (tmp_err->apr_err == SVN_ERR_WC_LOCKED)
1972 svn_error_clear
1973 (svn_cmdline_fputs(_("svn: run 'svn cleanup' to remove locks "
1974 "(type 'svn help cleanup' for details)\n"),
1975 stderr, pool));
1976 break;
1979 svn_error_clear(err);
1980 svn_pool_destroy(pool);
1981 return EXIT_FAILURE;
1983 else
1985 /* Ensure that stdout is flushed, so the user will see any write errors.
1986 This makes sure that output is not silently lost. */
1987 err = svn_cmdline_fflush(stdout);
1988 if (err)
1989 return svn_cmdline_handle_exit_error(err, pool, "svn: ");
1991 svn_pool_destroy(pool);
1992 return EXIT_SUCCESS;