~svn/ubuntu/oneiric/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_wc/translate.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-13 17:57:16 UTC
  • mfrom: (1.1.6 upstream) (0.1.3 etch)
  • Revision ID: james.westby@ubuntu.com-20061213175716-2ysv6z4w5dpa2r2f
Tags: 1.4.2dfsg1-2ubuntu1
* Merge with Debian unstable; remaining changes:
  - Create pot file on build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "wc.h"
38
38
#include "adm_files.h"
39
39
#include "translate.h"
 
40
#include "props.h"
40
41
 
41
42
#include "svn_private_config.h"
42
43
 
43
44
svn_error_t *
44
 
svn_wc_translated_file (const char **xlated_p,
45
 
                        const char *vfile,
 
45
svn_wc_translated_file2(const char **xlated_path,
 
46
                        const char *src,
 
47
                        const char *versioned_file,
46
48
                        svn_wc_adm_access_t *adm_access,
47
 
                        svn_boolean_t force_repair,
 
49
                        apr_uint32_t flags,
48
50
                        apr_pool_t *pool)
49
51
{
50
52
  svn_subst_eol_style_t style;
51
53
  const char *eol;
52
54
  apr_hash_t *keywords;
53
55
  svn_boolean_t special;
54
 
  
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));
58
 
 
59
 
  if ((style == svn_subst_eol_style_none) && (! keywords) && (! special))
 
56
 
 
57
  SVN_ERR(svn_wc__get_eol_style(&style, &eol, versioned_file,
 
58
                                adm_access, pool));
 
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));
 
62
 
 
63
 
 
64
  if (! svn_subst_translation_required(style, eol, keywords, special, TRUE)
 
65
      && (! (flags & SVN_WC_TRANSLATE_FORCE_COPY)))
60
66
    {
61
67
      /* Translation would be a no-op, so return the original file. */
62
 
      *xlated_p = vfile;
 
68
      *xlated_path = src;
 
69
 
63
70
    }
64
 
  else  /* some translation is necessary */
 
71
  else  /* some translation (or copying) is necessary */
65
72
    {
66
73
      const char *tmp_dir, *tmp_vfile;
67
 
      apr_file_t *ignored;
68
 
 
69
 
      /* First, reserve a tmp file name. */
70
 
 
71
 
      svn_path_split (vfile, &tmp_dir, &tmp_vfile, pool);
72
 
      
73
 
      tmp_vfile = svn_wc__adm_path (tmp_dir, 1, pool,
74
 
                                    tmp_vfile, NULL);
75
 
      
76
 
      SVN_ERR (svn_io_open_unique_file (&ignored,
77
 
                                        &tmp_vfile,
78
 
                                        tmp_vfile,
79
 
                                        SVN_WC__TMP_EXT,
80
 
                                        FALSE,
81
 
                                        pool));
82
 
      
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));
86
 
      
87
 
      if (style == svn_subst_eol_style_fixed)
88
 
        {
89
 
          SVN_ERR (svn_subst_copy_and_translate3 (vfile,
90
 
                                                  tmp_vfile,
91
 
                                                  eol,
92
 
                                                  TRUE,
93
 
                                                  keywords,
94
 
                                                  FALSE,
95
 
                                                  special,
96
 
                                                  pool));
97
 
        }
98
 
      else if (style == svn_subst_eol_style_native)
99
 
        {
100
 
          SVN_ERR (svn_subst_copy_and_translate3 (vfile,
101
 
                                                  tmp_vfile,
102
 
                                                  SVN_WC__DEFAULT_EOL_MARKER,
103
 
                                                  force_repair,
104
 
                                                  keywords,
105
 
                                                  FALSE,
106
 
                                                  special,
107
 
                                                  pool));
108
 
        }
109
 
      else if (style == svn_subst_eol_style_none)
110
 
        {
111
 
          SVN_ERR (svn_subst_copy_and_translate3 (vfile,
112
 
                                                  tmp_vfile,
113
 
                                                  NULL,
114
 
                                                  force_repair,
115
 
                                                  keywords,
116
 
                                                  FALSE,
117
 
                                                  special,
118
 
                                                  pool));
 
74
      svn_boolean_t repair_forced = flags & SVN_WC_TRANSLATE_FORCE_EOL_REPAIR;
 
75
 
 
76
      svn_path_split(versioned_file, &tmp_dir, &tmp_vfile, pool);
 
77
      if (flags & SVN_WC_TRANSLATE_USE_GLOBAL_TMP)
 
78
        {
 
79
          SVN_ERR(svn_io_temp_dir(&tmp_dir, pool));
 
80
          tmp_vfile = svn_path_join(tmp_dir, "svndiff", pool);
119
81
        }
120
82
      else
121
 
        {
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));
126
 
        }
127
 
 
128
 
      *xlated_p = tmp_vfile;
 
83
        tmp_vfile = svn_wc__adm_path(tmp_dir, 1, pool, tmp_vfile, NULL);
 
84
 
 
85
      SVN_ERR(svn_io_open_unique_file2
 
86
              (NULL, &tmp_vfile,
 
87
               tmp_vfile,
 
88
               SVN_WC__TMP_EXT,
 
89
               (flags & SVN_WC_TRANSLATE_NO_OUTPUT_CLEANUP)
 
90
               ? svn_io_file_del_none : svn_io_file_del_on_pool_cleanup,
 
91
               pool));
 
92
 
 
93
      if (flags & SVN_WC_TRANSLATE_TO_NF)
 
94
        /* to normal form */
 
95
        SVN_ERR(svn_subst_translate_to_normal_form
 
96
                (src, tmp_vfile, style, eol,
 
97
                 repair_forced,
 
98
                 keywords, special, pool));
 
99
      else /* from normal form */
 
100
        SVN_ERR(svn_subst_copy_and_translate3
 
101
                (src, tmp_vfile,
 
102
                 eol, TRUE,
 
103
                 keywords, TRUE,
 
104
                 special,
 
105
                 pool));
 
106
 
 
107
      *xlated_path = tmp_vfile;
129
108
    }
130
109
 
131
110
  return SVN_NO_ERROR;
133
112
 
134
113
 
135
114
svn_error_t *
136
 
svn_wc__get_eol_style (svn_subst_eol_style_t *style,
137
 
                       const char **eol,
138
 
                       const char *path,
 
115
svn_wc_translated_file(const char **xlated_p,
 
116
                       const char *vfile,
139
117
                       svn_wc_adm_access_t *adm_access,
 
118
                       svn_boolean_t force_repair,
140
119
                       apr_pool_t *pool)
141
120
{
 
121
  return svn_wc_translated_file2(xlated_p, vfile, vfile, adm_access,
 
122
                                 SVN_WC_TRANSLATE_TO_NF
 
123
                                 | (force_repair ?
 
124
                                    SVN_WC_TRANSLATE_FORCE_EOL_REPAIR : 0),
 
125
                                 pool);
 
126
}
 
127
 
 
128
 
 
129
svn_error_t *
 
130
svn_wc__get_eol_style(svn_subst_eol_style_t *style,
 
131
                      const char **eol,
 
132
                      const char *path,
 
133
                      svn_wc_adm_access_t *adm_access,
 
134
                      apr_pool_t *pool)
 
135
{
142
136
  const svn_string_t *propval;
143
137
 
144
138
  /* Get the property value. */
145
 
  SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EOL_STYLE, path, adm_access,
146
 
                            pool));
 
139
  SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_EOL_STYLE, path, adm_access,
 
140
                          pool));
147
141
 
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);
150
144
 
151
145
  return SVN_NO_ERROR;
152
146
}
153
147
 
154
148
 
155
149
void
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)
157
151
{
158
152
  if (eol == NULL)
159
153
    *value = NULL;
160
 
  else if (! strcmp ("\n", eol))
 
154
  else if (! strcmp("\n", eol))
161
155
    *value = "LF";
162
 
  else if (! strcmp ("\r", eol))
 
156
  else if (! strcmp("\r", eol))
163
157
    *value = "CR";
164
 
  else if (! strcmp ("\r\n", eol))
 
158
  else if (! strcmp("\r\n", eol))
165
159
    *value = "CRLF";
166
160
  else
167
161
    *value = NULL;
169
163
 
170
164
 
171
165
svn_error_t *
172
 
svn_wc__get_keywords (apr_hash_t **keywords,
173
 
                      const char *path,
174
 
                      svn_wc_adm_access_t *adm_access,
175
 
                      const char *force_list,
176
 
                      apr_pool_t *pool)
 
166
svn_wc__get_keywords(apr_hash_t **keywords,
 
167
                     const char *path,
 
168
                     svn_wc_adm_access_t *adm_access,
 
169
                     const char *force_list,
 
170
                     apr_pool_t *pool)
177
171
{
178
172
  const char *list;
179
173
  const svn_wc_entry_t *entry = NULL;
184
178
    {
185
179
      const svn_string_t *propval;
186
180
 
187
 
      SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_KEYWORDS, path, adm_access,
188
 
                                pool));
 
181
      SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_KEYWORDS, path, adm_access,
 
182
                              pool));
189
183
      
190
184
      list = propval ? propval->data : NULL;
191
185
    }
199
193
      return SVN_NO_ERROR;
200
194
    }
201
195
 
202
 
  SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
203
 
 
204
 
  SVN_ERR (svn_subst_build_keywords2 (keywords,
205
 
                                      list,
206
 
                                      apr_psprintf (pool, "%ld",
207
 
                                                    entry->cmt_rev),
208
 
                                      entry->url,
209
 
                                      entry->cmt_date,
210
 
                                      entry->cmt_author,
211
 
                                      pool));
212
 
 
213
 
  if (apr_hash_count (*keywords) == 0)
 
196
  SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool));
 
197
  if (! entry)
 
198
    return svn_error_createf(SVN_ERR_UNVERSIONED_RESOURCE, NULL,
 
199
                             _("'%s' is not under version control"),
 
200
                             svn_path_local_style(path, pool));
 
201
 
 
202
  SVN_ERR(svn_subst_build_keywords2(keywords,
 
203
                                    list,
 
204
                                    apr_psprintf(pool, "%ld",
 
205
                                                 entry->cmt_rev),
 
206
                                    entry->url,
 
207
                                    entry->cmt_date,
 
208
                                    entry->cmt_author,
 
209
                                    pool));
 
210
 
 
211
  if (apr_hash_count(*keywords) == 0)
214
212
    *keywords = NULL;
215
213
 
216
214
  return SVN_NO_ERROR;
218
216
 
219
217
 
220
218
svn_error_t *
221
 
svn_wc__get_special (svn_boolean_t *special,
222
 
                     const char *path,
223
 
                     svn_wc_adm_access_t *adm_access,
224
 
                     apr_pool_t *pool)
 
219
svn_wc__get_special(svn_boolean_t *special,
 
220
                    const char *path,
 
221
                    svn_wc_adm_access_t *adm_access,
 
222
                    apr_pool_t *pool)
225
223
{
226
224
  const svn_string_t *propval;
227
 
 
 
225
  
228
226
  /* Get the property value. */
229
 
  SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_SPECIAL, path, adm_access,
230
 
                            pool));
231
 
 
232
 
  *special = propval ? TRUE : FALSE;
233
 
 
234
 
  return SVN_NO_ERROR;
235
 
}
236
 
 
237
 
 
238
 
svn_error_t *
239
 
svn_wc__maybe_set_executable (svn_boolean_t *did_set,
240
 
                              const char *path,
241
 
                              svn_wc_adm_access_t *adm_access,
242
 
                              apr_pool_t *pool)
243
 
{
244
 
  const svn_string_t *propval;
245
 
  SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EXECUTABLE, path, adm_access,
246
 
                            pool));
247
 
 
248
 
  if (propval != NULL)
249
 
    {
250
 
      SVN_ERR (svn_io_set_file_executable (path, TRUE, FALSE, pool));
251
 
      if (did_set)
252
 
        *did_set = TRUE;
253
 
    }
254
 
  else if (did_set)
255
 
    *did_set = FALSE;
256
 
 
257
 
  return SVN_NO_ERROR;
258
 
}
259
 
 
260
 
 
261
 
svn_error_t *
262
 
svn_wc__maybe_set_read_only (svn_boolean_t *did_set,
 
227
  SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_SPECIAL, path,
 
228
                          adm_access, pool));
 
229
  *special = propval != NULL;
 
230
 
 
231
  return SVN_NO_ERROR;
 
232
}
 
233
 
 
234
 
 
235
svn_error_t *
 
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)
266
240
{
 
241
  const svn_string_t *propval;
 
242
  SVN_ERR(svn_wc_prop_get(&propval, SVN_PROP_EXECUTABLE, path, adm_access,
 
243
                          pool));
 
244
 
 
245
  if (propval != NULL)
 
246
    {
 
247
      SVN_ERR(svn_io_set_file_executable(path, TRUE, FALSE, pool));
 
248
      if (did_set)
 
249
        *did_set = TRUE;
 
250
    }
 
251
  else if (did_set)
 
252
    *did_set = FALSE;
 
253
 
 
254
  return SVN_NO_ERROR;
 
255
}
 
256
 
 
257
 
 
258
svn_error_t *
 
259
svn_wc__maybe_set_read_only(svn_boolean_t *did_set,
 
260
                            const char *path,
 
261
                            svn_wc_adm_access_t *adm_access,
 
262
                            apr_pool_t *pool)
 
263
{
267
264
  const svn_string_t *needs_lock;
268
265
  const svn_wc_entry_t* entry;
269
266
 
270
267
  if (did_set)
271
268
    *did_set = FALSE;
272
269
 
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;
276
273
 
277
 
  SVN_ERR (svn_wc_prop_get (&needs_lock, SVN_PROP_NEEDS_LOCK, path, 
278
 
                            adm_access, pool));
 
274
  SVN_ERR(svn_wc_prop_get(&needs_lock, SVN_PROP_NEEDS_LOCK, path, 
 
275
                          adm_access, pool));
279
276
 
280
277
  if (needs_lock != NULL)
281
278
    {
282
 
      SVN_ERR (svn_io_set_file_read_write_carefully (path, FALSE, 
283
 
                                                     FALSE, pool));
 
279
      SVN_ERR(svn_io_set_file_read_only(path, FALSE, pool));
284
280
      if (did_set)
285
281
        *did_set = TRUE;
286
282
    }