On Thu, Jul 26, 2007 at 11:50:32AM +0200, Stefan Sperling wrote:
> On Thu, Jul 26, 2007 at 12:47:41PM +0300, tom wrote:
> > That's API already implemented and I only deed use it in the svnlook
> > implementation?
>
> Yes, it's actually rather trivial (see patch below).
>
> A remaining problem is that the 'Modified' header and the delimiter
> are printed before the actual diff is made. But we can only tell if there
> were non-whitespace changes _after_ making the diff.
>
> Maybe you can do that part? :)
Thread moved from users@ to dev@.
As discussed off-list with Tom I also tackled the remaining problem.
Tom, can you test this diff to see if it implements the
desired behaviour?
[[[
Implement svnlook diff --ignore-whitespace.
* subversion/svnlook/main.c:
(print_diff_tree): Create diff header in buffer instead
of printing it straight to stdout, because it might turn out
the diff is empty if --ignore-whitespace is specified.
Only print header and diff if there is a diff to print.
Also, don't print a newline even if there is nothing else
interesting to print.
]]]
Index: subversion/svnlook/main.c
===================================================================
--- subversion/svnlook/main.c (revision 25835)
+++ subversion/svnlook/main.c (working copy)
@@ -78,7 +78,8 @@
svnlook__diff_copy_from,
svnlook__revprop_opt,
svnlook__full_paths,
- svnlook__copy_info
+ svnlook__copy_info,
+ svnlook__diff_ignore_space
};
/*
@@ -128,6 +129,9 @@
{"version", svnlook__version, 0,
N_("show program version information")},
+ {"ignore-whitespace", svnlook__diff_ignore_space, 0,
+ N_("ignore whitespace")},
+
{0, 0, 0, 0}
};
@@ -161,7 +165,7 @@
N_("usage: svnlook diff REPOS_PATH\n\n"
"Print GNU-style diffs of changed files and properties.\n"),
{'r', 't', svnlook__no_diff_deleted, svnlook__no_diff_added,
- svnlook__diff_copy_from} },
+ svnlook__diff_copy_from, svnlook__diff_ignore_space} },
{"dirs-changed", subcommand_dirschanged, {0},
N_("usage: svnlook dirs-changed REPOS_PATH\n\n"
@@ -247,6 +251,7 @@
svn_boolean_t full_paths; /* --full-paths */
svn_boolean_t copy_info; /* --copy-info */
svn_boolean_t non_recursive; /* --non-recursive */
+ svn_boolean_t diff_ignore_space;/* --ignore-whitespace */
};
@@ -264,6 +269,7 @@
svn_revnum_t rev_id;
svn_fs_txn_t *txn;
const char *txn_name /* UTF-8! */;
+ svn_boolean_t diff_ignore_space;
} svnlook_ctxt_t;
@@ -791,19 +797,23 @@
svn_boolean_t do_diff = FALSE;
svn_boolean_t orig_empty = FALSE;
svn_boolean_t is_copy = FALSE;
- svn_boolean_t printed_header = FALSE;
svn_boolean_t binary = FALSE;
apr_pool_t *subpool;
+ svn_stringbuf_t *header;
SVN_ERR(check_cancel(NULL));
if (! node)
return SVN_NO_ERROR;
+ header = svn_stringbuf_create("", pool);
+
/* Print copyfrom history for the top node of a copied tree. */
if ((SVN_IS_VALID_REVNUM(node->copyfrom_rev))
&& (node->copyfrom_path != NULL))
{
+ svn_string_t *str;
+
/* This is ... a copy. */
is_copy = TRUE;
@@ -816,11 +826,10 @@
else
base_path = apr_pstrdup(pool, node->copyfrom_path);
- SVN_ERR(svn_cmdline_printf(pool, _("Copied: %s (from rev %ld, %s)\n"),
- path, node->copyfrom_rev, base_path));
+ str = svn_string_createf(pool, _("Copied: %s (from rev %ld, %s)\n"),
+ path, node->copyfrom_rev, base_path);
+ svn_stringbuf_appendcstr(header, str->data);
- printed_header = TRUE;
-
SVN_ERR(svn_fs_revision_root(&base_root,
svn_fs_root_fs(base_root),
node->copyfrom_rev, pool));
@@ -879,37 +888,49 @@
tmpdir, pool));
}
- /* The header for the copy case has already been written, and we don't
+ /* The header for the copy case has already been created, and we don't
want a header here for files with only property modifications. */
- if (! printed_header
+ if (header->len == 0
&& (node->action != 'R' || node->text_mod))
{
- SVN_ERR(svn_cmdline_printf(pool, "%s: %s\n",
+ svn_string_t *str;
+
+ str = svn_string_createf(pool, "%s: %s\n",
((node->action == 'A') ? _("Added") :
((node->action == 'D') ? _("Deleted") :
((node->action == 'R') ? _("Modified")
: _("Index")))),
- path));
- printed_header = TRUE;
+ path);
+ svn_stringbuf_appendcstr(header, str->data);
}
}
if (do_diff)
{
- SVN_ERR(svn_cmdline_printf(pool, "%s\n", equal_string));
- SVN_ERR(svn_cmdline_fflush(stdout));
+ svn_stringbuf_appendcstr(header, equal_string);
+ svn_stringbuf_appendcstr(header, "\n");
if (binary)
- SVN_ERR(svn_cmdline_printf(pool, _("(Binary files differ)\n")));
+ svn_stringbuf_appendcstr(header, _("(Binary files differ)\n\n"));
else
{
svn_diff_t *diff;
- SVN_ERR(svn_diff_file_diff(&diff, orig_path, new_path, pool));
+ svn_diff_file_options_t *diff_options =
+ svn_diff_file_options_create(pool);
+
+ if (c->diff_ignore_space)
+ diff_options->ignore_space = svn_diff_file_ignore_space_all;
+
+ SVN_ERR(svn_diff_file_diff_2(&diff, orig_path, new_path,
+ diff_options, pool));
if (svn_diff_contains_diffs(diff))
{
svn_stream_t *ostream;
const char *orig_label, *new_label;
+ /* Print diff header. */
+ SVN_ERR(svn_cmdline_printf(pool, header->data));
+
SVN_ERR(svn_stream_for_stdout(&ostream, pool));
if (orig_empty)
@@ -923,14 +944,11 @@
orig_label, new_label,
svn_cmdline_output_encoding(pool), pool));
SVN_ERR(svn_stream_close(ostream));
+ SVN_ERR(svn_cmdline_printf(pool, "\n"));
}
}
-
- SVN_ERR(svn_cmdline_printf(pool, "\n"));
SVN_ERR(svn_cmdline_fflush(stdout));
}
- else if (printed_header)
- SVN_ERR(svn_cmdline_printf(pool, "\n"));
/* Make sure we delete any temporary files. */
if (orig_path)
@@ -1577,6 +1595,7 @@
baton->is_revision = opt_state->txn ? FALSE : TRUE;
baton->rev_id = opt_state->rev;
baton->txn_name = apr_pstrdup(pool, opt_state->txn);
+ baton->diff_ignore_space = opt_state->diff_ignore_space;
if (baton->txn_name)
SVN_ERR(svn_fs_open_txn(&(baton->txn), baton->fs,
baton->txn_name, pool));
@@ -2021,6 +2040,10 @@
opt_state.copy_info = TRUE;
break;
+ case svnlook__diff_ignore_space:
+ opt_state.diff_ignore_space = TRUE;
+ break;
+
default:
subcommand_help(NULL, NULL, pool);
svn_pool_destroy(pool);
--
Stefan Sperling <stsp@elego.de> Software Developer
elego Software Solutions GmbH HRB 77719
Gustav-Meyer-Allee 25, Gebaeude 12 Tel: +49 30 23 45 86 96
13355 Berlin Fax: +49 30 23 45 86 95
http://www.elego.de Geschaeftsfuehrer: Olaf Wagner
- application/pgp-signature attachment: stored
Received on Thu Jul 26 20:13:17 2007