Followup to r29625: fix getopt tests.
[svn.git] / subversion / svn / cl.h
blob77e166fdb8f134b30c758412f2d8b0faeba0ce48
1 /*
2 * cl.h: shared stuff in the command line program
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 #ifndef SVN_CL_H
24 #define SVN_CL_H
26 /*** Includes. ***/
27 #include <apr_tables.h>
28 #include <apr_getopt.h>
30 #include "svn_wc.h"
31 #include "svn_client.h"
32 #include "svn_string.h"
33 #include "svn_opt.h"
34 #include "svn_auth.h"
35 #include "svn_cmdline.h"
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
42 /*** Option processing ***/
44 /* --accept actions */
45 typedef enum
47 /* invalid or unspecified accept action */
48 svn_cl__accept_invalid = -1,
50 /* Leave conflicts alone, for later resolution. */
51 svn_cl__accept_postpone,
53 /* Resolve the conflict with the pre-conflict base file. */
54 svn_cl__accept_base,
56 /* Resolve the conflicted hunks by choosing the corresponding text
57 from the pre-conflict working copy file.
59 Note: this is a placeholder, not actually implemented in 1.5. */
60 svn_cl__accept_mine_conflict,
62 /* Resolve the conflicted hunks by choosing the corresponding text
63 from the post-conflict base copy file.
65 Note: this is a placeholder, not actually implemented in 1.5. */
66 svn_cl__accept_theirs_conflict,
68 /* Resolve the conflict by taking the entire pre-conflict working
69 copy file. */
70 svn_cl__accept_mine_full,
72 /* Resolve the conflict by taking the entire post-conflict base file. */
73 svn_cl__accept_theirs_full,
75 /* Launch user's editor and resolve conflict with edited file. */
76 svn_cl__accept_edit,
78 /* Launch user's resolver and resolve conflict with edited file. */
79 svn_cl__accept_launch,
80 } svn_cl__accept_t;
82 /* --accept action user input words */
83 #define SVN_CL__ACCEPT_POSTPONE "postpone"
84 #define SVN_CL__ACCEPT_BASE "base"
85 #define SVN_CL__ACCEPT_MINE_CONFLICT "mine-conflict"
86 #define SVN_CL__ACCEPT_THEIRS_CONFLICT "theirs-conflict"
87 #define SVN_CL__ACCEPT_MINE_FULL "mine-full"
88 #define SVN_CL__ACCEPT_THEIRS_FULL "theirs-full"
89 #define SVN_CL__ACCEPT_EDIT "edit"
90 #define SVN_CL__ACCEPT_LAUNCH "launch"
92 /* Return svn_cl__accept_t value corresponding to word. */
93 svn_cl__accept_t
94 svn_cl__accept_from_word(const char *word);
98 /*** Command dispatch. ***/
100 /* Hold results of option processing that are shared by multiple
101 commands. */
102 typedef struct svn_cl__opt_state_t
104 /* An array of svn_opt_revision_range_t *'s representing revisions
105 ranges indicated on the command-line via the -r and -c options.
106 For each range in the list, if only one revision was provided
107 (-rN), its 'end' member remains `svn_opt_revision_unspecified'.
109 NOTE: This is currently used only by merge subcommand. */
110 apr_array_header_t *revision_ranges;
112 /* These are simply a copy of the range start and end values present
113 in the first item of the revision_ranges list. */
114 svn_opt_revision_t start_revision;
115 svn_opt_revision_t end_revision;
117 /* Flag which is only set if the '-c' option was used. */
118 svn_boolean_t used_change_arg;
120 /* Max number of log messages to get back from svn_client_log2. */
121 int limit;
123 /* After option processing is done, reflects the switch actually
124 given on the command line, or svn_depth_unknown if none. */
125 svn_depth_t depth;
127 /* Was --no-unlock specified? */
128 svn_boolean_t no_unlock;
130 const char *message; /* log message */
131 const char *ancestor_path; /* ### todo: who sets this? */
132 svn_boolean_t force; /* be more forceful, as in "svn rm -f ..." */
133 svn_boolean_t force_log; /* force validity of a suspect log msg file */
134 svn_boolean_t incremental; /* yield output suitable for concatenation */
135 svn_boolean_t quiet; /* sssh...avoid unnecessary output */
136 svn_boolean_t non_interactive; /* do no interactive prompting */
137 svn_boolean_t version; /* print version information */
138 svn_boolean_t verbose; /* be verbose */
139 svn_boolean_t update; /* contact the server for the full story */
140 svn_boolean_t strict; /* do strictly what was requested */
141 svn_stringbuf_t *filedata; /* contents of file used as option data */
142 const char *encoding; /* the locale/encoding of the data*/
143 svn_boolean_t help; /* print usage message */
144 const char *auth_username; /* auth username */ /* UTF-8! */
145 const char *auth_password; /* auth password */ /* UTF-8! */
146 const char *extensions; /* subprocess extension args */ /* UTF-8! */
147 apr_array_header_t *targets; /* target list from file */ /* UTF-8! */
148 svn_boolean_t xml; /* output in xml, e.g., "svn log --xml" */
149 svn_boolean_t no_ignore; /* disregard default ignores & svn:ignore's */
150 svn_boolean_t no_auth_cache; /* do not cache authentication information */
151 svn_boolean_t no_diff_deleted; /* do not show diffs for deleted files */
152 svn_boolean_t notice_ancestry; /* notice ancestry for diff-y operations */
153 svn_boolean_t ignore_ancestry; /* ignore ancestry for merge-y operations */
154 svn_boolean_t ignore_externals;/* ignore externals definitions */
155 svn_boolean_t stop_on_copy; /* don't cross copies during processing */
156 svn_boolean_t dry_run; /* try operation but make no changes */
157 svn_boolean_t revprop; /* operate on a revision property */
158 const char *diff_cmd; /* the external diff command to use */
159 const char *merge_cmd; /* the external merge command to use */
160 const char *editor_cmd; /* external editor command. */
161 svn_boolean_t record_only; /* whether to record mergeinfo */
162 const char *old_target; /* diff target */
163 const char *new_target; /* diff target */
164 svn_boolean_t relocate; /* rewrite urls (svn switch) */
165 const char *config_dir; /* over-riding configuration directory */
166 svn_boolean_t autoprops; /* enable automatic properties */
167 svn_boolean_t no_autoprops; /* disable automatic properties */
168 const char *native_eol; /* override system standard eol marker */
169 svn_boolean_t summarize; /* create a summary of a diff */
170 svn_boolean_t remove; /* deassociate a changelist */
171 apr_array_header_t *changelists; /* changelist filters */
172 const char *changelist; /* operate on this changelist
173 THIS IS TEMPORARY (LAST OF CHANGELISTS) */
174 svn_boolean_t keep_changelists;/* don't remove changelists after commit */
175 svn_boolean_t keep_local; /* delete path only from repository */
176 svn_boolean_t all_revprops; /* retrieve all props */
177 apr_hash_t *revprop_table; /* table of revision properties to get/set */
178 svn_boolean_t parents; /* create intermediate directories */
179 svn_boolean_t use_merge_history; /* use/display extra merge information */
180 svn_cl__accept_t accept_which; /* how to handle conflicts */
181 const char *from_source; /* merge source to query (svn mergeinfo) */
182 svn_depth_t set_depth; /* new sticky ambient depth value */
183 svn_boolean_t reintegrate; /* use "reintegrate" merge-source heuristic */
184 } svn_cl__opt_state_t;
187 typedef struct
189 svn_cl__opt_state_t *opt_state;
190 svn_client_ctx_t *ctx;
191 } svn_cl__cmd_baton_t;
194 /* Declare all the command procedures */
195 svn_opt_subcommand_t
196 svn_cl__add,
197 svn_cl__blame,
198 svn_cl__cat,
199 svn_cl__changelist,
200 svn_cl__checkout,
201 svn_cl__cleanup,
202 svn_cl__commit,
203 svn_cl__copy,
204 svn_cl__delete,
205 svn_cl__diff,
206 svn_cl__export,
207 svn_cl__help,
208 svn_cl__import,
209 svn_cl__info,
210 svn_cl__lock,
211 svn_cl__log,
212 svn_cl__list,
213 svn_cl__merge,
214 svn_cl__mergeinfo,
215 svn_cl__mkdir,
216 svn_cl__move,
217 svn_cl__propdel,
218 svn_cl__propedit,
219 svn_cl__propget,
220 svn_cl__proplist,
221 svn_cl__propset,
222 svn_cl__revert,
223 svn_cl__resolved,
224 svn_cl__status,
225 svn_cl__switch,
226 svn_cl__unlock,
227 svn_cl__update;
230 /* See definition in main.c for documentation. */
231 extern const svn_opt_subcommand_desc2_t svn_cl__cmd_table[];
233 /* See definition in main.c for documentation. */
234 extern const int svn_cl__global_options[];
236 /* See definition in main.c for documentation. */
237 extern const apr_getopt_option_t svn_cl__options[];
240 /* A helper for the many subcommands that wish to merely warn when
241 * invoked on an unversioned, nonexistent, or otherwise innocuously
242 * errorful resource. Meant to be wrapped with SVN_ERR().
244 * If ERR is null, return SVN_NO_ERROR, setting *SUCCESS to TRUE
245 * if SUCCESS is not NULL.
247 * Else if ERR->apr_err is one of the error codes supplied in varargs,
248 * then handle ERR as a warning (unless QUIET is true), clear ERR, and
249 * return SVN_NO_ERROR, setting *SUCCESS to FALSE if SUCCESS is not
250 * NULL.
252 * Else return ERR, setting *SUCCESS to FALSE if SUCCESS is not NULL.
254 * Typically, error codes like SVN_ERR_UNVERSIONED_RESOURCE,
255 * SVN_ERR_ENTRY_NOT_FOUND, etc, are supplied in varargs. Don't
256 * forget to terminate the argument list with SVN_NO_ERROR.
258 svn_error_t *
259 svn_cl__try(svn_error_t *err,
260 svn_boolean_t *success,
261 svn_boolean_t quiet,
262 ...);
265 /* Our cancellation callback. */
266 svn_error_t *svn_cl__check_cancel(void *baton);
270 /* Various conflict-resolution callbacks. */
272 typedef struct {
273 svn_cl__accept_t accept_which;
274 apr_hash_t *config;
275 const char *editor_cmd;
276 svn_boolean_t external_failed;
277 svn_cmdline_prompt_baton_t *pb;
278 } svn_cl__conflict_baton_t;
280 /* Return address of newly allocated and initialized
281 svn_cl__conflict_baton_t. */
282 svn_cl__conflict_baton_t *
283 svn_cl__conflict_baton_make(svn_cl__accept_t accept_which,
284 apr_hash_t *config,
285 const char *editor_cmd,
286 svn_cmdline_prompt_baton_t *pb,
287 apr_pool_t *pool);
289 /* A conflict-resolution callback which prompts the user to choose
290 one of the 3 fulltexts, edit the merged file on the spot, or just
291 skip the conflict (to be resolved later).
292 Implements @c svn_wc_conflict_resolver_func_t. */
293 svn_error_t *
294 svn_cl__conflict_handler(svn_wc_conflict_result_t **result,
295 const svn_wc_conflict_description_t *desc,
296 void *baton,
297 apr_pool_t *pool);
301 /*** Command-line output functions -- printing to the user. ***/
303 /* Print out commit information found in COMMIT_INFO to the console.
304 * POOL is used for temporay allocations.
305 * COMMIT_INFO should not be NULL.
307 svn_error_t *svn_cl__print_commit_info(svn_commit_info_t *commit_info,
308 apr_pool_t *pool);
311 /* Print STATUS for PATH to stdout for human consumption. Prints in
312 abbreviated format by default, or DETAILED format if flag is set.
314 When DETAILED is set, use SHOW_LAST_COMMITTED to toggle display of
315 the last-committed-revision and last-committed-author.
317 If SKIP_UNRECOGNIZED is TRUE, this function will not print out
318 unversioned items found in the working copy.
320 When DETAILED is set, and REPOS_LOCKS is set, treat missing repository locks
321 as broken WC locks. */
322 svn_error_t *svn_cl__print_status(const char *path,
323 svn_wc_status2_t *status,
324 svn_boolean_t detailed,
325 svn_boolean_t show_last_committed,
326 svn_boolean_t skip_unrecognized,
327 svn_boolean_t repos_locks,
328 apr_pool_t *pool);
331 /* Print STATUS for PATH in XML to stdout. Use POOL for temporary
332 allocations. */
333 svn_error_t *
334 svn_cl__print_status_xml(const char *path,
335 svn_wc_status2_t *status,
336 apr_pool_t *pool);
339 /* Print a hash that maps property names (char *) to property values
340 (svn_string_t *). The names are assumed to be in UTF-8 format;
341 the values are either in UTF-8 (the special Subversion props) or
342 plain binary values.
344 If NAMES_ONLY is true, print just names, else print names and
345 values. */
346 svn_error_t *
347 svn_cl__print_prop_hash(apr_hash_t *prop_hash,
348 svn_boolean_t names_only,
349 apr_pool_t *pool);
351 /* Print a single xml property name-value pair to OUTSTR. If OUTSTR is NULL,
352 allocate it first from pool, otherwise append the xml to it. Escape
353 property values which are not xml safe, as determined by
354 svn_xml_is_xml_safe(). */
355 void
356 svn_cl__print_xml_prop(svn_stringbuf_t **outstr,
357 const char* propname,
358 svn_string_t *propval,
359 apr_pool_t *pool);
361 /* Same as svn_cl__print_prop_hash(), only output xml to OUTSTR. If OUTSTR is
362 NULL, allocate it first from pool, otherwise append the xml to it. */
363 svn_error_t *
364 svn_cl__print_xml_prop_hash(svn_stringbuf_t **outstr,
365 apr_hash_t *prop_hash,
366 svn_boolean_t names_only,
367 apr_pool_t *pool);
369 /* Output a commit xml element to OUTSTR. IF OUTSTR is NULL, allocate it
370 first from pool, otherwise appen the xml to it. If AUTHOR or DATE is
371 NULL, it will be omitted. */
372 void
373 svn_cl__print_xml_commit(svn_stringbuf_t **outstr,
374 svn_revnum_t revision,
375 const char *author,
376 const char *date,
377 apr_pool_t *pool);
379 /* Do the following things that are commonly required before accessing revision
380 properties. Ensure that REVISION is specified explicitly and is not
381 relative to a working-copy item. Ensure that exactly one target is
382 specified in TARGETS. Set *URL to the URL of the target. Return an
383 appropriate error if any of those checks or operations fail.
385 svn_error_t *
386 svn_cl__revprop_prepare(const svn_opt_revision_t *revision,
387 apr_array_header_t *targets,
388 const char **URL,
389 apr_pool_t *pool);
391 /* Search for a text editor command in standard environment variables,
392 and invoke it to edit CONTENTS (using a temporary file created in
393 directory BASE_DIR). Return the new contents in *EDITED_CONTENTS,
394 or set *EDITED_CONTENTS to NULL if no edit was performed.
396 If EDITOR_CMD is not NULL, it is the name of the external editor
397 command to use, overriding anything else that might determine the
398 editor.
400 If TMPFILE_LEFT is NULL, the temporary file will be destroyed.
401 Else, the file will be left on disk, and its path returned in
402 *TMPFILE_LEFT.
404 CONFIG is a hash of svn_config_t * items keyed on a configuration
405 category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.
407 If AS_TEXT is TRUE, recode CONTENTS and convert to native eol-style before
408 editing and back again afterwards. In this case, ENCODING determines the
409 encoding used during editing. If non-NULL, use the named encoding, else
410 use the system encoding. If AS_TEXT is FALSE, don't do any translation.
411 In that case, ENCODING is ignored.
413 Use POOL for all allocations. Use PREFIX as the prefix for the
414 temporary file used by the editor.
416 If return error, *EDITED_CONTENTS is not touched. */
417 svn_error_t *
418 svn_cl__edit_string_externally(svn_string_t **edited_contents,
419 const char **tmpfile_left,
420 const char *editor_cmd,
421 const char *base_dir,
422 const svn_string_t *contents,
423 const char *prefix,
424 apr_hash_t *config,
425 svn_boolean_t as_text,
426 const char *encoding,
427 apr_pool_t *pool);
430 /* Search for a text editor command in standard environment variables,
431 and invoke it to edit PATH. Use POOL for all allocations.
433 If EDITOR_CMD is not NULL, it is the name of the external editor
434 command to use, overriding anything else that might determine the
435 editor.
437 CONFIG is a hash of svn_config_t * items keyed on a configuration
438 category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL. */
439 svn_error_t *
440 svn_cl__edit_file_externally(const char *path,
441 const char *editor_cmd,
442 apr_hash_t *config,
443 apr_pool_t *pool);
445 /* Search for a merge tool command in environment variables,
446 and use it to perform the merge of the four given files.
447 Use POOL for all allocations.
449 CONFIG is a hash of svn_config_t * items keyed on a configuration
450 category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.
452 svn_error_t *
453 svn_cl__merge_file_externally(const char *base_path,
454 const char *their_path,
455 const char *my_path,
456 const char *merged_path,
457 apr_hash_t *config,
458 apr_pool_t *pool);
462 /*** Notification functions to display results on the terminal. */
464 /* Set *NOTIFY_FUNC_P and *NOTIFY_BATON_P to a notifier/baton for all
465 * operations, allocated in POOL.
467 * If this is a checkout, set IS_CHECKOUT to true, so that the
468 * notifier will print the appropriate summary line at the end of the
469 * output.
471 * If this is an export, set IS_EXPORT to true, so that the
472 * notifier will print the appropriate summary line at the end of the
473 * output.
475 * If don't want a summary line at the end of notifications, set
476 * SUPPRESS_FINAL_LINE.
478 void svn_cl__get_notifier(svn_wc_notify_func2_t *notify_func_p,
479 void **notify_baton_p,
480 svn_boolean_t is_checkout,
481 svn_boolean_t is_export,
482 svn_boolean_t suppress_final_line,
483 apr_pool_t *pool);
486 /*** Log message callback stuffs. ***/
488 /* Allocate in POOL a baton for use with svn_cl__get_log_message().
490 OPT_STATE is the set of command-line options given.
492 BASE_DIR is a directory in which to create temporary files if an
493 external editor is used to edit the log message. If BASE_DIR is
494 NULL, the current working directory (`.') will be used, and
495 therefore the user must have the proper permissions on that
496 directory. ### todo: What *should* happen in the NULL case is that
497 we ask APR to tell us where a suitable tmp directory is (like, /tmp
498 on Unix and C:\Windows\Temp on Win32 or something), and use it.
499 But APR doesn't yet have that capability.
501 CONFIG is a client configuration hash of svn_config_t * items keyed
502 on config categories, and may be NULL.
504 NOTE: While the baton itself will be allocated from POOL, the items
505 add to it are added by reference, not duped into POOL!*/
506 svn_error_t *svn_cl__make_log_msg_baton(void **baton,
507 svn_cl__opt_state_t *opt_state,
508 const char *base_dir,
509 apr_hash_t *config,
510 apr_pool_t *pool);
512 /* A function of type svn_client_get_commit_log3_t. */
513 svn_error_t *svn_cl__get_log_message(const char **log_msg,
514 const char **tmp_file,
515 const apr_array_header_t *commit_items,
516 void *baton,
517 apr_pool_t *pool);
519 /* Handle the cleanup of a log message, using the data in the
520 LOG_MSG_BATON, in the face of COMMIT_ERR. This may mean removing a
521 temporary file left by an external editor, or it may be a complete
522 no-op. COMMIT_ERR may be NULL to indicate to indicate that the
523 function should act as though no commit error occurred.
525 All error returns from this function are guaranteed to at least
526 include COMMIT_ERR, and perhaps additional errors attached to the
527 end of COMMIT_ERR's chain. */
528 svn_error_t *svn_cl__cleanup_log_msg(void *log_msg_baton,
529 svn_error_t *commit_err);
531 /* Add a message about --force if appropriate */
532 svn_error_t *svn_cl__may_need_force(svn_error_t *err);
534 /* Write the STRING to the stdio STREAM, returning an error if it fails. */
535 svn_error_t *svn_cl__error_checked_fputs(const char *string,
536 FILE* stream);
538 /* If STRING is non-null, append it, wrapped in a simple XML CDATA element
539 named TAGNAME, to the string SB. Use POOL for temporary allocations. */
540 void svn_cl__xml_tagged_cdata(svn_stringbuf_t **sb,
541 apr_pool_t *pool,
542 const char *tagname,
543 const char *string);
545 /* Print the XML prolog and document root element start-tag to stdout, using
546 TAGNAME as the root element name. Use pool for temporary allocations. */
547 svn_error_t *svn_cl__xml_print_header(const char *tagname,
548 apr_pool_t *pool);
550 /* Print the XML document root element end-tag to stdout, using TAGNAME as the
551 root element name. Use pool for temporary allocations. */
552 svn_error_t *svn_cl__xml_print_footer(const char *tagname,
553 apr_pool_t *pool);
555 /* Return a (non-localised) string representation of KIND, being "dir" or
556 "file" or, in any other case, the empty string. */
557 const char *svn_cl__node_kind_str(svn_node_kind_t kind);
560 /* If PROPNAME is one of the svn: properties with a boolean value, and
561 * PROPVAL looks like an attempt to turn the property off (i.e., it's
562 * "off", "no", "false", or ""), then print a warning to the user that
563 * setting the property to this value might not do what they expect.
564 * Perform temporary allocations in POOL.
566 void svn_cl__check_boolean_prop_val(const char *propname,
567 const char *propval,
568 apr_pool_t *pool);
570 /* De-streamifying wrapper around svn_client_get_changelists(), which
571 is called for each target in TARGETS to populate *PATHS (a list of
572 paths assigned to one of the CHANGELISTS. */
573 svn_error_t *svn_cl__changelist_paths(apr_array_header_t **paths,
574 const apr_array_header_t *changelists,
575 const apr_array_header_t *targets,
576 svn_depth_t depth,
577 svn_client_ctx_t *ctx,
578 apr_pool_t *pool);
580 svn_error_t *
581 svn_cl__args_to_target_array_print_reserved(apr_array_header_t **targets_p,
582 apr_getopt_t *os,
583 apr_array_header_t *known_targets,
584 apr_pool_t *pool);
586 #ifdef __cplusplus
588 #endif /* __cplusplus */
590 #endif /* SVN_CL_H */