2
* blame-cmd.c -- Display blame information
4
* ====================================================================
5
* Copyright (c) 2000-2004 CollabNet. All rights reserved.
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.
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
* ====================================================================
22
#include "svn_client.h"
23
#include "svn_error.h"
25
#include "svn_pools.h"
26
#include "svn_cmdline.h"
30
#include "svn_private_config.h"
34
svn_cl__opt_state_t *opt_state;
41
blame_receiver (void *baton,
43
svn_revnum_t revision,
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;
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)
59
if (opt_state->verbose)
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,
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. */
73
return svn_stream_printf (out, pool, "%s %10s %s %s\n", rev_str,
74
author ? author : " -",
79
return svn_stream_printf (out, pool, "%s %10s %s\n", rev_str,
80
author ? author : " -", line);
85
/* This implements the `svn_opt_subcommand_t' interface. */
87
svn_cl__blame (apr_getopt_t *os,
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;
94
apr_array_header_t *targets;
98
svn_boolean_t is_head_or_base = FALSE;
100
SVN_ERR (svn_opt_args_to_target_array2 (&targets, os,
101
opt_state->targets, pool));
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);
107
if (opt_state->end_revision.kind == svn_opt_revision_unspecified)
109
if (opt_state->start_revision.kind != svn_opt_revision_unspecified)
111
/* In the case that -rX was specified, we actually want to set the
112
range to be -r1:X. */
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;
119
is_head_or_base = TRUE;
122
if (opt_state->start_revision.kind == svn_opt_revision_unspecified)
124
opt_state->start_revision.kind = svn_opt_revision_number;
125
opt_state->start_revision.value.number = 1;
128
SVN_ERR (svn_stream_for_stdout (&out, pool));
129
bl.opt_state = opt_state;
132
subpool = svn_pool_create (pool);
134
for (i = 0; i < targets->nelts; i++)
137
const char *target = ((const char **) (targets->elts))[i];
138
const char *truepath;
139
svn_opt_revision_t peg_revision;
141
svn_pool_clear (subpool);
142
SVN_ERR (svn_cl__check_cancel (ctx->cancel_baton));
145
if (svn_path_is_url (target))
146
opt_state->end_revision.kind = svn_opt_revision_head;
148
opt_state->end_revision.kind = svn_opt_revision_base;
151
/* Check for a peg revision. */
152
SVN_ERR (svn_opt_parse_path (&peg_revision, &truepath, target,
155
err = svn_client_blame2 (truepath,
157
&opt_state->start_revision,
158
&opt_state->end_revision,
165
if (err->apr_err == SVN_ERR_CLIENT_IS_BINARY_FILE)
167
SVN_ERR (svn_cmdline_printf (subpool,
168
_("Skipping binary file: '%s'\n"),
170
svn_error_clear (err);
178
svn_pool_destroy (subpool);