~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_delta/delta-window-test.h

  • 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
/* delta-window-test.h -- utilities for delta window output
 
2
 *
 
3
 * ====================================================================
 
4
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
5
 *
 
6
 * This software is licensed as described in the file COPYING, which
 
7
 * you should have received as part of this distribution.  The terms
 
8
 * are also available at http://subversion.tigris.org/license-1.html.
 
9
 * If newer versions of this license are posted there, you may use a
 
10
 * newer version instead, at your option.
 
11
 *
 
12
 * This software consists of voluntary contributions made by many
 
13
 * individuals.  For exact contribution history, see the revision
 
14
 * history and logs, available at http://subversion.tigris.org/.
 
15
 * ====================================================================
 
16
 */
 
17
 
 
18
#ifndef SVN_DELTA_WINDOW_TEST_H
 
19
#define SVN_DELTA_WINDOW_TEST_H
 
20
 
 
21
#define APR_WANT_STDIO
 
22
#define APR_WANT_STRFUNC
 
23
#include <apr_want.h>
 
24
#include <apr_lib.h>
 
25
 
 
26
#include "svn_delta.h"
 
27
 
 
28
static apr_off_t
 
29
delta_window_size_estimate (const svn_txdelta_window_t *window)
 
30
{
 
31
  apr_off_t len;
 
32
  int i;
 
33
 
 
34
  if (!window)
 
35
    return 0;
 
36
 
 
37
  /* Try to estimate the size of the delta. */
 
38
  for (i = 0, len = 0; i < window->num_ops; ++i)
 
39
    {
 
40
      apr_size_t const offset = window->ops[i].offset;
 
41
      apr_size_t const length = window->ops[i].length;
 
42
      if (window->ops[i].action_code == svn_txdelta_new)
 
43
        {
 
44
          len += 1;             /* opcode */
 
45
          len += (length > 255 ? 2 : 1);
 
46
          len += length;
 
47
        }
 
48
      else
 
49
        {
 
50
          len += 1;             /* opcode */
 
51
          len += (offset > 255 ? 2 : 1);
 
52
          len += (length > 255 ? 2 : 1);
 
53
        }
 
54
    }
 
55
 
 
56
  return len;
 
57
}
 
58
 
 
59
 
 
60
static apr_off_t
 
61
delta_window_print (const svn_txdelta_window_t *window,
 
62
                    const char *tag, FILE *stream)
 
63
{
 
64
  const apr_off_t len = delta_window_size_estimate (window);
 
65
  apr_off_t op_offset = 0;
 
66
  int i;
 
67
 
 
68
  if (!window)
 
69
    return 0;
 
70
 
 
71
  fprintf (stream, "%s: (WINDOW %" APR_OFF_T_FMT, tag, len);
 
72
  fprintf (stream,
 
73
           " (%" SVN_FILESIZE_T_FMT
 
74
           " %" APR_SIZE_T_FMT " %" APR_SIZE_T_FMT ")",
 
75
           window->sview_offset, window->sview_len, window->tview_len);
 
76
  for (i = 0; i < window->num_ops; ++i)
 
77
    {
 
78
      apr_size_t const offset = window->ops[i].offset;
 
79
      apr_size_t const length = window->ops[i].length;
 
80
      apr_size_t tmp;
 
81
      switch (window->ops[i].action_code)
 
82
        {
 
83
        case svn_txdelta_source:
 
84
          fprintf (stream, "\n%s:   (%" APR_OFF_T_FMT " SRC %" APR_SIZE_T_FMT
 
85
                   " %" APR_SIZE_T_FMT ")", tag, op_offset, offset, length);
 
86
          break;
 
87
        case svn_txdelta_target:
 
88
          fprintf (stream, "\n%s:   (%" APR_OFF_T_FMT " TGT %" APR_SIZE_T_FMT
 
89
                   " %" APR_SIZE_T_FMT ")", tag, op_offset, offset, length);
 
90
          break;
 
91
        case svn_txdelta_new:
 
92
          fprintf (stream, "\n%s:   (%" APR_OFF_T_FMT " NEW %"
 
93
                   APR_SIZE_T_FMT " \"", tag, op_offset, length);
 
94
          for (tmp = offset; tmp < offset + length; ++tmp)
 
95
            {
 
96
              int const dat = window->new_data->data[tmp];
 
97
              if (apr_iscntrl (dat) || !apr_isascii(dat))
 
98
                fprintf (stream, "\\%3.3o", dat & 0xff);
 
99
              else if (dat == '\\')
 
100
                fputs ("\\\\", stream);
 
101
              else
 
102
                putc (dat, stream);
 
103
            }
 
104
          fputs ("\")", stream);
 
105
          break;
 
106
        default:
 
107
          fprintf (stream, "\n%s:   (BAD-OP)", tag);
 
108
        }
 
109
 
 
110
      op_offset += length;
 
111
    }
 
112
  fputs (")\n", stream);
 
113
  return len;
 
114
}
 
115
 
 
116
 
 
117
#endif /* SVN_DELTA_WINDOW_TEST_H */