~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_wc/translate.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * translate.c :  wc-specific eol/keyword substitution
 
3
 *
 
4
 * ====================================================================
 
5
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
6
 *
 
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.
 
12
 *
 
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
 * ====================================================================
 
17
 */
 
18
 
 
19
 
 
20
 
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
#include <assert.h>
 
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"
 
30
#include "svn_path.h"
 
31
#include "svn_error.h"
 
32
#include "svn_subst.h"
 
33
#include "svn_io.h"
 
34
#include "svn_props.h"
 
35
#include "svn_wc.h"
 
36
 
 
37
#include "wc.h"
 
38
#include "adm_files.h"
 
39
#include "translate.h"
 
40
 
 
41
#include "svn_private_config.h"
 
42
 
 
43
svn_error_t *
 
44
svn_wc_translated_file (const char **xlated_p,
 
45
                        const char *vfile,
 
46
                        svn_wc_adm_access_t *adm_access,
 
47
                        svn_boolean_t force_repair,
 
48
                        apr_pool_t *pool)
 
49
{
 
50
  svn_subst_eol_style_t style;
 
51
  const char *eol;
 
52
  svn_subst_keywords_t *keywords;
 
53
  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))
 
60
    {
 
61
      /* Translation would be a no-op, so return the original file. */
 
62
      *xlated_p = vfile;
 
63
    }
 
64
  else  /* some translation is necessary */
 
65
    {
 
66
      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_translate2 (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_translate2 (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_translate2 (vfile,
 
112
                                                  tmp_vfile,
 
113
                                                  NULL,
 
114
                                                  force_repair,
 
115
                                                  keywords,
 
116
                                                  FALSE,
 
117
                                                  special,
 
118
                                                  pool));
 
119
        }
 
120
      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;
 
129
    }
 
130
 
 
131
  return SVN_NO_ERROR;
 
132
}
 
133
 
 
134
 
 
135
svn_error_t *
 
136
svn_wc__get_eol_style (svn_subst_eol_style_t *style,
 
137
                       const char **eol,
 
138
                       const char *path,
 
139
                       svn_wc_adm_access_t *adm_access,
 
140
                       apr_pool_t *pool)
 
141
{
 
142
  const svn_string_t *propval;
 
143
 
 
144
  /* Get the property value. */
 
145
  SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_EOL_STYLE, path, adm_access,
 
146
                            pool));
 
147
 
 
148
  /* Convert it. */
 
149
  svn_subst_eol_style_from_value (style, eol, propval ? propval->data : NULL);
 
150
 
 
151
  return SVN_NO_ERROR;
 
152
}
 
153
 
 
154
 
 
155
void
 
156
svn_wc__eol_value_from_string (const char **value, const char *eol)
 
157
{
 
158
  if (eol == NULL)
 
159
    *value = NULL;
 
160
  else if (! strcmp ("\n", eol))
 
161
    *value = "LF";
 
162
  else if (! strcmp ("\r", eol))
 
163
    *value = "CR";
 
164
  else if (! strcmp ("\r\n", eol))
 
165
    *value = "CRLF";
 
166
  else
 
167
    *value = NULL;
 
168
}
 
169
 
 
170
 
 
171
svn_error_t *
 
172
svn_wc__get_keywords (svn_subst_keywords_t **keywords,
 
173
                      const char *path,
 
174
                      svn_wc_adm_access_t *adm_access,
 
175
                      const char *force_list,
 
176
                      apr_pool_t *pool)
 
177
{
 
178
  const char *list;
 
179
  svn_subst_keywords_t tmp_keywords = { 0 };
 
180
  const svn_wc_entry_t *entry = NULL;
 
181
 
 
182
  /* Start by assuming no keywords. */
 
183
  *keywords = NULL;
 
184
 
 
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)
 
188
    {
 
189
      const svn_string_t *propval;
 
190
 
 
191
      SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_KEYWORDS, path, adm_access,
 
192
                                pool));
 
193
      
 
194
      list = propval ? propval->data : NULL;
 
195
    }
 
196
  else
 
197
    list = force_list;
 
198
 
 
199
  /* The easy answer. */
 
200
  if (list == NULL)
 
201
    return SVN_NO_ERROR;
 
202
 
 
203
  SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
 
204
 
 
205
  SVN_ERR (svn_subst_build_keywords (&tmp_keywords,
 
206
                                     list,
 
207
                                     apr_psprintf (pool, "%ld",
 
208
                                                   entry->cmt_rev),
 
209
                                     entry->url,
 
210
                                     entry->cmt_date,
 
211
                                     entry->cmt_author,
 
212
                                     pool));
 
213
 
 
214
  *keywords = apr_pmemdup (pool, &tmp_keywords, sizeof (tmp_keywords));
 
215
      
 
216
  return SVN_NO_ERROR;
 
217
}
 
218
 
 
219
 
 
220
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)
 
225
{
 
226
  const svn_string_t *propval;
 
227
 
 
228
  /* 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,
 
263
                             const char *path,
 
264
                             svn_wc_adm_access_t *adm_access,
 
265
                             apr_pool_t *pool)
 
266
{
 
267
  const svn_string_t *needs_lock;
 
268
  const svn_wc_entry_t* entry;
 
269
 
 
270
  if (did_set)
 
271
    *did_set = FALSE;
 
272
 
 
273
  SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
 
274
  if (entry && entry->lock_token)
 
275
    return SVN_NO_ERROR;
 
276
 
 
277
  SVN_ERR (svn_wc_prop_get (&needs_lock, SVN_PROP_NEEDS_LOCK, path, 
 
278
                            adm_access, pool));
 
279
 
 
280
  if (needs_lock != NULL)
 
281
    {
 
282
      SVN_ERR (svn_io_set_file_read_write_carefully (path, FALSE, 
 
283
                                                     FALSE, pool));
 
284
      if (did_set)
 
285
        *did_set = TRUE;
 
286
    }
 
287
 
 
288
  return SVN_NO_ERROR;
 
289
}