~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/clients/cmdline/blame-cmd.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
 * blame-cmd.c -- Display blame information
 
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
/*** Includes. ***/
 
21
 
 
22
#include "svn_client.h"
 
23
#include "svn_error.h"
 
24
#include "svn_path.h"
 
25
#include "svn_pools.h"
 
26
#include "svn_cmdline.h"
 
27
#include "svn_time.h"
 
28
#include "cl.h"
 
29
 
 
30
#include "svn_private_config.h"
 
31
 
 
32
typedef struct
 
33
{
 
34
  svn_cl__opt_state_t *opt_state;
 
35
  svn_stream_t *out;
 
36
} blame_baton_t;
 
37
 
 
38
 
 
39
/*** Code. ***/
 
40
static svn_error_t *
 
41
blame_receiver (void *baton,
 
42
                apr_int64_t line_no,
 
43
                svn_revnum_t revision,
 
44
                const char *author,
 
45
                const char *date,
 
46
                const char *line,
 
47
                apr_pool_t *pool)
 
48
{
 
49
  svn_cl__opt_state_t *opt_state =
 
50
    ((blame_baton_t *) baton)->opt_state;
 
51
  svn_stream_t *out = ((blame_baton_t *)baton)->out;
 
52
  apr_time_t atime;
 
53
  const char *time_utf8;
 
54
  const char *time_stdout;
 
55
  const char *rev_str = SVN_IS_VALID_REVNUM (revision) 
 
56
                        ? apr_psprintf (pool, "%6ld", revision)
 
57
                        : "     -";
 
58
  
 
59
  if (opt_state->verbose)
 
60
    {
 
61
      if (date)
 
62
        {
 
63
          SVN_ERR (svn_time_from_cstring (&atime, date, pool));
 
64
          time_utf8 = svn_time_to_human_cstring (atime, pool);
 
65
          SVN_ERR (svn_cmdline_cstring_from_utf8 (&time_stdout, time_utf8,
 
66
                                                  pool));
 
67
        } else
 
68
          /* ### This is a 44 characters long string. It assumes the current
 
69
             format of svn_time_to_human_cstring and also 3 letter
 
70
             abbreviations for the month and weekday names.  Else, the
 
71
             line contents will be misaligned. */
 
72
          time_stdout = "                                           -";
 
73
      return svn_stream_printf (out, pool, "%s %10s %s %s\n", rev_str, 
 
74
                                author ? author : "         -", 
 
75
                                time_stdout , line);
 
76
    }
 
77
  else
 
78
    {
 
79
      return svn_stream_printf (out, pool, "%s %10s %s\n", rev_str, 
 
80
                                author ? author : "         -", line);
 
81
    }
 
82
}
 
83
 
 
84
 
 
85
/* This implements the `svn_opt_subcommand_t' interface. */
 
86
svn_error_t *
 
87
svn_cl__blame (apr_getopt_t *os,
 
88
               void *baton,
 
89
               apr_pool_t *pool)
 
90
{
 
91
  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
 
92
  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
 
93
  apr_pool_t *subpool;
 
94
  apr_array_header_t *targets;
 
95
  svn_stream_t *out;
 
96
  blame_baton_t bl;
 
97
  int i;
 
98
  svn_boolean_t is_head_or_base = FALSE;
 
99
 
 
100
  SVN_ERR (svn_opt_args_to_target_array2 (&targets, os, 
 
101
                                          opt_state->targets, pool));
 
102
 
 
103
  /* Blame needs a file on which to operate. */
 
104
  if (! targets->nelts)
 
105
    return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
 
106
 
 
107
  if (opt_state->end_revision.kind == svn_opt_revision_unspecified)
 
108
    {
 
109
      if (opt_state->start_revision.kind != svn_opt_revision_unspecified)
 
110
        {
 
111
          /* In the case that -rX was specified, we actually want to set the
 
112
             range to be -r1:X. */
 
113
 
 
114
          opt_state->end_revision = opt_state->start_revision;
 
115
          opt_state->start_revision.kind = svn_opt_revision_number;
 
116
          opt_state->start_revision.value.number = 1;
 
117
        }
 
118
      else
 
119
        is_head_or_base = TRUE;
 
120
    }
 
121
 
 
122
  if (opt_state->start_revision.kind == svn_opt_revision_unspecified)
 
123
    {
 
124
      opt_state->start_revision.kind = svn_opt_revision_number;
 
125
      opt_state->start_revision.value.number = 1;
 
126
    }
 
127
 
 
128
  SVN_ERR (svn_stream_for_stdout (&out, pool));
 
129
  bl.opt_state = opt_state;
 
130
  bl.out = out;
 
131
  
 
132
  subpool = svn_pool_create (pool);
 
133
 
 
134
  for (i = 0; i < targets->nelts; i++)
 
135
    {
 
136
      svn_error_t *err;
 
137
      const char *target = ((const char **) (targets->elts))[i];
 
138
      const char *truepath;
 
139
      svn_opt_revision_t peg_revision;
 
140
      
 
141
      svn_pool_clear (subpool);
 
142
      SVN_ERR (svn_cl__check_cancel (ctx->cancel_baton));
 
143
      if (is_head_or_base)
 
144
        {
 
145
          if (svn_path_is_url (target))
 
146
            opt_state->end_revision.kind = svn_opt_revision_head;
 
147
          else
 
148
            opt_state->end_revision.kind = svn_opt_revision_base;
 
149
        }
 
150
 
 
151
      /* Check for a peg revision. */
 
152
      SVN_ERR (svn_opt_parse_path (&peg_revision, &truepath, target,
 
153
                                   subpool));
 
154
               
 
155
      err = svn_client_blame2 (truepath,
 
156
                               &peg_revision,
 
157
                               &opt_state->start_revision,
 
158
                               &opt_state->end_revision,
 
159
                               blame_receiver,
 
160
                               &bl,
 
161
                               ctx,
 
162
                               subpool);
 
163
      if (err)
 
164
        {
 
165
          if (err->apr_err == SVN_ERR_CLIENT_IS_BINARY_FILE)
 
166
            {
 
167
              SVN_ERR (svn_cmdline_printf (subpool,
 
168
                                           _("Skipping binary file: '%s'\n"),
 
169
                                           target));
 
170
              svn_error_clear (err);
 
171
            }
 
172
          else
 
173
            {
 
174
              return err;
 
175
            }
 
176
        }
 
177
    }
 
178
  svn_pool_destroy (subpool);
 
179
 
 
180
  return SVN_NO_ERROR;
 
181
}