1 /*
2  * cl.h:  shared stuff in the command line program
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23 
24 /* ==================================================================== */
25 
26 
27 
28 #ifndef SVN_CL_H
29 #define SVN_CL_H
30 
31 /*** Includes. ***/
32 #include <apr_tables.h>
33 #include <apr_getopt.h>
34 
35 #include "svn_types.h"
36 #include "svn_wc.h"
37 #include "svn_client.h"
38 #include "svn_string.h"
39 #include "svn_opt.h"
40 #include "svn_auth.h"
41 #include "svn_cmdline.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 
47 
48 /*** Option processing ***/
49 
50 /* --accept actions */
51 typedef enum svn_cl__accept_t
52 {
53   /* invalid accept action */
54   svn_cl__accept_invalid = -2,
55 
56   /* unspecified accept action */
57   svn_cl__accept_unspecified = -1,
58 
59   /* Leave conflicts alone, for later resolution. */
60   svn_cl__accept_postpone,
61 
62   /* Resolve the conflict with the pre-conflict base file. */
63   svn_cl__accept_base,
64 
65   /* Resolve the conflict with the current working file. */
66   svn_cl__accept_working,
67 
68   /* Resolve the conflicted hunks by choosing the corresponding text
69      from the pre-conflict working copy file. */
70   svn_cl__accept_mine_conflict,
71 
72   /* Resolve the conflicted hunks by choosing the corresponding text
73      from the post-conflict base copy file. */
74   svn_cl__accept_theirs_conflict,
75 
76   /* Resolve the conflict by taking the entire pre-conflict working
77      copy file. */
78   svn_cl__accept_mine_full,
79 
80   /* Resolve the conflict by taking the entire post-conflict base file. */
81   svn_cl__accept_theirs_full,
82 
83   /* Launch user's editor and resolve conflict with edited file. */
84   svn_cl__accept_edit,
85 
86   /* Launch user's resolver and resolve conflict with edited file. */
87   svn_cl__accept_launch,
88 
89   /* Use recommended resolution if available, else leave the conflict alone. */
90   svn_cl__accept_recommended
91 
92 } svn_cl__accept_t;
93 
94 /* --accept action user input words */
95 #define SVN_CL__ACCEPT_POSTPONE "postpone"
96 #define SVN_CL__ACCEPT_BASE "base"
97 #define SVN_CL__ACCEPT_WORKING "working"
98 #define SVN_CL__ACCEPT_MINE_CONFLICT "mine-conflict"
99 #define SVN_CL__ACCEPT_THEIRS_CONFLICT "theirs-conflict"
100 #define SVN_CL__ACCEPT_MINE_FULL "mine-full"
101 #define SVN_CL__ACCEPT_THEIRS_FULL "theirs-full"
102 #define SVN_CL__ACCEPT_EDIT "edit"
103 #define SVN_CL__ACCEPT_LAUNCH "launch"
104 #define SVN_CL__ACCEPT_RECOMMENDED "recommended"
105 
106 /* Return the svn_cl__accept_t value corresponding to WORD, using exact
107  * case-sensitive string comparison. Return svn_cl__accept_invalid if WORD
108  * is empty or is not one of the known values. */
109 svn_cl__accept_t
110 svn_cl__accept_from_word(const char *word);
111 
112 
113 /*** Mergeinfo flavors. ***/
114 
115 /* --show-revs values */
116 typedef enum svn_cl__show_revs_t {
117   svn_cl__show_revs_invalid = -1,
118   svn_cl__show_revs_merged,
119   svn_cl__show_revs_eligible
120 } svn_cl__show_revs_t;
121 
122 /* --show-revs user input words */
123 #define SVN_CL__SHOW_REVS_MERGED   "merged"
124 #define SVN_CL__SHOW_REVS_ELIGIBLE "eligible"
125 
126 /* Return svn_cl__show_revs_t value corresponding to word. */
127 svn_cl__show_revs_t
128 svn_cl__show_revs_from_word(const char *word);
129 
130 
131 /* Unit types for file size conversion. */
132 typedef enum svn_cl__size_unit_t
133   {
134     SVN_CL__SIZE_UNIT_NONE = 0,       /* Default, no conversion. */
135     SVN_CL__SIZE_UNIT_XML = -1,       /* Conversion for XML output. */
136     SVN_CL__SIZE_UNIT_BASE_10 = 1000, /* Use base-10 SI units. */
137     SVN_CL__SIZE_UNIT_BASE_2 = 1024   /* Use base-2 SI units. */
138   } svn_cl__size_unit_t;
139 
140 
141 /*** Command dispatch. ***/
142 
143 /* Hold results of option processing that are shared by multiple
144    commands. */
145 typedef struct svn_cl__opt_state_t
146 {
147   /* An array of svn_opt_revision_range_t *'s representing revisions
148      ranges indicated on the command-line via the -r and -c options.
149      For each range in the list, if only one revision was provided
150      (-rN), its 'end' member remains 'svn_opt_revision_unspecified'.
151      This array always has at least one element, even if that is a
152      null range in which both ends are 'svn_opt_revision_unspecified'. */
153   apr_array_header_t *revision_ranges;
154 
155   /* These are simply a copy of the range start and end values present
156      in the first item of the revision_ranges list. */
157   svn_opt_revision_t start_revision;
158   svn_opt_revision_t end_revision;
159 
160   /* Flag which is only set if the '-c' option was used. */
161   svn_boolean_t used_change_arg;
162 
163   /* Flag which is only set if the '-r' option was used. */
164   svn_boolean_t used_revision_arg;
165 
166   /* Max number of log messages to get back from svn_client_log2. */
167   int limit;
168 
169   /* After option processing is done, reflects the switch actually
170      given on the command line, or svn_depth_unknown if none. */
171   svn_depth_t depth;
172 
173   /* Was --no-unlock specified? */
174   svn_boolean_t no_unlock;
175 
176   const char *message;           /* log message (not converted to UTF-8) */
177   svn_boolean_t force;           /* be more forceful, as in "svn rm -f ..." */
178   svn_boolean_t force_log;       /* force validity of a suspect log msg file */
179   svn_boolean_t incremental;     /* yield output suitable for concatenation */
180   svn_boolean_t quiet;           /* sssh...avoid unnecessary output */
181   svn_boolean_t non_interactive; /* do no interactive prompting */
182   svn_boolean_t version;         /* print version information */
183   svn_boolean_t verbose;         /* be verbose */
184   svn_boolean_t update;          /* contact the server for the full story */
185   svn_stringbuf_t *filedata;     /* contents of file used as option data
186                                     (not converted to UTF-8) */
187   const char *encoding;          /* the locale/encoding of 'message' and of
188                                     'filedata' (not converted to UTF-8) */
189   svn_boolean_t help;            /* print usage message */
190   const char *auth_username;     /* auth username */
191   const char *auth_password;     /* auth password */
192   svn_boolean_t auth_password_from_stdin; /* read password from stdin */
193   const char *extensions;        /* subprocess extension args */
194   apr_array_header_t *targets;   /* target list from file */
195   svn_boolean_t xml;             /* output in xml, e.g., "svn log --xml" */
196   svn_boolean_t no_ignore;       /* disregard default ignores & svn:ignore's */
197   svn_boolean_t no_auth_cache;   /* do not cache authentication information */
198   struct
199     {
200   const char *diff_cmd;              /* the external diff command to use
201                                         (not converted to UTF-8) */
202   svn_boolean_t internal_diff;       /* override diff_cmd in config file */
203   svn_boolean_t no_diff_added;       /* do not show diffs for deleted files */
204   svn_boolean_t no_diff_deleted;     /* do not show diffs for deleted files */
205   svn_boolean_t show_copies_as_adds; /* do not diff copies with their source */
206   svn_boolean_t notice_ancestry;     /* notice ancestry for diff-y operations */
207   svn_boolean_t summarize;           /* create a summary of a diff */
208   svn_boolean_t use_git_diff_format; /* Use git's extended diff format */
209   svn_boolean_t ignore_properties;   /* ignore properties */
210   svn_boolean_t properties_only;     /* Show properties only */
211   svn_boolean_t patch_compatible;    /* Output compatible with GNU patch */
212     } diff;
213   svn_boolean_t ignore_ancestry; /* ignore ancestry for merge-y operations */
214   svn_boolean_t ignore_externals;/* ignore externals definitions */
215   svn_boolean_t stop_on_copy;    /* don't cross copies during processing */
216   svn_boolean_t dry_run;         /* try operation but make no changes */
217   svn_boolean_t revprop;         /* operate on a revision property */
218   const char *merge_cmd;         /* the external merge command to use
219                                     (not converted to UTF-8) */
220   const char *editor_cmd;        /* the external editor command to use
221                                     (not converted to UTF-8) */
222   svn_boolean_t record_only;     /* whether to record mergeinfo */
223   const char *old_target;        /* diff target */
224   const char *new_target;        /* diff target */
225   svn_boolean_t relocate;        /* rewrite urls (svn switch) */
226   const char *config_dir;        /* over-riding configuration directory */
227   apr_array_header_t *config_options; /* over-riding configuration options */
228   svn_boolean_t autoprops;       /* enable automatic properties */
229   svn_boolean_t no_autoprops;    /* disable automatic properties */
230   const char *native_eol;        /* override system standard eol marker */
231   svn_boolean_t remove;          /* deassociate a changelist */
232   apr_array_header_t *changelists; /* changelist filters */
233   svn_boolean_t keep_changelists;/* don't remove changelists after commit */
234   svn_boolean_t keep_local;      /* delete path only from repository */
235   svn_boolean_t all_revprops;    /* retrieve all revprops */
236   svn_boolean_t no_revprops;     /* retrieve no revprops */
237   apr_hash_t *revprop_table;     /* table of revision properties to get/set
238                                     (not converted to UTF-8) */
239   svn_boolean_t parents;         /* create intermediate directories */
240   svn_boolean_t use_merge_history; /* use/display extra merge information */
241   svn_cl__accept_t accept_which;   /* how to handle conflicts */
242   svn_cl__show_revs_t show_revs;   /* mergeinfo flavor */
243   svn_depth_t set_depth;           /* new sticky ambient depth value */
244   svn_boolean_t reintegrate;      /* use "reintegrate" merge-source heuristic */
245   /* trust server SSL certs that would otherwise be rejected as "untrusted" */
246   svn_boolean_t trust_server_cert_unknown_ca;
247   svn_boolean_t trust_server_cert_cn_mismatch;
248   svn_boolean_t trust_server_cert_expired;
249   svn_boolean_t trust_server_cert_not_yet_valid;
250   svn_boolean_t trust_server_cert_other_failure;
251   int strip; /* number of leading path components to strip */
252   svn_boolean_t ignore_keywords;   /* do not expand keywords */
253   svn_boolean_t reverse_diff;      /* reverse a diff (e.g. when patching) */
254   svn_boolean_t ignore_whitespace; /* don't account for whitespace when
255                                       patching */
256   svn_boolean_t show_diff;         /* produce diff output (maps to --diff) */
257   svn_boolean_t allow_mixed_rev;   /* Allow operation on mixed-revision WC */
258   svn_boolean_t include_externals; /* Recurses (in)to file & dir externals */
259   svn_boolean_t show_inherited_props;  /* get inherited properties */
260   apr_array_header_t* search_patterns; /* pattern arguments for --search */
261   svn_boolean_t mergeinfo_log;     /* show log message in mergeinfo command */
262   svn_boolean_t remove_unversioned;/* remove unversioned items */
263   svn_boolean_t remove_ignored;    /* remove ignored items */
264   svn_boolean_t remove_added;      /* reverting added item also removes it */
265   svn_boolean_t no_newline;        /* do not output the trailing newline */
266   svn_boolean_t show_passwords;    /* show cached passwords */
267   svn_boolean_t pin_externals;     /* pin externals to last-changed revisions */
268   const char *show_item;           /* print only the given item */
269   svn_boolean_t adds_as_modification; /* update 'add vs add' no tree conflict */
270   svn_boolean_t vacuum_pristines; /* remove unreferenced pristines */
271   svn_boolean_t drop;             /* drop shelf after successful unshelve */
272   svn_cl__size_unit_t file_size_unit; /* file size format */
273   enum svn_cl__viewspec_t {
274       svn_cl__viewspec_unspecified = 0 /* default */,
275       svn_cl__viewspec_classic,
276       svn_cl__viewspec_svn11
277   } viewspec;                     /* value of --x-viewspec */
278 } svn_cl__opt_state_t;
279 
280 /* Conflict stats for operations such as update and merge. */
281 typedef struct svn_cl__conflict_stats_t svn_cl__conflict_stats_t;
282 
283 typedef struct svn_cl__cmd_baton_t
284 {
285   svn_cl__opt_state_t *opt_state;
286   svn_cl__conflict_stats_t *conflict_stats;
287   svn_client_ctx_t *ctx;
288 } svn_cl__cmd_baton_t;
289 
290 
291 /* Add an identifier here for long options that don't have a short
292    option. Options that have both long and short options should just
293    use the short option letter as identifier.  */
294 typedef enum svn_cl__longopt_t {
295   opt_auth_password = SVN_OPT_FIRST_LONGOPT_ID,
296   opt_auth_password_from_stdin,
297   opt_auth_username,
298   opt_autoprops,
299   opt_changelist,
300   opt_config_dir,
301   opt_config_options,
302   /* diff options */
303   opt_diff_cmd,
304   opt_internal_diff,
305   opt_no_diff_added,
306   opt_no_diff_deleted,
307   opt_show_copies_as_adds,
308   opt_notice_ancestry,
309   opt_summarize,
310   opt_use_git_diff_format,
311   opt_ignore_properties,
312   opt_properties_only,
313   opt_patch_compatible,
314   /* end of diff options */
315   opt_dry_run,
316   opt_editor_cmd,
317   opt_encoding,
318   opt_force_log,
319   opt_force,
320   opt_keep_changelists,
321   opt_ignore_ancestry,
322   opt_ignore_externals,
323   opt_incremental,
324   opt_merge_cmd,
325   opt_native_eol,
326   opt_new_cmd,
327   opt_no_auth_cache,
328   opt_no_autoprops,
329   opt_no_ignore,
330   opt_no_unlock,
331   opt_non_interactive,
332   opt_force_interactive,
333   opt_old_cmd,
334   opt_record_only,
335   opt_relocate,
336   opt_remove,
337   opt_revprop,
338   opt_stop_on_copy,
339   opt_strict,                   /* ### DEPRECATED */
340   opt_targets,
341   opt_depth,
342   opt_set_depth,
343   opt_version,
344   opt_xml,
345   opt_keep_local,
346   opt_with_revprop,
347   opt_with_all_revprops,
348   opt_with_no_revprops,
349   opt_parents,
350   opt_accept,
351   opt_show_revs,
352   opt_reintegrate,
353   opt_trust_server_cert,
354   opt_trust_server_cert_failures,
355   opt_strip,
356   opt_ignore_keywords,
357   opt_reverse_diff,
358   opt_ignore_whitespace,
359   opt_diff,
360   opt_allow_mixed_revisions,
361   opt_include_externals,
362   opt_show_inherited_props,
363   opt_search,
364   opt_search_and,
365   opt_mergeinfo_log,
366   opt_remove_unversioned,
367   opt_remove_ignored,
368   opt_remove_added,
369   opt_no_newline,
370   opt_show_passwords,
371   opt_pin_externals,
372   opt_show_item,
373   opt_adds_as_modification,
374   opt_vacuum_pristines,
375   opt_drop,
376   opt_viewspec,
377 } svn_cl__longopt_t;
378 
379 /* Options for giving a log message.  (Some of these also have other uses.)
380  */
381 #define SVN_CL__LOG_MSG_OPTIONS 'm', 'F', \
382                                 opt_force_log, \
383                                 opt_editor_cmd, \
384                                 opt_encoding, \
385                                 opt_with_revprop
386 
387 
388 /* Declare all the command procedures */
389 svn_opt_subcommand_t
390   svn_cl__add,
391   svn_cl__auth,
392   svn_cl__blame,
393   svn_cl__cat,
394   svn_cl__changelist,
395   svn_cl__checkout,
396   svn_cl__cleanup,
397   svn_cl__commit,
398   svn_cl__copy,
399   svn_cl__delete,
400   svn_cl__diff,
401   svn_cl__export,
402   svn_cl__help,
403   svn_cl__import,
404   svn_cl__info,
405   svn_cl__lock,
406   svn_cl__log,
407   svn_cl__list,
408   svn_cl__merge,
409   svn_cl__mergeinfo,
410   svn_cl__mkdir,
411   svn_cl__move,
412   svn_cl__patch,
413   svn_cl__propdel,
414   svn_cl__propedit,
415   svn_cl__propget,
416   svn_cl__proplist,
417   svn_cl__propset,
418   svn_cl__relocate,
419   svn_cl__revert,
420   svn_cl__resolve,
421   svn_cl__resolved,
422   svn_cl__status,
423   svn_cl__switch,
424   svn_cl__unlock,
425   svn_cl__update,
426   svn_cl__upgrade;
427 
428 
429 /* See definition in svn.c for documentation. */
430 extern const svn_opt_subcommand_desc3_t *svn_cl__cmd_table;
431 
432 /* See definition in svn.c for documentation. */
433 extern const int svn_cl__global_options[];
434 
435 /* See definition in svn.c for documentation. */
436 extern const apr_getopt_option_t svn_cl__options[];
437 
438 
439 /* A helper for the many subcommands that wish to merely warn when
440  * invoked on an unversioned, nonexistent, or otherwise innocuously
441  * errorful resource.  Meant to be wrapped with SVN_ERR().
442  *
443  * If ERR is null, return SVN_NO_ERROR.
444  *
445  * Else if ERR->apr_err is one of the error codes supplied in varargs,
446  * then handle ERR as a warning (unless QUIET is true), clear ERR, and
447  * return SVN_NO_ERROR, and push the value of ERR->apr_err into the
448  * ERRORS_SEEN array, if ERRORS_SEEN is not NULL.
449  *
450  * Else return ERR.
451  *
452  * Typically, error codes like SVN_ERR_UNVERSIONED_RESOURCE,
453  * SVN_ERR_ENTRY_NOT_FOUND, etc, are supplied in varargs.  Don't
454  * forget to terminate the argument list with 0 (or APR_SUCCESS).
455  */
456 svn_error_t *
457 svn_cl__try(svn_error_t *err,
458             apr_array_header_t *errors_seen,
459             svn_boolean_t quiet,
460             ...);
461 
462 
463 /* Our cancellation callback. */
464 extern svn_cancel_func_t svn_cl__check_cancel;
465 
466 
467 
468 /* Various conflict-resolution callbacks. */
469 
470 /* Opaque baton type for svn_cl__conflict_func_interactive(). */
471 typedef struct svn_cl__interactive_conflict_baton_t
472   svn_cl__interactive_conflict_baton_t;
473 
474 /* Return a new, initialized, conflict stats structure, allocated in
475  * POOL. */
476 svn_cl__conflict_stats_t *
477 svn_cl__conflict_stats_create(apr_pool_t *pool);
478 
479 /* Update CONFLICT_STATS to reflect that a conflict on PATH_LOCAL of kind
480  * CONFLICT_KIND is resolved.  (There is no support for updating the
481  * 'skipped paths' stats, since skips cannot be 'resolved'.) */
482 void
483 svn_cl__conflict_stats_resolved(svn_cl__conflict_stats_t *conflict_stats,
484                                 const char *path_local,
485                                 svn_wc_conflict_kind_t conflict_kind);
486 
487 /* Set *CONFLICTED_PATHS to the conflicted paths contained in CONFLICT_STATS.
488  * If no conflicted path exists, set *CONFLICTED_PATHS to NULL. */
489 svn_error_t *
490 svn_cl__conflict_stats_get_paths(apr_array_header_t **conflicted_paths,
491                                  svn_cl__conflict_stats_t *conflict_stats,
492                                  apr_pool_t *result_pool,
493                                  apr_pool_t *scratch_pool);
494 
495 /* Print the conflict stats accumulated in CONFLICT_STATS.
496  *
497  * Return any error encountered during printing.
498  * See also svn_cl__notifier_print_conflict_stats().
499  */
500 svn_error_t *
501 svn_cl__print_conflict_stats(svn_cl__conflict_stats_t *conflict_stats,
502                              apr_pool_t *scratch_pool);
503 
504 /*
505  * Interactively resolve the conflict a @a CONFLICT.
506  * TODO: more docs
507  */
508 svn_error_t *
509 svn_cl__resolve_conflict(svn_boolean_t *quit,
510                          svn_boolean_t *external_failed,
511                          svn_boolean_t *printed_summary,
512                          svn_client_conflict_t *conflict,
513                          svn_cl__accept_t accept_which,
514                          const char *editor_cmd,
515                          const char *path_prefix,
516                          svn_cmdline_prompt_baton_t *pb,
517                          svn_cl__conflict_stats_t *conflict_stats,
518                          svn_client_ctx_t *ctx,
519                          apr_pool_t *scratch_pool);
520 
521 /*
522  * Interactively resolve conflicts for all TARGETS.
523  * TODO: more docs
524  */
525 svn_error_t *
526 svn_cl__walk_conflicts(apr_array_header_t *targets,
527                        svn_cl__conflict_stats_t *conflict_stats,
528                        svn_cl__opt_state_t *opt_state,
529                        svn_client_ctx_t *ctx,
530                        apr_pool_t *scratch_pool);
531 
532 
533 /*** Command-line output functions -- printing to the user. ***/
534 
535 /* Print out commit information found in COMMIT_INFO to the console.
536  * POOL is used for temporay allocations.
537  * COMMIT_INFO should not be NULL.
538  *
539  * This function implements svn_commit_callback2_t.
540  */
541 svn_error_t *
542 svn_cl__print_commit_info(const svn_commit_info_t *commit_info,
543                           void *baton,
544                           apr_pool_t *pool);
545 
546 
547 /* Convert the date in DATA to a human-readable UTF-8-encoded string
548  * *HUMAN_CSTRING, or set the latter to "(invalid date)" if DATA is not
549  * a valid date.  DATA should be as expected by svn_time_from_cstring().
550  *
551  * Do all allocations in POOL.
552  */
553 svn_error_t *
554 svn_cl__time_cstring_to_human_cstring(const char **human_cstring,
555                                       const char *data,
556                                       apr_pool_t *pool);
557 
558 
559 /* Print STATUS for PATH to stdout for human consumption.  Prints in
560    abbreviated format by default, or DETAILED format if flag is set.
561 
562    When SUPPRESS_EXTERNALS_PLACEHOLDERS is set, avoid printing
563    externals placeholder lines ("X lines").
564 
565    When DETAILED is set, use SHOW_LAST_COMMITTED to toggle display of
566    the last-committed-revision and last-committed-author.
567 
568    If SKIP_UNRECOGNIZED is TRUE, this function will not print out
569    unversioned items found in the working copy.
570 
571    When DETAILED is set, and REPOS_LOCKS is set, treat missing repository locks
572    as broken WC locks.
573 
574    Increment *TEXT_CONFLICTS, *PROP_CONFLICTS, or *TREE_CONFLICTS if
575    a conflict was encountered.
576 
577    Use TARGET_ABSPATH and TARGET_PATH to shorten PATH into something
578    relative to the target as necessary.
579 */
580 svn_error_t *
581 svn_cl__print_status(const char *target_abspath,
582                      const char *target_path,
583                      const char *path,
584                      const svn_client_status_t *status,
585                      svn_boolean_t suppress_externals_placeholders,
586                      svn_boolean_t detailed,
587                      svn_boolean_t show_last_committed,
588                      svn_boolean_t skip_unrecognized,
589                      svn_boolean_t repos_locks,
590                      unsigned int *text_conflicts,
591                      unsigned int *prop_conflicts,
592                      unsigned int *tree_conflicts,
593                      svn_client_ctx_t *ctx,
594                      apr_pool_t *pool);
595 
596 
597 /* Print STATUS for PATH in XML to stdout.  Use POOL for temporary
598    allocations.
599 
600    Use TARGET_ABSPATH and TARGET_PATH to shorten PATH into something
601    relative to the target as necessary.
602  */
603 svn_error_t *
604 svn_cl__print_status_xml(const char *target_abspath,
605                          const char *target_path,
606                          const char *path,
607                          const svn_client_status_t *status,
608                          svn_client_ctx_t *ctx,
609                          apr_pool_t *pool);
610 
611 /* Output a commit xml element to *OUTSTR.  If *OUTSTR is NULL, allocate it
612    first from POOL, otherwise append to it.  If AUTHOR or DATE is
613    NULL, it will be omitted. */
614 void
615 svn_cl__print_xml_commit(svn_stringbuf_t **outstr,
616                          svn_revnum_t revision,
617                          const char *author,
618                          const char *date,
619                          apr_pool_t *pool);
620 
621 /* Output an XML "<lock>" element describing LOCK to *OUTSTR.  If *OUTSTR is
622    NULL, allocate it first from POOL, otherwise append to it. */
623 void
624 svn_cl__print_xml_lock(svn_stringbuf_t **outstr,
625                        const svn_lock_t *lock,
626                        apr_pool_t *pool);
627 
628 /* Do the following things that are commonly required before accessing revision
629    properties.  Ensure that REVISION is specified explicitly and is not
630    relative to a working-copy item.  Ensure that exactly one target is
631    specified in TARGETS.  Set *URL to the URL of the target.  Return an
632    appropriate error if any of those checks or operations fail. Use CTX for
633    accessing the working copy
634  */
635 svn_error_t *
636 svn_cl__revprop_prepare(const svn_opt_revision_t *revision,
637                         const apr_array_header_t *targets,
638                         const char **URL,
639                         svn_client_ctx_t *ctx,
640                         apr_pool_t *pool);
641 
642 /* Search for a merge tool command in environment variables,
643    and use it to perform the merge of the four given files.
644    WC_PATH is the path of the file that is in conflict, relative
645    to the merge target.
646    Use POOL for all allocations.
647 
648    CONFIG is a hash of svn_config_t * items keyed on a configuration
649    category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.
650 
651    Upon success, set *REMAINS_IN_CONFLICT to indicate whether the
652    merge result contains conflict markers.
653    */
654 svn_error_t *
655 svn_cl__merge_file_externally(const char *base_path,
656                               const char *their_path,
657                               const char *my_path,
658                               const char *merged_path,
659                               const char *wc_path,
660                               apr_hash_t *config,
661                               svn_boolean_t *remains_in_conflict,
662                               apr_pool_t *pool);
663 
664 /* Like svn_cl__merge_file_externally, but using a built-in merge tool
665  * with help from an external editor specified by EDITOR_CMD. */
666 svn_error_t *
667 svn_cl__merge_file(svn_boolean_t *remains_in_conflict,
668                    const char *base_path,
669                    const char *their_path,
670                    const char *my_path,
671                    const char *merged_path,
672                    const char *wc_path,
673                    const char *path_prefix,
674                    const char *editor_cmd,
675                    apr_hash_t *config,
676                    svn_cancel_func_t cancel_func,
677                    void *cancel_baton,
678                    apr_pool_t *scratch_pool);
679 
680 
681 /*** Notification functions to display results on the terminal. */
682 
683 /* Set *NOTIFY_FUNC_P and *NOTIFY_BATON_P to a notifier/baton for all
684  * operations, allocated in POOL.
685  */
686 svn_error_t *
687 svn_cl__get_notifier(svn_wc_notify_func2_t *notify_func_p,
688                      void **notify_baton_p,
689                      svn_cl__conflict_stats_t *conflict_stats,
690                      apr_pool_t *pool);
691 
692 /* Make the notifier for use with BATON print the appropriate summary
693  * line at the end of the output.
694  */
695 svn_error_t *
696 svn_cl__notifier_mark_checkout(void *baton);
697 
698 /* Make the notifier for use with BATON print the appropriate summary
699  * line at the end of the output.
700  */
701 svn_error_t *
702 svn_cl__notifier_mark_export(void *baton);
703 
704 /* Make the notifier for use with BATON print the appropriate notifications
705  * for a wc to repository copy
706  */
707 svn_error_t *
708 svn_cl__notifier_mark_wc_to_repos_copy(void *baton);
709 
710 /* Baton for use with svn_cl__check_externals_failed_notify_wrapper(). */
711 struct svn_cl__check_externals_failed_notify_baton
712 {
713   svn_wc_notify_func2_t wrapped_func; /* The "real" notify_func2. */
714   void *wrapped_baton;                /* The "real" notify_func2 baton. */
715   svn_boolean_t had_externals_error;  /* Did something fail in an external? */
716 };
717 
718 /* Notification function wrapper (implements `svn_wc_notify_func2_t').
719    Use with an svn_cl__check_externals_failed_notify_baton BATON. */
720 void
721 svn_cl__check_externals_failed_notify_wrapper(void *baton,
722                                               const svn_wc_notify_t *n,
723                                               apr_pool_t *pool);
724 
725 /* Print the conflict stats accumulated in BATON, which is the
726  * notifier baton from svn_cl__get_notifier().  This is just like
727  * calling svn_cl__print_conflict_stats().
728  *
729  * Return any error encountered during printing.
730  */
731 svn_error_t *
732 svn_cl__notifier_print_conflict_stats(void *baton, apr_pool_t *scratch_pool);
733 
734 
735 /*** Log message callback stuffs. ***/
736 
737 /* Allocate in POOL a baton for use with svn_cl__get_log_message().
738 
739    OPT_STATE is the set of command-line options given.
740 
741    BASE_DIR is a directory in which to create temporary files if an
742    external editor is used to edit the log message.  If BASE_DIR is
743    NULL, the current working directory (`.') will be used, and
744    therefore the user must have the proper permissions on that
745    directory.  ### todo: What *should* happen in the NULL case is that
746    we ask APR to tell us where a suitable tmp directory is (like, /tmp
747    on Unix and C:\Windows\Temp on Win32 or something), and use it.
748    But APR doesn't yet have that capability.
749 
750    CONFIG is a client configuration hash of svn_config_t * items keyed
751    on config categories, and may be NULL.
752 
753    NOTE: While the baton itself will be allocated from POOL, the items
754    add to it are added by reference, not duped into POOL!*/
755 svn_error_t *
756 svn_cl__make_log_msg_baton(void **baton,
757                            svn_cl__opt_state_t *opt_state,
758                            const char *base_dir,
759                            apr_hash_t *config,
760                            apr_pool_t *pool);
761 
762 /* A function of type svn_client_get_commit_log3_t. */
763 svn_error_t *
764 svn_cl__get_log_message(const char **log_msg,
765                         const char **tmp_file,
766                         const apr_array_header_t *commit_items,
767                         void *baton,
768                         apr_pool_t *pool);
769 
770 /* Handle the cleanup of a log message, using the data in the
771    LOG_MSG_BATON, in the face of COMMIT_ERR.  This may mean removing a
772    temporary file left by an external editor, or it may be a complete
773    no-op.  COMMIT_ERR may be NULL to indicate to indicate that the
774    function should act as though no commit error occurred. Use POOL
775    for temporary allocations.
776 
777    All error returns from this function are guaranteed to at least
778    include COMMIT_ERR, and perhaps additional errors attached to the
779    end of COMMIT_ERR's chain.  */
780 svn_error_t *
781 svn_cl__cleanup_log_msg(void *log_msg_baton,
782                         svn_error_t *commit_err,
783                         apr_pool_t *pool);
784 
785 /* Add a message about --force if appropriate */
786 svn_error_t *
787 svn_cl__may_need_force(svn_error_t *err);
788 
789 /* Write the STRING to the stdio STREAM, returning an error if it fails.
790 
791    This function is equal to svn_cmdline_fputs() minus the utf8->local
792    encoding translation.  */
793 svn_error_t *
794 svn_cl__error_checked_fputs(const char *string, FILE* stream);
795 
796 /* If STRING is non-null, append it, wrapped in a simple XML CDATA element
797    named TAGNAME, to the string SB.  Use POOL for temporary allocations. */
798 void
799 svn_cl__xml_tagged_cdata(svn_stringbuf_t **sb,
800                          apr_pool_t *pool,
801                          const char *tagname,
802                          const char *string);
803 
804 /* Print the XML prolog and document root element start-tag to stdout, using
805    TAGNAME as the root element name.  Use POOL for temporary allocations. */
806 svn_error_t *
807 svn_cl__xml_print_header(const char *tagname, apr_pool_t *pool);
808 
809 /* Print the XML document root element end-tag to stdout, using TAGNAME as the
810    root element name.  Use POOL for temporary allocations. */
811 svn_error_t *
812 svn_cl__xml_print_footer(const char *tagname, apr_pool_t *pool);
813 
814 
815 /* For use in XML output, return a non-localised string representation
816  * of KIND, being "none" or "dir" or "file" or, in any other case,
817  * the empty string. */
818 const char *
819 svn_cl__node_kind_str_xml(svn_node_kind_t kind);
820 
821 /* Return a (possibly localised) string representation of KIND, being "none" or
822    "dir" or "file" or, in any other case, the empty string. */
823 const char *
824 svn_cl__node_kind_str_human_readable(svn_node_kind_t kind);
825 
826 /* Set *RESULT to the size of a file, formatted according to BASE.
827    For base-10 and base-2 units, the size is constrained to at most
828    three significant digits.
829 
830    If LONG_UNITS is TRUE, any unit suffixes will be the whole SI symbol,
831    e.g., KiB, MiB, etc; otherwise only the first letters will be used.
832 
833    File sizes are never negative, so we don't handle that case other than
834    making sure that the scale adjustment will work.
835 
836    The result will be allocated from RESULT_POOL. */
837 svn_error_t *
838 svn_cl__format_file_size(const char **result,
839                          svn_filesize_t size,
840                          svn_cl__size_unit_t base,
841                          svn_boolean_t long_units,
842                          apr_pool_t *result_pool);
843 
844 
845 /** Provides an XML name for a given OPERATION.
846  * Note: POOL is currently not used.
847  */
848 const char *
849 svn_cl__operation_str_xml(svn_wc_operation_t operation, apr_pool_t *pool);
850 
851 /** Return a possibly localized human readable string for
852  * a given OPERATION.
853  * Note: POOL is currently not used.
854  */
855 const char *
856 svn_cl__operation_str_human_readable(svn_wc_operation_t operation,
857                                      apr_pool_t *pool);
858 
859 
860 /* What use is a property name intended for.
861    Used by svn_cl__check_svn_prop_name to customize error messages. */
862 typedef enum svn_cl__prop_use_e
863   {
864     svn_cl__prop_use_set,       /* setting the property */
865     svn_cl__prop_use_edit,      /* editing the property */
866     svn_cl__prop_use_use        /* using the property name */
867   }
868 svn_cl__prop_use_t;
869 
870 /* If PROPNAME looks like but is not identical to one of the svn:
871  * poperties, raise an error and suggest a better spelling. Names that
872  * raise errors look like this:
873  *
874  *   - start with svn: but do not exactly match a known property; or,
875  *   - start with a 3-letter prefix that differs in only one letter
876  *     from "svn:", and the rest exactly matches a known propery.
877  *
878  * If REVPROP is TRUE, only check revision property names; otherwise
879  * only check node property names.
880  *
881  * Use SCRATCH_POOL for temporary allocations.
882  */
883 svn_error_t *
884 svn_cl__check_svn_prop_name(const char *propname,
885                             svn_boolean_t revprop,
886                             svn_cl__prop_use_t prop_use,
887                             apr_pool_t *scratch_pool);
888 
889 /* If PROPNAME is one of the svn: properties with a boolean value, and
890  * PROPVAL looks like an attempt to turn the property off (i.e., it's
891  * "off", "no", "false", or ""), then print a warning to the user that
892  * setting the property to this value might not do what they expect.
893  * Perform temporary allocations in POOL.
894  */
895 void
896 svn_cl__check_boolean_prop_val(const char *propname,
897                                const char *propval,
898                                apr_pool_t *pool);
899 
900 /* De-streamifying wrapper around svn_client_get_changelists(), which
901    is called for each target in TARGETS to populate *PATHS (a list of
902    paths assigned to one of the CHANGELISTS.
903    If all targets are to be included, may set *PATHS to TARGETS without
904    reallocating. */
905 svn_error_t *
906 svn_cl__changelist_paths(apr_array_header_t **paths,
907                          const apr_array_header_t *changelists,
908                          const apr_array_header_t *targets,
909                          svn_depth_t depth,
910                          svn_client_ctx_t *ctx,
911                          apr_pool_t *result_pool,
912                          apr_pool_t *scratch_pool);
913 
914 /* Like svn_client_args_to_target_array() but, if the only error is that some
915  * arguments are reserved file names, then print warning messages for those
916  * targets, store the rest of the targets in TARGETS_P and return success. */
917 svn_error_t *
918 svn_cl__args_to_target_array_print_reserved(apr_array_header_t **targets_p,
919                                             apr_getopt_t *os,
920                                             const apr_array_header_t *known_targets,
921                                             svn_client_ctx_t *ctx,
922                                             svn_boolean_t keep_dest_origpath_on_truepath_collision,
923                                             apr_pool_t *pool);
924 
925 /* Return a string showing a conflicted node's kind, URL and revision,
926  * to the extent that that information is available. If REPOS_ROOT_URL or
927  * REPOS_RELPATH are NULL, this prints just a 'none' node kind.
928  * WC_REPOS_ROOT_URL should reflect the target working copy's repository
929  * root URL. If the node is from that same URL, the printed URL is abbreviated
930  * to caret notation (^/). WC_REPOS_ROOT_URL may be NULL, in which case
931  * this function tries to print the conflicted node's complete URL. */
932 const char *
933 svn_cl__node_description(const char *repos_root_url,
934                          const char *repos_relpath,
935                          svn_revnum_t peg_rev,
936                          svn_node_kind_t node_kind,
937                          const char *wc_repos_root_URL,
938                          apr_pool_t *pool);
939 
940 /* Return, in @a *true_targets_p, a shallow copy of @a targets with any
941  * empty peg revision specifier snipped off the end of each element.  If any
942  * target has a non-empty peg revision specifier, throw an error.  The user
943  * may have specified a peg revision where it doesn't make sense to do so,
944  * or may have forgotten to escape an '@' character in a filename.
945  *
946  * This function is useful for subcommands for which peg revisions
947  * do not make any sense. Such subcommands still need to allow an empty
948  * peg revision to be specified on the command line so that users of
949  * the command line client can consistently escape '@' characters
950  * in filenames by appending an '@' character, regardless of the
951  * subcommand being used.
952  *
953  * It is safe to pass the address of @a targets as @a true_targets_p.
954  *
955  * Do all allocations in @a pool. */
956 svn_error_t *
957 svn_cl__eat_peg_revisions(apr_array_header_t **true_targets_p,
958                           const apr_array_header_t *targets,
959                           apr_pool_t *pool);
960 
961 /* Return an error if TARGETS contains a mixture of URLs and paths; otherwise
962  * return SVN_NO_ERROR. */
963 svn_error_t *
964 svn_cl__assert_homogeneous_target_type(const apr_array_header_t *targets);
965 
966 /* Return an error if TARGETS contains a URL; otherwise return SVN_NO_ERROR. */
967 svn_error_t *
968 svn_cl__check_targets_are_local_paths(const apr_array_header_t *targets);
969 
970 /* Return an error if TARGET is a URL; otherwise return SVN_NO_ERROR. */
971 svn_error_t *
972 svn_cl__check_target_is_local_path(const char *target);
973 
974 /* Return a copy of PATH, converted to the local path style, skipping
975  * PARENT_PATH if it is non-null and is a parent of or equal to PATH.
976  *
977  * This function assumes PARENT_PATH and PATH are both absolute "dirents"
978  * or both relative "dirents". */
979 const char *
980 svn_cl__local_style_skip_ancestor(const char *parent_path,
981                                   const char *path,
982                                   apr_pool_t *pool);
983 
984 /* If the user is setting a mime-type to mark one of the TARGETS as binary,
985  * as determined by property name PROPNAME and value PROPVAL, then check
986  * whether Subversion's own binary-file detection recognizes the target as
987  * a binary file. If Subversion doesn't consider the target to be a binary
988  * file, assume the user is making an error and print a warning to inform
989  * the user that some operations might fail on the file in the future. */
990 svn_error_t *
991 svn_cl__propset_print_binary_mime_type_warning(apr_array_header_t *targets,
992                                                const char *propname,
993                                                const svn_string_t *propval,
994                                                apr_pool_t *scratch_pool);
995 
996 /* A wrapper around the deprecated svn_client_merge_reintegrate. */
997 svn_error_t *
998 svn_cl__deprecated_merge_reintegrate(const char *source_path_or_url,
999                                      const svn_opt_revision_t *src_peg_revision,
1000                                      const char *target_wcpath,
1001                                      svn_boolean_t dry_run,
1002                                      const apr_array_header_t *merge_options,
1003                                      svn_client_ctx_t *ctx,
1004                                      apr_pool_t *pool);
1005 
1006 
1007 /* Forward declaration of the similarity check context. */
1008 typedef struct svn_cl__simcheck_context_t svn_cl__simcheck_context_t;
1009 
1010 /* Token definition for the similarity check. */
1011 typedef struct svn_cl__simcheck_t
1012 {
1013   /* The token we're checking for similarity. */
1014   svn_string_t token;
1015 
1016   /* User data associated with this token. */
1017   const void *data;
1018 
1019   /*
1020    * The following fields are populated by svn_cl__similarity_check.
1021    */
1022 
1023   /* Similarity score [0..SVN_STRING__SIM_RANGE_MAX] */
1024   apr_size_t score;
1025 
1026   /* Number of characters of difference from the key. */
1027   apr_size_t diff;
1028 
1029   /* Similarity check context (private) */
1030   svn_cl__simcheck_context_t *context;
1031 } svn_cl__simcheck_t;
1032 
1033 /* Find the entries in TOKENS that are most similar to KEY.
1034  * TOKEN_COUNT is the number of entries in the (mutable) TOKENS array.
1035  * Use SCRATCH_POOL for temporary allocations.
1036  *
1037  * On return, the TOKENS array will be sorted according to similarity
1038  * to KEY, in descending order. The return value will be zero if the
1039  * first token is an exact match; otherwise, it will be one more than
1040  * the number of tokens that are at least two-thirds similar to KEY.
1041  */
1042 apr_size_t
1043 svn_cl__similarity_check(const char *key,
1044                          svn_cl__simcheck_t **tokens,
1045                          apr_size_t token_count,
1046                          apr_pool_t *scratch_pool);
1047 
1048 /* Return in FUNC_P and BATON_P a callback that prints a summary diff,
1049  * according to the options XML and IGNORE_PROPERTIES.
1050  *
1051  * ANCHOR is a URL or local path to be prefixed to the printed paths.
1052  */
1053 svn_error_t *
1054 svn_cl__get_diff_summary_writer(svn_client_diff_summarize_func_t *func_p,
1055                                 void **baton_p,
1056                                 svn_boolean_t xml,
1057                                 svn_boolean_t ignore_properties,
1058                                 const char *anchor,
1059                                 apr_pool_t *result_pool,
1060                                 apr_pool_t *scratch_pool);
1061 
1062 #ifdef __cplusplus
1063 }
1064 #endif /* __cplusplus */
1065 
1066 #endif /* SVN_CL_H */
1067