~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/clients/cmdline/notify.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
 * feedback.c:  feedback handlers for cmdline client.
 
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
#define APR_WANT_STDIO
 
26
#define APR_WANT_STRFUNC
 
27
#include <apr_want.h>
 
28
 
 
29
#include "svn_cmdline.h"
 
30
#include "svn_pools.h"
 
31
#include "svn_path.h"
 
32
#include "cl.h"
 
33
 
 
34
#include "svn_private_config.h"
 
35
 
 
36
 
 
37
/* Baton for notify and friends. */
 
38
struct notify_baton
 
39
{
 
40
  svn_boolean_t received_some_change;
 
41
  svn_boolean_t is_checkout;
 
42
  svn_boolean_t is_export;
 
43
  svn_boolean_t suppress_final_line;
 
44
  svn_boolean_t sent_first_txdelta;
 
45
  svn_boolean_t in_external;
 
46
  svn_boolean_t had_print_error; /* Used to not keep printing error messages
 
47
                                    when we've already had one print error. */
 
48
};
 
49
 
 
50
 
 
51
/* This implements `svn_wc_notify_func2_t'.
 
52
 * NOTE: This function can't fail, so we just ignore any print errors. */
 
53
static void
 
54
notify (void *baton, const svn_wc_notify_t *n, apr_pool_t *pool)
 
55
{
 
56
  struct notify_baton *nb = baton;
 
57
  char statchar_buf[5] = "    ";
 
58
  const char *path_local;
 
59
  svn_error_t *err;
 
60
 
 
61
  path_local = svn_path_local_style (n->path, pool);
 
62
 
 
63
  switch (n->action)
 
64
    {
 
65
    case svn_wc_notify_skip:
 
66
      if (n->content_state == svn_wc_notify_state_missing)
 
67
        {
 
68
          if ((err = svn_cmdline_printf
 
69
               (pool, _("Skipped missing target: '%s'\n"),
 
70
                path_local)))
 
71
            goto print_error;
 
72
        }
 
73
      else
 
74
        {
 
75
          if ((err = svn_cmdline_printf
 
76
               (pool, _("Skipped '%s'\n"), path_local)))
 
77
            goto print_error;
 
78
        }
 
79
      break;
 
80
 
 
81
    case svn_wc_notify_update_delete:
 
82
      nb->received_some_change = TRUE;
 
83
      if ((err = svn_cmdline_printf (pool, "D    %s\n", path_local)))
 
84
        goto print_error;
 
85
      break;
 
86
 
 
87
    case svn_wc_notify_update_add:
 
88
      nb->received_some_change = TRUE;
 
89
      if ((err = svn_cmdline_printf (pool, "A    %s\n", path_local)))
 
90
        goto print_error;
 
91
      break;
 
92
 
 
93
    case svn_wc_notify_restore:
 
94
      if ((err = svn_cmdline_printf (pool, _("Restored '%s'\n"),
 
95
                                     path_local)))
 
96
        goto print_error;
 
97
      break;
 
98
 
 
99
    case svn_wc_notify_revert:
 
100
      if ((err = svn_cmdline_printf (pool, _("Reverted '%s'\n"),
 
101
                                     path_local)))
 
102
        goto print_error;
 
103
      break;
 
104
 
 
105
    case svn_wc_notify_failed_revert:
 
106
      if (( err = svn_cmdline_printf (pool, _("Failed to revert '%s' -- "
 
107
                                              "try updating instead.\n"), 
 
108
                                      path_local)))
 
109
        goto print_error;
 
110
      break;
 
111
 
 
112
    case svn_wc_notify_resolved:
 
113
      if ((err = svn_cmdline_printf (pool,
 
114
                                     _("Resolved conflicted state of '%s'\n"),
 
115
                                     path_local)))
 
116
        goto print_error;
 
117
      break;
 
118
 
 
119
    case svn_wc_notify_add:
 
120
      /* We *should* only get the MIME_TYPE if PATH is a file.  If we
 
121
         do get it, and the mime-type is not textual, note that this
 
122
         is a binary addition. */
 
123
      if (n->mime_type && (svn_mime_type_is_binary (n->mime_type)))
 
124
        {
 
125
          if ((err = svn_cmdline_printf (pool, "A  (bin)  %s\n",
 
126
                                         path_local)))
 
127
            goto print_error;
 
128
        }
 
129
      else
 
130
        {
 
131
          if ((err = svn_cmdline_printf (pool, "A         %s\n",
 
132
                                         path_local)))
 
133
            goto print_error;
 
134
        }
 
135
      break;
 
136
 
 
137
    case svn_wc_notify_delete:
 
138
      nb->received_some_change = TRUE;
 
139
      if ((err = svn_cmdline_printf (pool, "D         %s\n",
 
140
                                     path_local)))
 
141
        goto print_error;
 
142
      break;
 
143
 
 
144
    case svn_wc_notify_update_update:
 
145
      {
 
146
        /* If this is an inoperative dir change, do no notification.
 
147
           An inoperative dir change is when a directory gets closed
 
148
           without any props having been changed. */
 
149
        if (! ((n->kind == svn_node_dir)
 
150
               && ((n->prop_state == svn_wc_notify_state_inapplicable)
 
151
                   || (n->prop_state == svn_wc_notify_state_unknown)
 
152
                   || (n->prop_state == svn_wc_notify_state_unchanged))))
 
153
          {
 
154
            if (n->kind == svn_node_file)
 
155
              {
 
156
                if (n->content_state == svn_wc_notify_state_conflicted)
 
157
                  statchar_buf[0] = 'C';
 
158
                else if (n->content_state == svn_wc_notify_state_merged)
 
159
                  statchar_buf[0] = 'G';
 
160
                else if (n->content_state == svn_wc_notify_state_changed)
 
161
                  statchar_buf[0] = 'U';
 
162
              }
 
163
            
 
164
            if (n->prop_state == svn_wc_notify_state_conflicted)
 
165
              statchar_buf[1] = 'C';
 
166
            else if (n->prop_state == svn_wc_notify_state_merged)
 
167
              statchar_buf[1] = 'G';
 
168
            else if (n->prop_state == svn_wc_notify_state_changed)
 
169
              statchar_buf[1] = 'U';
 
170
 
 
171
            if (n->lock_state == svn_wc_notify_lock_state_unlocked)
 
172
              statchar_buf[2] = 'B';
 
173
 
 
174
            if (statchar_buf[0] != ' ' || statchar_buf[1] != ' ')
 
175
              nb->received_some_change = TRUE;
 
176
 
 
177
            if (statchar_buf[0] != ' ' || statchar_buf[1] != ' '
 
178
                || statchar_buf[2] != ' ')
 
179
              {
 
180
                if ((err = svn_cmdline_printf (pool, "%s %s\n",
 
181
                                               statchar_buf, path_local)))
 
182
                  goto print_error;
 
183
              }
 
184
          }
 
185
      }
 
186
      break;
 
187
 
 
188
    case svn_wc_notify_update_external:
 
189
      /* Remember that we're now "inside" an externals definition. */
 
190
      nb->in_external = TRUE;
 
191
 
 
192
      /* Currently this is used for checkouts and switches too.  If we
 
193
         want different output, we'll have to add new actions. */
 
194
      if ((err = svn_cmdline_printf (pool,
 
195
                                     _("\nFetching external item into '%s'\n"),
 
196
                                     path_local)))
 
197
        goto print_error;
 
198
      break;
 
199
 
 
200
    case svn_wc_notify_update_completed:
 
201
      {
 
202
        if (! nb->suppress_final_line)
 
203
          {
 
204
            if (SVN_IS_VALID_REVNUM (n->revision))
 
205
              {
 
206
                if (nb->is_export)
 
207
                  {
 
208
                    if ((err = svn_cmdline_printf
 
209
                         (pool, nb->in_external
 
210
                          ? _("Exported external at revision %ld.\n")
 
211
                          : _("Exported revision %ld.\n"),
 
212
                          n->revision)))
 
213
                      goto print_error;
 
214
                  }
 
215
                else if (nb->is_checkout)
 
216
                  {
 
217
                    if ((err = svn_cmdline_printf
 
218
                         (pool, nb->in_external
 
219
                          ? _("Checked out external at revision %ld.\n")
 
220
                          : _("Checked out revision %ld.\n"),
 
221
                          n->revision)))
 
222
                      goto print_error;
 
223
                  }
 
224
                else
 
225
                  {
 
226
                    if (nb->received_some_change)
 
227
                      {
 
228
                        if ((err = svn_cmdline_printf
 
229
                             (pool, nb->in_external
 
230
                              ? _("Updated external to revision %ld.\n")
 
231
                              : _("Updated to revision %ld.\n"),
 
232
                              n->revision)))
 
233
                          goto print_error;
 
234
                      }
 
235
                    else
 
236
                      {
 
237
                        if ((err = svn_cmdline_printf
 
238
                             (pool, nb->in_external
 
239
                              ? _("External at revision %ld.\n")
 
240
                              : _("At revision %ld.\n"),
 
241
                              n->revision)))
 
242
                          goto print_error;
 
243
                      }
 
244
                  }
 
245
              }
 
246
            else  /* no revision */
 
247
              {
 
248
                if (nb->is_export)
 
249
                  {
 
250
                    if ((err = svn_cmdline_printf
 
251
                         (pool, nb->in_external
 
252
                          ? _("External export complete.\n")
 
253
                          : _("Export complete.\n"))))
 
254
                      goto print_error;
 
255
                  }
 
256
                else if (nb->is_checkout)
 
257
                  {
 
258
                    if ((err = svn_cmdline_printf
 
259
                         (pool, nb->in_external
 
260
                          ? _("External checkout complete.\n")
 
261
                          : _("Checkout complete.\n"))))
 
262
                      goto print_error;
 
263
                  }
 
264
                else
 
265
                  {
 
266
                    if ((err = svn_cmdline_printf
 
267
                         (pool, nb->in_external
 
268
                          ? _("External update complete.\n")
 
269
                          : _("Update complete.\n"))))
 
270
                      goto print_error;
 
271
                  }
 
272
              }
 
273
          }
 
274
      }
 
275
      if (nb->in_external)
 
276
        {
 
277
          nb->in_external = FALSE;
 
278
          if ((err = svn_cmdline_printf (pool, "\n")))
 
279
            goto print_error;
 
280
        }
 
281
      break;
 
282
 
 
283
    case svn_wc_notify_status_external:
 
284
      if ((err = svn_cmdline_printf
 
285
           (pool, _("\nPerforming status on external item at '%s'\n"), 
 
286
            path_local)))
 
287
        goto print_error;
 
288
      break;
 
289
 
 
290
    case svn_wc_notify_status_completed:
 
291
      if (SVN_IS_VALID_REVNUM (n->revision))
 
292
        if ((err = svn_cmdline_printf (pool,
 
293
                                       _("Status against revision: %6ld\n"),
 
294
                                       n->revision)))
 
295
          goto print_error;
 
296
      break;
 
297
 
 
298
    case svn_wc_notify_commit_modified:
 
299
      /* xgettext: Align the %s's on this and the following 4 messages */
 
300
      if ((err = svn_cmdline_printf (pool,
 
301
                                     _("Sending        %s\n"),
 
302
                                     path_local)))
 
303
        goto print_error;
 
304
      break;
 
305
 
 
306
    case svn_wc_notify_commit_added:
 
307
      if (n->mime_type && svn_mime_type_is_binary (n->mime_type))
 
308
        {
 
309
        if ((err = svn_cmdline_printf (pool,
 
310
                                       _("Adding  (bin)  %s\n"),
 
311
                                       path_local)))
 
312
          goto print_error;
 
313
        }
 
314
      else
 
315
        {
 
316
          if ((err = svn_cmdline_printf (pool,
 
317
                                         _("Adding         %s\n"),
 
318
                                         path_local)))
 
319
            goto print_error;
 
320
        }
 
321
      break;
 
322
 
 
323
    case svn_wc_notify_commit_deleted:
 
324
      if ((err = svn_cmdline_printf (pool, _("Deleting       %s\n"),
 
325
                                     path_local)))
 
326
        goto print_error;
 
327
      break;
 
328
 
 
329
    case svn_wc_notify_commit_replaced:
 
330
      if ((err = svn_cmdline_printf (pool,
 
331
                                     _("Replacing      %s\n"),
 
332
                                     path_local)))
 
333
        goto print_error;
 
334
      break;
 
335
 
 
336
    case svn_wc_notify_commit_postfix_txdelta:
 
337
      if (! nb->sent_first_txdelta)
 
338
        {
 
339
          nb->sent_first_txdelta = TRUE;
 
340
          if ((err = svn_cmdline_printf (pool,
 
341
                                         _("Transmitting file data "))))
 
342
            goto print_error;
 
343
        }
 
344
 
 
345
      if ((err = svn_cmdline_printf (pool, ".")))
 
346
        goto print_error;
 
347
      fflush (stdout);
 
348
      break;
 
349
 
 
350
    case svn_wc_notify_locked:
 
351
      if ((err = svn_cmdline_printf (pool, _("'%s' locked by user '%s'.\n"),
 
352
                                     n->path, n->lock->owner)))
 
353
        goto print_error;
 
354
      break;
 
355
 
 
356
    case svn_wc_notify_unlocked:
 
357
      if ((err = svn_cmdline_printf (pool, _("'%s' unlocked.\n"),
 
358
                                     n->path)))
 
359
        goto print_error;
 
360
      break;
 
361
 
 
362
    case svn_wc_notify_failed_lock:
 
363
    case svn_wc_notify_failed_unlock:
 
364
      svn_handle_error (n->err, stderr, FALSE);
 
365
      break;
 
366
 
 
367
    default:
 
368
      break;
 
369
    }
 
370
 
 
371
  return;
 
372
 
 
373
 print_error:
 
374
  /* If we had no errors before, print this error to stderr. Else, don't print
 
375
     anything.  The user already knows there were some output errors,
 
376
     so there is no point in flooding her with an error per notification. */
 
377
  if (!nb->had_print_error)
 
378
    {
 
379
      nb->had_print_error = TRUE;
 
380
      svn_handle_error (err, stderr, FALSE);
 
381
    }
 
382
  svn_error_clear (err);
 
383
}
 
384
 
 
385
 
 
386
void
 
387
svn_cl__get_notifier (svn_wc_notify_func2_t *notify_func_p,
 
388
                      void **notify_baton_p,
 
389
                      svn_boolean_t is_checkout,
 
390
                      svn_boolean_t is_export,
 
391
                      svn_boolean_t suppress_final_line,
 
392
                      apr_pool_t *pool)
 
393
{
 
394
  struct notify_baton *nb = apr_palloc (pool, sizeof (*nb));
 
395
 
 
396
  nb->received_some_change = FALSE;
 
397
  nb->sent_first_txdelta = FALSE;
 
398
  nb->is_checkout = is_checkout;
 
399
  nb->is_export = is_export;
 
400
  nb->suppress_final_line = suppress_final_line;
 
401
  nb->in_external = FALSE;
 
402
  nb->had_print_error = FALSE;
 
403
 
 
404
  *notify_func_p = notify;
 
405
  *notify_baton_p = nb;
 
406
}