You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2010/10/28 15:54:16 UTC
svn commit: r1028296 - /subversion/trunk/tools/diff/diff.c
Author: cmpilato
Date: Thu Oct 28 13:54:16 2010
New Revision: 1028296
URL: http://svn.apache.org/viewvc?rev=1028296&view=rev
Log:
Teach the standalone diff sample tool how to handle our diff
extensions. (Issue #2799)
* tools/diff/diff.c
(do_diff): Add 'options' parameter, passed to an updated call to
svn_diff_file_diff_2(). Also, add 'show_c_function' parameter,
passed to an updated call to svn_diff_file_output_unified3().
(print_usage): New function.
(main): Parse the arguments, culling out all options (and noticing
if -p is among them) so those things can be passed to an updated
call to do_diff().
Patch by: Nicolás Lichtmaier <ni...@reloco.com.ar>
(Tweaked pretty heavily by me.)
Modified:
subversion/trunk/tools/diff/diff.c
Modified: subversion/trunk/tools/diff/diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/diff/diff.c?rev=1028296&r1=1028295&r2=1028296&view=diff
==============================================================================
--- subversion/trunk/tools/diff/diff.c (original)
+++ subversion/trunk/tools/diff/diff.c Thu Oct 28 13:54:16 2010
@@ -28,35 +28,55 @@
#include "svn_pools.h"
#include "svn_diff.h"
#include "svn_io.h"
-
+#include "svn_utf.h"
static svn_error_t *
do_diff(svn_stream_t *ostream,
- const char *original, const char *modified,
+ const char *original,
+ const char *modified,
svn_boolean_t *has_changes,
+ svn_diff_file_options_t *options,
+ svn_boolean_t show_c_function,
apr_pool_t *pool)
{
svn_diff_t *diff;
- SVN_ERR(svn_diff_file_diff(&diff, original, modified, pool));
-
+ SVN_ERR(svn_diff_file_diff_2(&diff, original, modified, options, pool));
*has_changes = svn_diff_contains_diffs(diff);
+ return svn_diff_file_output_unified3(ostream, diff, original, modified,
+ NULL, NULL, SVN_APR_LOCALE_CHARSET,
+ NULL, show_c_function, pool);
+}
- SVN_ERR(svn_diff_file_output_unified(ostream, diff,
- original, modified,
- NULL, NULL, pool));
-
- return NULL;
+static void
+print_usage(svn_stream_t *ostream, const char *progname,
+ apr_pool_t *pool)
+{
+ svn_error_clear(svn_stream_printf(ostream, pool,
+ "Usage: %s [OPTIONS] <file1> <file2>\n"
+ "\n"
+ "Display the differences between <file1> and <file2> in unified diff\n"
+ "format. OPTIONS are diff extensions as described by 'svn help diff'.\n"
+ "Use '--' alone to indicate that no more options follow.\n",
+ progname));
}
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
{
apr_pool_t *pool;
svn_stream_t *ostream;
- int rc;
svn_error_t *svn_err;
+ svn_boolean_t has_changes;
+ svn_diff_file_options_t *diff_options;
+ apr_array_header_t *options_array;
+ int i;
+ const char *from = NULL;
+ const char *to = NULL;
+ svn_boolean_t show_c_function = FALSE;
+ svn_boolean_t no_more_options = FALSE;
apr_initialize();
+ atexit(apr_terminate);
pool = svn_pool_create(NULL);
@@ -64,32 +84,65 @@ int main(int argc, char *argv[])
if (svn_err)
{
svn_handle_error2(svn_err, stdout, FALSE, "diff: ");
- rc = 2;
+ return 2;
}
- else if (argc == 3)
+
+ options_array = apr_array_make(pool, 0, sizeof(const char *));
+
+ for (i = 1 ; i < argc ; i++)
{
- svn_boolean_t has_changes;
-
- svn_err = do_diff(ostream, argv[1], argv[2], &has_changes, pool);
- if (svn_err == NULL)
+ if (!no_more_options && (argv[i][0] == '-'))
{
- rc = has_changes ? 1 : 0;
+ /* Special case: '--' means "no more options follow" */
+ if (argv[i][1] == '-' && !argv[i][2])
+ {
+ no_more_options = TRUE;
+ continue;
+ }
+ /* Special case: we need to detect '-p' and handle it specially */
+ if (argv[i][1] == 'p' && !argv[i][2])
+ {
+ show_c_function = TRUE;
+ continue;
+ }
+ APR_ARRAY_PUSH(options_array, const char *) = argv[i];
}
else
{
- svn_handle_error2(svn_err, stdout, FALSE, "diff: ");
- rc = 2;
+ if (from == NULL)
+ from = argv[i];
+ else if (to == NULL)
+ to = argv[i];
+ else
+ {
+ print_usage(ostream, argv[0], pool);
+ return 2;
+ }
}
}
- else
+
+ if (!from || !to)
{
- svn_error_clear(svn_stream_printf(ostream, pool,
- "Usage: %s <file1> <file2>\n",
- argv[0]));
- rc = 2;
+ print_usage(ostream, argv[0], pool);
+ return 2;
}
- apr_terminate();
+ diff_options = svn_diff_file_options_create(pool);
+
+ svn_err = svn_diff_file_options_parse(diff_options, options_array, pool);
+ if (svn_err)
+ {
+ svn_handle_error2(svn_err, stdout, FALSE, "diff: ");
+ return 2;
+ }
+
+ svn_err = do_diff(ostream, from, to, &has_changes,
+ diff_options, show_c_function, pool);
+ if (svn_err)
+ {
+ svn_handle_error2(svn_err, stdout, FALSE, "diff: ");
+ return 2;
+ }
- return rc;
+ return has_changes ? 1 : 0;
}