[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: SVN & Diff & White Spaces

From: Stefan Sperling <stsp_at_elego.de>
Date: 2007-07-26 11:50:32 CEST

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? :)

What this patch achieves so far:

(In this example, the file project/a contains 'a' in revision 1
and 'a ' in revision 2.)

  [stsp@ted /tmp]$ svnlook cat -r1 /tmp/repos project/a
  a
  [stsp@ted /tmp]$ svnlook cat -r2 /tmp/repos project/a
  a
  [stsp@ted /tmp]$ svnlook diff -r2 /tmp/repos project/a
  Modified: project/a
  ===================================================================
  --- project/a 2007-07-26 09:14:16 UTC (rev 1)
  +++ project/a 2007-07-26 09:15:15 UTC (rev 2)
  @@ -1 +1 @@
  -a
  +a
  
  [stsp@ted /tmp]$ svnlook diff --ignore-whitespace -r2 /tmp/repos project/a
  Modified: project/a
  ===================================================================
  
  [stsp@ted /tmp]$

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;
 
@@ -904,7 +910,14 @@
       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;
@@ -1577,6 +1590,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 +2035,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 11:53:29 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.