svn_subst.h

Go to the documentation of this file.
00001 /**
00002  * @copyright
00003  * ====================================================================
00004  * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
00005  *
00006  * This software is licensed as described in the file COPYING, which
00007  * you should have received as part of this distribution.  The terms
00008  * are also available at http://subversion.tigris.org/license-1.html.
00009  * If newer versions of this license are posted there, you may use a
00010  * newer version instead, at your option.
00011  *
00012  * This software consists of voluntary contributions made by many
00013  * individuals.  For exact contribution history, see the revision
00014  * history and logs, available at http://subversion.tigris.org/.
00015  * ====================================================================
00016  * @endcopyright
00017  *
00018  * @file svn_subst.h
00019  * @brief Data substitution (keywords and EOL style)
00020  */
00021 
00022 
00023 
00024 #ifndef SVN_SUBST_H
00025 #define SVN_SUBST_H
00026 
00027 #include "svn_types.h"
00028 #include "svn_string.h"
00029 #include "svn_io.h"
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif /* __cplusplus */
00034 
00035 /* EOL conversion and keyword expansion. */
00036 
00037 /** Valid states for 'svn:eol-style' property.
00038  *
00039  * Property nonexistence is equivalent to 'none'.
00040  */
00041 typedef enum svn_subst_eol_style
00042 {
00043   /** An unrecognized style */
00044   svn_subst_eol_style_unknown,
00045 
00046   /** EOL translation is "off" or ignored value */
00047   svn_subst_eol_style_none,
00048 
00049   /** Translation is set to client's native eol */
00050   svn_subst_eol_style_native,
00051 
00052   /** Translation is set to one of LF, CR, CRLF */
00053   svn_subst_eol_style_fixed
00054 
00055 } svn_subst_eol_style_t;
00056 
00057 /** Set @a *style to the appropriate @c svn_subst_eol_style_t and @a *eol to
00058  * the appropriate cstring for a given svn:eol-style property value.
00059  *
00060  * Set @a *eol to
00061  *
00062  *    - @c NULL for @c svn_subst_eol_style_none, or
00063  *
00064  *    - a NULL-terminated C string containing the native eol marker
00065  *      for this platform, for @c svn_subst_eol_style_native, or
00066  *
00067  *    - a NULL-terminated C string containing the eol marker indicated
00068  *      by the property value, for @c svn_subst_eol_style_fixed.
00069  *
00070  * If @a *style is NULL, it is ignored.
00071  */
00072 void
00073 svn_subst_eol_style_from_value(svn_subst_eol_style_t *style,
00074                                const char **eol,
00075                                const char *value);
00076 
00077 /** Indicates whether the working copy and normalized versions of a file
00078  * with the given the parameters differ.  If @a force_eol_check is TRUE,
00079  * the routine also accounts for all translations required due to repairing
00080  * fixed eol styles.
00081  *
00082  * @since New in 1.4
00083  *
00084  */
00085 svn_boolean_t
00086 svn_subst_translation_required(svn_subst_eol_style_t style,
00087                                const char *eol,
00088                                apr_hash_t *keywords,
00089                                svn_boolean_t special,
00090                                svn_boolean_t force_eol_check);
00091 
00092 
00093 /** Values used in keyword expansion.
00094  *
00095  * @deprecated Provided for backward compatibility with the 1.2 API.
00096  */
00097 typedef struct svn_subst_keywords_t
00098 {
00099   /**
00100    * @name svn_subst_keywords_t fields
00101    * String expansion of the like-named keyword, or NULL if the keyword
00102    * was not selected in the svn:keywords property.
00103    * @{
00104    */
00105   const svn_string_t *revision;
00106   const svn_string_t *date;
00107   const svn_string_t *author;
00108   const svn_string_t *url;
00109   const svn_string_t *id;
00110   /** @} */
00111 } svn_subst_keywords_t;
00112 
00113 
00114 /**
00115  * Set @a *kw to a new keywords hash filled with the appropriate contents
00116  * given a @a keywords_string (the contents of the svn:keywords
00117  * property for the file in question), the revision @a rev, the @a url,
00118  * the @a date the file was committed on, and the @a author of the last
00119  * commit.  Any of these can be @c NULL to indicate that the information is
00120  * not present, or @c 0 for @a date.
00121  *
00122  * Hash keys are of type <tt>const char *</tt>.
00123  * Hash values are of type <tt>svn_string_t *</tt>.
00124  *
00125  * All memory is allocated out of @a pool.
00126  *
00127  * @since New in 1.3.
00128  */
00129 svn_error_t *
00130 svn_subst_build_keywords2(apr_hash_t **kw,
00131                           const char *keywords_string,
00132                           const char *rev,
00133                           const char *url,
00134                           apr_time_t date,
00135                           const char *author,
00136                           apr_pool_t *pool);
00137 
00138 /** Similar to svn_subst_build_keywords2() except that it populates
00139  * an existing structure @a *kw instead of creating a keywords hash.
00140  *
00141  * @deprecated Provided for backward compatibility with the 1.2 API.
00142  */
00143 SVN_DEPRECATED
00144 svn_error_t *
00145 svn_subst_build_keywords(svn_subst_keywords_t *kw,
00146                          const char *keywords_string,
00147                          const char *rev,
00148                          const char *url,
00149                          apr_time_t date,
00150                          const char *author,
00151                          apr_pool_t *pool);
00152 
00153 
00154 /** Return @c TRUE if @a a and @a b do not hold the same keywords.
00155  *
00156  * @a a and @a b are hashes of the form produced by
00157  * svn_subst_build_keywords2().
00158  *
00159  * @since New in 1.3.
00160  *
00161  * If @a compare_values is @c TRUE, "same" means that the @a a and @a b
00162  * contain exactly the same set of keywords, and the values of corresponding
00163  * keywords match as well.  Else if @a compare_values is @c FALSE, then
00164  * "same" merely means that @a a and @a b hold the same set of keywords,
00165  * although those keywords' values might differ.
00166  *
00167  * @a a and/or @a b may be @c NULL; for purposes of comparison, @c NULL is
00168  * equivalent to holding no keywords.
00169  */
00170 svn_boolean_t
00171 svn_subst_keywords_differ2(apr_hash_t *a,
00172                            apr_hash_t *b,
00173                            svn_boolean_t compare_values,
00174                            apr_pool_t *pool);
00175 
00176 /** Similar to svn_subst_keywords_differ2() except that it compares
00177  * two @c svn_subst_keywords_t structs instead of keyword hashes.
00178  *
00179  * @deprecated Provided for backward compatibility with the 1.2 API.
00180  */
00181 SVN_DEPRECATED
00182 svn_boolean_t
00183 svn_subst_keywords_differ(const svn_subst_keywords_t *a,
00184                           const svn_subst_keywords_t *b,
00185                           svn_boolean_t compare_values);
00186 
00187 
00188 /**
00189  * Copy and translate the data in stream @a src into stream @a dst.  It is
00190  * assumed that @a src is a readable stream and @a dst is a writable stream.
00191  *
00192  * @since New in 1.3.
00193  *
00194  * If @a eol_str is non-@c NULL, replace whatever bytestring @a src uses to
00195  * denote line endings with @a eol_str in the output.  If @a src has an
00196  * inconsistent line ending style, then: if @a repair is @c FALSE, return
00197  * @c SVN_ERR_IO_INCONSISTENT_EOL, else if @a repair is @c TRUE, convert any
00198  * line ending in @a src to @a eol_str in @a dst.  Recognized line endings are:
00199  * "\n", "\r", and "\r\n".
00200  *
00201  * Expand and contract keywords using the contents of @a keywords as the
00202  * new values.  If @a expand is @c TRUE, expand contracted keywords and
00203  * re-expand expanded keywords.  If @a expand is @c FALSE, contract expanded
00204  * keywords and ignore contracted ones.  Keywords not found in the hash are
00205  * ignored (not contracted or expanded).  If the @a keywords hash
00206  * itself is @c NULL, keyword substitution will be altogether ignored.
00207  *
00208  * Detect only keywords that are no longer than @c SVN_KEYWORD_MAX_LEN
00209  * bytes, including the delimiters and the keyword itself.
00210  *
00211  * Note that a translation request is *required*:  one of @a eol_str or
00212  * @a keywords must be non-@c NULL.
00213  *
00214  * Recommendation: if @a expand is FALSE, then you don't care about the
00215  * keyword values, so use empty strings as non-NULL signifiers when you
00216  * build the keywords hash.
00217  *
00218  * Notes:
00219  *
00220  * See svn_wc__get_keywords() and svn_wc__get_eol_style() for a
00221  * convenient way to get @a eol_str and @a keywords if in libsvn_wc.
00222  */
00223 svn_error_t *
00224 svn_subst_translate_stream3(svn_stream_t *src,
00225                             svn_stream_t *dst,
00226                             const char *eol_str,
00227                             svn_boolean_t repair,
00228                             apr_hash_t *keywords,
00229                             svn_boolean_t expand,
00230                             apr_pool_t *pool);
00231 
00232 /** Return a stream which performs eol translation and keyword
00233  * expansion when read from or written to.  The stream @a stream
00234  * is used to read and write all data.  Make sure you call
00235  * svn_stream_close() on @a stream to make sure all data are flushed
00236  * and cleaned up.
00237  *
00238  * Read operations from and write operations to the stream
00239  * perform the same operation: if @a expand is @c FALSE, both
00240  * contract keywords.  One stream supports both read and write
00241  * operations.  Reads and writes may be mixed.
00242  *
00243  * The stream returned is allocated in @a pool.
00244  *
00245  * @since New in 1.4.
00246  */
00247 svn_stream_t *
00248 svn_subst_stream_translated(svn_stream_t *stream,
00249                             const char *eol_str,
00250                             svn_boolean_t repair,
00251                             apr_hash_t *keywords,
00252                             svn_boolean_t expand,
00253                             apr_pool_t *pool);
00254 
00255 /** Return a stream which performs eol translation and keyword
00256  * expansion when read from or written to.  The stream @a stream
00257  * is used to read and write all data.  Make sure you call
00258  * svn_stream_close() on @a stream to make sure all data are flushed
00259  * and cleaned up.
00260  *
00261  * Read and write operations perform the same transformation:
00262  * all data is translated to normal form.
00263  *
00264  * @see svn_subst_translate_to_normal_form()
00265  *
00266  * @since New in 1.5.
00267  */
00268 svn_error_t *
00269 svn_subst_stream_translated_to_normal_form(svn_stream_t **stream,
00270                                            svn_stream_t *source,
00271                                            svn_subst_eol_style_t eol_style,
00272                                            const char *eol_str,
00273                                            svn_boolean_t always_repair_eols,
00274                                            apr_hash_t *keywords,
00275                                            apr_pool_t *pool);
00276 
00277 
00278 /** Returns a stream which translates the special file at @a path to
00279  * the internal representation for special files when read from.  When
00280  * written to, it does the reverse: creating a special file when the
00281  * stream is closed.
00282  *
00283  * @since New in 1.5.
00284  */
00285 svn_error_t *
00286 svn_subst_stream_from_specialfile(svn_stream_t **stream,
00287                                   const char *path,
00288                                   apr_pool_t *pool);
00289 
00290 
00291 /** Similar to svn_subst_translate_stream3() except relies upon a
00292  * @c svn_subst_keywords_t struct instead of a hash for the keywords.
00293  *
00294  * @deprecated Provided for backward compatibility with the 1.2 API.
00295  */
00296 SVN_DEPRECATED
00297 svn_error_t *
00298 svn_subst_translate_stream2(svn_stream_t *src,
00299                             svn_stream_t *dst,
00300                             const char *eol_str,
00301                             svn_boolean_t repair,
00302                             const svn_subst_keywords_t *keywords,
00303                             svn_boolean_t expand,
00304                             apr_pool_t *pool);
00305 
00306 
00307 /**
00308  * Same as svn_subst_translate_stream2(), but does not take a @a pool
00309  * argument, instead creates a temporary subpool of the global pool, and
00310  * destroys it before returning.
00311  *
00312  * @deprecated Provided for backward compatibility with the 1.1 API.
00313  */
00314 SVN_DEPRECATED
00315 svn_error_t *
00316 svn_subst_translate_stream(svn_stream_t *src,
00317                            svn_stream_t *dst,
00318                            const char *eol_str,
00319                            svn_boolean_t repair,
00320                            const svn_subst_keywords_t *keywords,
00321                            svn_boolean_t expand);
00322 
00323 
00324 /**
00325  * Translates the file at path @a src into a file at path @a dst.  The
00326  * parameters @a *eol_str, @a repair, @a *keywords and @a expand are
00327  * defined the same as in svn_subst_translate_stream3().
00328  *
00329  * In addition, it will create a special file from normal form or
00330  * translate one to normal form if @a special is @c TRUE.
00331  *
00332  * Copy the contents of file-path @a src to file-path @a dst atomically,
00333  * either creating @a dst (or overwriting @a dst if it exists), possibly
00334  * performing line ending and keyword translations.
00335  *
00336  * If anything goes wrong during the copy, attempt to delete @a dst (if
00337  * it exists).
00338  *
00339  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00340  * copy.
00341  *
00342  * @since New in 1.3.
00343  */
00344 svn_error_t *
00345 svn_subst_copy_and_translate3(const char *src,
00346                               const char *dst,
00347                               const char *eol_str,
00348                               svn_boolean_t repair,
00349                               apr_hash_t *keywords,
00350                               svn_boolean_t expand,
00351                               svn_boolean_t special,
00352                               apr_pool_t *pool);
00353 
00354 /**
00355  * Similar to svn_subst_copy_and_translate3() except that @a keywords is a
00356  * @c svn_subst_keywords_t struct instead of a keywords hash.
00357  *
00358  * @deprecated Provided for backward compatibility with the 1.2 API.
00359  * @since New in 1.1.
00360  */
00361 SVN_DEPRECATED
00362 svn_error_t *
00363 svn_subst_copy_and_translate2(const char *src,
00364                               const char *dst,
00365                               const char *eol_str,
00366                               svn_boolean_t repair,
00367                               const svn_subst_keywords_t *keywords,
00368                               svn_boolean_t expand,
00369                               svn_boolean_t special,
00370                               apr_pool_t *pool);
00371 
00372 /**
00373  * Similar to svn_subst_copy_and_translate2() except that @a special is
00374  * always set to @c FALSE.
00375  *
00376  * @deprecated Provided for backward compatibility with the 1.0 API.
00377  */
00378 SVN_DEPRECATED
00379 svn_error_t *
00380 svn_subst_copy_and_translate(const char *src,
00381                              const char *dst,
00382                              const char *eol_str,
00383                              svn_boolean_t repair,
00384                              const svn_subst_keywords_t *keywords,
00385                              svn_boolean_t expand,
00386                              apr_pool_t *pool);
00387 
00388 
00389 /**
00390  * Create a new, translated file.
00391  *
00392  * This is similar to svn_subst_copy_and_translate3() except that it
00393  * takes a source stream.
00394  *
00395  * Translates the stream @a src into a file at path @a dst.  The
00396  * parameters @a *eol_str, @a repair, @a *keywords and @a expand are
00397  * defined the same as in svn_subst_translate_stream3().
00398  *
00399  * If @a special is TRUE, then the stream should define a special fine,
00400  * and be in "normal form". The file @a dst will then be a special file.
00401  *
00402  * The contents will be copied/translated into a temporary file, and then
00403  * moved to @a dst atomically.
00404  *
00405  * If anything goes wrong during the copy, attempt to delete @a dst (if
00406  * it exists).
00407  *
00408  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00409  * copy.
00410  *
00411  * @since New in 1.6.
00412  */
00413 svn_error_t *
00414 svn_subst_create_translated(svn_stream_t *src,
00415                             const char *dst,
00416                             const char *eol_str,
00417                             svn_boolean_t repair,
00418                             apr_hash_t *keywords,
00419                             svn_boolean_t expand,
00420                             svn_boolean_t special,
00421                             apr_pool_t *scratch_pool);
00422 
00423 
00424 /**
00425  * Convenience routine: a variant of svn_subst_translate_stream3() which
00426  * operates on cstrings.
00427  *
00428  * @since New in 1.3.
00429  *
00430  * Return a new string in @a *dst, allocated in @a pool, by copying the
00431  * contents of string @a src, possibly performing line ending and keyword
00432  * translations.
00433  *
00434  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00435  * copy.
00436  */
00437 svn_error_t *
00438 svn_subst_translate_cstring2(const char *src,
00439                              const char **dst,
00440                              const char *eol_str,
00441                              svn_boolean_t repair,
00442                              apr_hash_t *keywords,
00443                              svn_boolean_t expand,
00444                              apr_pool_t *pool);
00445 
00446 /**
00447  * Similar to svn_subst_translate_cstring2() except that @a keywords is a
00448  * @c svn_subst_keywords_t struct instead of a keywords hash.
00449  *
00450  * @deprecated Provided for backward compatibility with the 1.2 API.
00451  */
00452 SVN_DEPRECATED
00453 svn_error_t *
00454 svn_subst_translate_cstring(const char *src,
00455                             const char **dst,
00456                             const char *eol_str,
00457                             svn_boolean_t repair,
00458                             const svn_subst_keywords_t *keywords,
00459                             svn_boolean_t expand,
00460                             apr_pool_t *pool);
00461 
00462 /**
00463  * Translates a file @a src in working copy form to a file @a dst in
00464  * normal form.
00465  *
00466  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00467  * @a special, should be the ones used to translate the file to its
00468  * working copy form.  Usually, these are the values specified by the
00469  * user in the files' properties.
00470  *
00471  * Inconsistent line endings in the file will be automatically repaired
00472  * (made consistent) for some eol styles.  For all others, an error is
00473  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00474  * made consistent even for those styles which don't have it by default.
00475  *
00476  * @note To translate a file FROM normal form, use
00477  *       svn_subst_copy_and_translate3().
00478  *
00479  * @since New in 1.4
00480  *
00481  */
00482 svn_error_t *
00483 svn_subst_translate_to_normal_form(const char *src,
00484                                    const char *dst,
00485                                    svn_subst_eol_style_t eol_style,
00486                                    const char *eol_str,
00487                                    svn_boolean_t always_repair_eols,
00488                                    apr_hash_t *keywords,
00489                                    svn_boolean_t special,
00490                                    apr_pool_t *pool);
00491 
00492 /**
00493  * Set @a *stream_p to a stream that detranslates the file @a src from
00494  * working copy form to normal form, allocated in @a pool.
00495  *
00496  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00497  * @a special, should be the ones used to translate the file to its
00498  * working copy form.  Usually, these are the values specified by the
00499  * user in the files' properties.
00500  *
00501  * Inconsistent line endings in the file will be automatically repaired
00502  * (made consistent) for some eol styles.  For all others, an error is
00503  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00504  * made consistent even for those styles which don't have it by default.
00505  *
00506  * @since New in 1.4.
00507  *
00508  */
00509 svn_error_t *
00510 svn_subst_stream_detranslated(svn_stream_t **stream_p,
00511                               const char *src,
00512                               svn_subst_eol_style_t eol_style,
00513                               const char *eol_str,
00514                               svn_boolean_t always_repair_eols,
00515                               apr_hash_t *keywords,
00516                               svn_boolean_t special,
00517                               apr_pool_t *pool);
00518 
00519 
00520 /* EOL conversion and character encodings */
00521 
00522 /** Translate the data in @a value (assumed to be in encoded in charset
00523  * @a encoding) to UTF8 and LF line-endings.  If @a encoding is @c NULL,
00524  * then assume that @a value is in the system-default language encoding.
00525  * Return the translated data in @a *new_value, allocated in @a pool.
00526  */
00527 svn_error_t *svn_subst_translate_string(svn_string_t **new_value,
00528                                         const svn_string_t *value,
00529                                         const char *encoding,
00530                                         apr_pool_t *pool);
00531 
00532 /** Translate the data in @a value from UTF8 and LF line-endings into
00533  * native locale and native line-endings, or to the output locale if
00534  * @a for_output is TRUE.  Return the translated data in @a
00535  * *new_value, allocated in @a pool.
00536  */
00537 svn_error_t *svn_subst_detranslate_string(svn_string_t **new_value,
00538                                           const svn_string_t *value,
00539                                           svn_boolean_t for_output,
00540                                           apr_pool_t *pool);
00541 
00542 
00543 /** Get a stream that contains the (detranslated) "normal form" of the
00544  * file located at @a path. If the file is not special, then a normal,
00545  * readonly stream is opened up on it.
00546  *
00547  * The stream is allocated in @a result_pool, and all temporary allocations
00548  * are performed in @a scratch_pool.
00549  *
00550  * @since New in 1.6
00551  */
00552 svn_error_t *
00553 svn_subst_get_detranslated_stream(svn_stream_t **stream,
00554                                   const char *path,
00555                                   apr_pool_t *result_pool,
00556                                   apr_pool_t *scratch_pool);
00557 
00558 
00559 #ifdef __cplusplus
00560 }
00561 #endif /* __cplusplus */
00562 
00563 #endif /* SVN_SUBST_H */

Generated on Tue Oct 7 04:09:55 2008 for Subversion by  doxygen 1.3.9.1