~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_client/revert.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
 * revert.c:  wrapper around wc revert functionality.
 
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
 
 
22
 
 
23
/*** Includes. ***/
 
24
 
 
25
#include "svn_wc.h"
 
26
#include "svn_client.h"
 
27
#include "svn_pools.h"
 
28
#include "svn_error.h"
 
29
#include "svn_time.h"
 
30
#include "svn_config.h"
 
31
#include "client.h"
 
32
 
 
33
 
 
34
 
 
35
/*** Code. ***/
 
36
 
 
37
/* Attempt to revert PATH, recursively if RECURSIVE is true and PATH
 
38
   is a directory, else non-recursively.  Consult CTX to determine
 
39
   whether or not to revert timestamp to the time of last commit
 
40
   ('use-commit-times = yes').  Use POOL for temporary allocation.
 
41
 
 
42
   If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
 
43
static svn_error_t *
 
44
revert (const char *path,
 
45
        svn_boolean_t recursive,
 
46
        svn_client_ctx_t *ctx,
 
47
        apr_pool_t *pool)
 
48
{
 
49
  svn_wc_adm_access_t *adm_access, *target_access;
 
50
  svn_boolean_t use_commit_times;
 
51
  const char *target;
 
52
  svn_config_t *cfg;
 
53
  svn_error_t *err;
 
54
 
 
55
  cfg = ctx->config ? apr_hash_get (ctx->config, SVN_CONFIG_CATEGORY_CONFIG,  
 
56
                                    APR_HASH_KEY_STRING) : NULL;
 
57
 
 
58
  SVN_ERR (svn_config_get_bool (cfg, &use_commit_times,
 
59
                                SVN_CONFIG_SECTION_MISCELLANY,
 
60
                                SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
 
61
                                FALSE));
 
62
 
 
63
  SVN_ERR (svn_wc_adm_open_anchor (&adm_access, &target_access, &target, path,
 
64
                                   TRUE, recursive ? -1 : 0,
 
65
                                   ctx->cancel_func, ctx->cancel_baton,
 
66
                                   pool));
 
67
 
 
68
  err = svn_wc_revert2 (path, adm_access, recursive, use_commit_times,
 
69
                        ctx->cancel_func, ctx->cancel_baton,
 
70
                        ctx->notify_func2, ctx->notify_baton2,
 
71
                        pool);
 
72
 
 
73
  /* If no error, or SVN_ERR_UNVERSIONED_RESOURCE error, then we want
 
74
     to close up before returning.  For any other kind of error, we
 
75
     want to leave things exactly as they were when the error
 
76
     occurred. */
 
77
 
 
78
  if (err && err->apr_err != SVN_ERR_UNVERSIONED_RESOURCE)
 
79
    return err;
 
80
 
 
81
  SVN_ERR (svn_wc_adm_close (adm_access));
 
82
 
 
83
  return err;
 
84
}
 
85
 
 
86
 
 
87
svn_error_t *
 
88
svn_client_revert (const apr_array_header_t *paths,
 
89
                   svn_boolean_t recursive,
 
90
                   svn_client_ctx_t *ctx,
 
91
                   apr_pool_t *pool)
 
92
{
 
93
  apr_pool_t *subpool = svn_pool_create (pool);
 
94
  svn_error_t *err = SVN_NO_ERROR;
 
95
  int i;
 
96
 
 
97
  for (i = 0; i < paths->nelts; i++)
 
98
    {
 
99
      const char *path = APR_ARRAY_IDX (paths, i, const char *);
 
100
 
 
101
      svn_pool_clear (subpool);
 
102
 
 
103
      /* See if we've been asked to cancel this operation. */
 
104
      if ((ctx->cancel_func) 
 
105
          && ((err = ctx->cancel_func (ctx->cancel_baton))))
 
106
        goto errorful;
 
107
 
 
108
      err = revert (path, recursive, ctx, subpool);
 
109
      if (err)
 
110
        {
 
111
          /* If one of the targets isn't versioned, just send a 'skip'
 
112
             notification and move on. */
 
113
          if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
 
114
              || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE)
 
115
            {
 
116
              if (ctx->notify_func2)
 
117
                (*ctx->notify_func2)
 
118
                  (ctx->notify_baton2,
 
119
                   svn_wc_create_notify (path, svn_wc_notify_skip, subpool),
 
120
                   subpool);
 
121
              svn_error_clear (err);
 
122
              err = SVN_NO_ERROR;
 
123
              continue;
 
124
            }
 
125
          else
 
126
            goto errorful;
 
127
        }
 
128
    }
 
129
  
 
130
 errorful:
 
131
 
 
132
  svn_pool_destroy (subpool);
 
133
  
 
134
  /* Sleep to ensure timestamp integrity. */
 
135
  svn_sleep_for_timestamps ();
 
136
 
 
137
  return err;
 
138
}
 
139
 
 
140