2
* translate.c : wc-specific eol/keyword substitution
4
* ====================================================================
5
* Copyright (c) 2000-2004 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
* ====================================================================
24
#include <apr_general.h> /* for strcasecmp() */
25
#include <apr_pools.h>
26
#include <apr_file_io.h>
27
#include <apr_strings.h>
28
#include "svn_types.h"
29
#include "svn_string.h"
31
#include "svn_error.h"
32
#include "svn_subst.h"
34
#include "svn_props.h"
38
#include "adm_files.h"
39
#include "translate.h"
41
#include "svn_private_config.h"
44
svn_wc_translated_file (const char **xlated_p,
46
svn_wc_adm_access_t *adm_access,
47
svn_boolean_t force_repair,
50
svn_subst_eol_style_t style;
52
svn_subst_keywords_t *keywords;
53
svn_boolean_t special;
55
SVN_ERR (svn_wc__get_eol_style (&style, &eol, vfile, adm_access, pool));
56
SVN_ERR (svn_wc__get_keywords (&keywords, vfile, adm_access, NULL, pool));
57
SVN_ERR (svn_wc__get_special (&special, vfile, adm_access, pool));
59
if ((style == svn_subst_eol_style_none) && (! keywords) && (! special))
61
/* Translation would be a no-op, so return the original file. */
64
else /* some translation is necessary */
66
const char *tmp_dir, *tmp_vfile;
69
/* First, reserve a tmp file name. */
71
svn_path_split (vfile, &tmp_dir, &tmp_vfile, pool);
73
tmp_vfile = svn_wc__adm_path (tmp_dir, 1, pool,
76
SVN_ERR (svn_io_open_unique_file (&ignored,
83
/* We were just reserving the name and don't actually need the
84
filehandle, so close immediately. */
85
SVN_ERR (svn_io_file_close (ignored, pool));
87
if (style == svn_subst_eol_style_fixed)
89
SVN_ERR (svn_subst_copy_and_translate2 (vfile,
98
else if (style == svn_subst_eol_style_native)
100
SVN_ERR (svn_subst_copy_and_translate2 (vfile,
102
SVN_WC__DEFAULT_EOL_MARKER,
109
else if (style == svn_subst_eol_style_none)
111
SVN_ERR (svn_subst_copy_and_translate2 (vfile,
122
return svn_error_createf
123
(SVN_ERR_IO_UNKNOWN_EOL, NULL,
124
_("'%s' has unknown value for svn:eol-style property"),
125
svn_path_local_style (vfile, pool));
128
*xlated_p = tmp_vfile;
136
svn_wc__get_eol_style (svn_subst_eol_style_t *style,
139
svn_wc_adm_access_t *adm_access,
142
const svn_string_t *propval;
144
/* Get the property value. */
145
SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EOL_STYLE, path, adm_access,
149
svn_subst_eol_style_from_value (style, eol, propval ? propval->data : NULL);
156
svn_wc__eol_value_from_string (const char **value, const char *eol)
160
else if (! strcmp ("\n", eol))
162
else if (! strcmp ("\r", eol))
164
else if (! strcmp ("\r\n", eol))
172
svn_wc__get_keywords (svn_subst_keywords_t **keywords,
174
svn_wc_adm_access_t *adm_access,
175
const char *force_list,
179
svn_subst_keywords_t tmp_keywords = { 0 };
180
const svn_wc_entry_t *entry = NULL;
182
/* Start by assuming no keywords. */
185
/* Choose a property list to parse: either the one that came into
186
this function, or the one attached to PATH. */
187
if (force_list == NULL)
189
const svn_string_t *propval;
191
SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_KEYWORDS, path, adm_access,
194
list = propval ? propval->data : NULL;
199
/* The easy answer. */
203
SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
205
SVN_ERR (svn_subst_build_keywords (&tmp_keywords,
207
apr_psprintf (pool, "%ld",
214
*keywords = apr_pmemdup (pool, &tmp_keywords, sizeof (tmp_keywords));
221
svn_wc__get_special (svn_boolean_t *special,
223
svn_wc_adm_access_t *adm_access,
226
const svn_string_t *propval;
228
/* Get the property value. */
229
SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_SPECIAL, path, adm_access,
232
*special = propval ? TRUE : FALSE;
239
svn_wc__maybe_set_executable (svn_boolean_t *did_set,
241
svn_wc_adm_access_t *adm_access,
244
const svn_string_t *propval;
245
SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EXECUTABLE, path, adm_access,
250
SVN_ERR (svn_io_set_file_executable (path, TRUE, FALSE, pool));
262
svn_wc__maybe_set_read_only (svn_boolean_t *did_set,
264
svn_wc_adm_access_t *adm_access,
267
const svn_string_t *needs_lock;
268
const svn_wc_entry_t* entry;
273
SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
274
if (entry && entry->lock_token)
277
SVN_ERR (svn_wc_prop_get (&needs_lock, SVN_PROP_NEEDS_LOCK, path,
280
if (needs_lock != NULL)
282
SVN_ERR (svn_io_set_file_read_write_carefully (path, FALSE,