38
38
#include "adm_files.h"
39
39
#include "translate.h"
41
42
#include "svn_private_config.h"
44
svn_wc_translated_file (const char **xlated_p,
45
svn_wc_translated_file2(const char **xlated_path,
47
const char *versioned_file,
46
48
svn_wc_adm_access_t *adm_access,
47
svn_boolean_t force_repair,
50
52
svn_subst_eol_style_t style;
52
54
apr_hash_t *keywords;
53
55
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))
57
SVN_ERR(svn_wc__get_eol_style(&style, &eol, versioned_file,
59
SVN_ERR(svn_wc__get_keywords(&keywords, versioned_file,
60
adm_access, NULL, pool));
61
SVN_ERR(svn_wc__get_special(&special, versioned_file, adm_access, pool));
64
if (! svn_subst_translation_required(style, eol, keywords, special, TRUE)
65
&& (! (flags & SVN_WC_TRANSLATE_FORCE_COPY)))
61
67
/* Translation would be a no-op, so return the original file. */
64
else /* some translation is necessary */
71
else /* some translation (or copying) is necessary */
66
73
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_translate3 (vfile,
98
else if (style == svn_subst_eol_style_native)
100
SVN_ERR (svn_subst_copy_and_translate3 (vfile,
102
SVN_WC__DEFAULT_EOL_MARKER,
109
else if (style == svn_subst_eol_style_none)
111
SVN_ERR (svn_subst_copy_and_translate3 (vfile,
74
svn_boolean_t repair_forced = flags & SVN_WC_TRANSLATE_FORCE_EOL_REPAIR;
76
svn_path_split(versioned_file, &tmp_dir, &tmp_vfile, pool);
77
if (flags & SVN_WC_TRANSLATE_USE_GLOBAL_TMP)
79
SVN_ERR(svn_io_temp_dir(&tmp_dir, pool));
80
tmp_vfile = svn_path_join(tmp_dir, "svndiff", pool);
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;
83
tmp_vfile = svn_wc__adm_path(tmp_dir, 1, pool, tmp_vfile, NULL);
85
SVN_ERR(svn_io_open_unique_file2
89
(flags & SVN_WC_TRANSLATE_NO_OUTPUT_CLEANUP)
90
? svn_io_file_del_none : svn_io_file_del_on_pool_cleanup,
93
if (flags & SVN_WC_TRANSLATE_TO_NF)
95
SVN_ERR(svn_subst_translate_to_normal_form
96
(src, tmp_vfile, style, eol,
98
keywords, special, pool));
99
else /* from normal form */
100
SVN_ERR(svn_subst_copy_and_translate3
107
*xlated_path = tmp_vfile;
131
110
return SVN_NO_ERROR;
136
svn_wc__get_eol_style (svn_subst_eol_style_t *style,
115
svn_wc_translated_file(const char **xlated_p,
139
117
svn_wc_adm_access_t *adm_access,
118
svn_boolean_t force_repair,
140
119
apr_pool_t *pool)
121
return svn_wc_translated_file2(xlated_p, vfile, vfile, adm_access,
122
SVN_WC_TRANSLATE_TO_NF
124
SVN_WC_TRANSLATE_FORCE_EOL_REPAIR : 0),
130
svn_wc__get_eol_style(svn_subst_eol_style_t *style,
133
svn_wc_adm_access_t *adm_access,
142
136
const svn_string_t *propval;
144
138
/* Get the property value. */
145
SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EOL_STYLE, path, adm_access,
139
SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_EOL_STYLE, path, adm_access,
148
142
/* Convert it. */
149
svn_subst_eol_style_from_value (style, eol, propval ? propval->data : NULL);
143
svn_subst_eol_style_from_value(style, eol, propval ? propval->data : NULL);
151
145
return SVN_NO_ERROR;
156
svn_wc__eol_value_from_string (const char **value, const char *eol)
150
svn_wc__eol_value_from_string(const char **value, const char *eol)
160
else if (! strcmp ("\n", eol))
154
else if (! strcmp("\n", eol))
162
else if (! strcmp ("\r", eol))
156
else if (! strcmp("\r", eol))
164
else if (! strcmp ("\r\n", eol))
158
else if (! strcmp("\r\n", eol))
199
193
return SVN_NO_ERROR;
202
SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
204
SVN_ERR (svn_subst_build_keywords2 (keywords,
206
apr_psprintf (pool, "%ld",
213
if (apr_hash_count (*keywords) == 0)
196
SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool));
198
return svn_error_createf(SVN_ERR_UNVERSIONED_RESOURCE, NULL,
199
_("'%s' is not under version control"),
200
svn_path_local_style(path, pool));
202
SVN_ERR(svn_subst_build_keywords2(keywords,
204
apr_psprintf(pool, "%ld",
211
if (apr_hash_count(*keywords) == 0)
214
212
*keywords = NULL;
216
214
return SVN_NO_ERROR;
221
svn_wc__get_special (svn_boolean_t *special,
223
svn_wc_adm_access_t *adm_access,
219
svn_wc__get_special(svn_boolean_t *special,
221
svn_wc_adm_access_t *adm_access,
226
224
const svn_string_t *propval;
228
226
/* 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,
227
SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_SPECIAL, path,
229
*special = propval != NULL;
236
svn_wc__maybe_set_executable(svn_boolean_t *did_set,
263
237
const char *path,
264
238
svn_wc_adm_access_t *adm_access,
265
239
apr_pool_t *pool)
241
const svn_string_t *propval;
242
SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_EXECUTABLE, path, adm_access,
247
SVN_ERR(svn_io_set_file_executable(path, TRUE, FALSE, pool));
259
svn_wc__maybe_set_read_only(svn_boolean_t *did_set,
261
svn_wc_adm_access_t *adm_access,
267
264
const svn_string_t *needs_lock;
268
265
const svn_wc_entry_t* entry;
271
268
*did_set = FALSE;
273
SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
270
SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool));
274
271
if (entry && entry->lock_token)
275
272
return SVN_NO_ERROR;
277
SVN_ERR (svn_wc_prop_get (&needs_lock, SVN_PROP_NEEDS_LOCK, path,
274
SVN_ERR(svn_wc_prop_get(&needs_lock, SVN_PROP_NEEDS_LOCK, path,
280
277
if (needs_lock != NULL)
282
SVN_ERR (svn_io_set_file_read_write_carefully (path, FALSE,
279
SVN_ERR(svn_io_set_file_read_only(path, FALSE, pool));