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

[PATCH] "svnlook diff" option to filter files

From: Pete Gonzalez <pgonzalez_at_bluel.com>
Date: 2005-11-18 04:25:02 CET

The attached patch is for this file:

     subversion/subversion/svnlook/main.c

It adds a new command-line option "--no-diff", which is used to prevent
svnlook from displaying differences for certain files. (The effect is
similar the way binary files are excluded.) For example:

     svnlook diff my_repository -r 1234 --no-diff "*.resx *Designer.cs"

In this example, if revision #1234 affected any filenames such as
"MyForm.resx" or "MyForm.Designer.cs", they will be excluded from the diff
(although they will still be listed as changed).

I created this option because our Subversion log e-mails were becoming
cluttered by a lot of verbose diffs for text files that are normally edited
using automated tools. For example, in C# a .resx file might contain
thousands of lines of BASE64-encoded image data.

Cheers,
-Pete

Index: main.c
===================================================================
--- main.c (revision 17436)
+++ main.c (working copy)
@@ -75,6 +75,7 @@
     svnlook__show_ids,
     svnlook__no_diff_deleted,
     svnlook__no_diff_added,
+ svnlook__no_diff,
     svnlook__diff_copy_from,
     svnlook__revprop_opt,
     svnlook__full_paths,
@@ -116,6 +117,9 @@
     {"no-diff-added", svnlook__no_diff_added, 0,
      N_("do not print differences for added files")},
 
+ {"no-diff", svnlook__no_diff, 1,
+ N_("do not print differences for files matching ARG")},
+
     {"diff-copy-from", svnlook__diff_copy_from, 0,
      N_("print differences against the copy source")},
 
@@ -163,7 +167,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__no_diff, svnlook__diff_copy_from} },
 
     {"dirs-changed", subcommand_dirschanged, {0},
      N_("usage: svnlook dirs-changed REPOS_PATH\n\n"
@@ -243,6 +247,7 @@
   svn_boolean_t help; /* --help */
   svn_boolean_t no_diff_deleted; /* --no-diff-deleted */
   svn_boolean_t no_diff_added; /* --no-diff-added */
+ const char *no_diff; /* --no-diff */
   svn_boolean_t diff_copy_from; /* --diff-copy-from */
   svn_boolean_t verbose; /* --verbose */
   svn_boolean_t revprop; /* --revprop */
@@ -259,6 +264,7 @@
   svn_boolean_t show_ids;
   svn_boolean_t no_diff_deleted;
   svn_boolean_t no_diff_added;
+ const char *no_diff;
   svn_boolean_t diff_copy_from;
   svn_boolean_t full_paths;
   svn_boolean_t copy_info;
@@ -848,6 +854,7 @@
                  const char *path /* UTF-8! */,
                  const char *base_path /* UTF-8! */,
                  const svnlook_ctxt_t *c,
+ apr_array_header_t *no_diff_patterns,
                  const char *tmpdir,
                  apr_pool_t *pool)
 {
@@ -969,14 +976,22 @@
 
   if (do_diff)
     {
+ int ignore_me = FALSE;
+
+ if (no_diff_patterns != NULL)
+ ignore_me = svn_cstring_match_glob_list (path, no_diff_patterns);
+
       SVN_ERR (svn_cmdline_printf (pool, "%s\n", equal_string));
       SVN_ERR (svn_cmdline_fflush (stdout));
 
- if (binary)
+ if (ignore_me)
+ SVN_ERR (svn_cmdline_printf (pool, _("(Skipping this file type)\n")));
+ else if (binary)
         SVN_ERR (svn_cmdline_printf (pool, _("(Binary files differ)\n")));
       else
         {
           svn_diff_t *diff;
+
           SVN_ERR (svn_diff_file_diff (&diff, orig_path, new_path, pool));
           if (svn_diff_contains_diffs (diff))
             {
@@ -1041,7 +1056,7 @@
   SVN_ERR (print_diff_tree (root, base_root, node,
                             svn_path_join (path, node->name, subpool),
                             svn_path_join (base_path, node->name, subpool),
- c, tmpdir, subpool));
+ c, no_diff_patterns, tmpdir, subpool));
   while (node->sibling)
     {
       svn_pool_clear (subpool);
@@ -1049,7 +1064,7 @@
       SVN_ERR (print_diff_tree (root, base_root, node,
                                 svn_path_join (path, node->name, subpool),
                                 svn_path_join (base_path, node->name, subpool),
- c, tmpdir, subpool));
+ c, no_diff_patterns, tmpdir, subpool));
     }
   apr_pool_destroy (subpool);
 
@@ -1419,11 +1434,16 @@
     {
       const char *tmpdir;
       svn_error_t *err;
+ apr_array_header_t *no_diff_patterns = NULL;
 
+ /* parse the --no-diff patterns */
+ if (c->no_diff != NULL)
+ no_diff_patterns = svn_cstring_split ( c->no_diff, " ", TRUE, pool);
+
       SVN_ERR (svn_fs_revision_root (&base_root, c->fs, base_rev_id, pool));
       SVN_ERR (create_unique_tmpdir (&tmpdir, pool));
       err = print_diff_tree (root, base_root, tree, "", "",
- c, tmpdir, pool);
+ c, no_diff_patterns, tmpdir, pool);
       if (err)
         {
           svn_error_clear (svn_io_remove_dir (tmpdir, pool));
@@ -1671,6 +1691,7 @@
   baton->show_ids = opt_state->show_ids;
   baton->no_diff_deleted = opt_state->no_diff_deleted;
   baton->no_diff_added = opt_state->no_diff_added;
+ baton->no_diff = opt_state->no_diff;
   baton->diff_copy_from = opt_state->diff_copy_from;
   baton->full_paths = opt_state->full_paths;
   baton->copy_info = opt_state->copy_info;
@@ -2101,6 +2122,10 @@
           opt_state.no_diff_added = TRUE;
           break;
 
+ case svnlook__no_diff:
+ opt_state.no_diff = opt_arg;
+ break;
+
         case svnlook__diff_copy_from:
           opt_state.diff_copy_from = TRUE;
           break;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Nov 18 04:26:01 2005

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

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