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