You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gb...@apache.org on 2013/10/19 11:25:00 UTC

svn commit: r1533721 - in /subversion/branches/invoke-diff-cmd-feature: BRANCH-README subversion/libsvn_subr/io.c subversion/svn/svn.c subversion/tests/cmdline/diff_tests.py

Author: gbg
Date: Sat Oct 19 09:24:59 2013
New Revision: 1533721

URL: http://svn.apache.org/r1533721
Log:
On the invoke-diff-cmd branch: Refactor __create_custom_diff_cmd() to
use the new delimiter schema.  Update svn_io_run_diff2(), add a
scratch_pool to svn_io_run_external_diff(), update help into in
svn_cl__options[].

* BRANCH-README:
  
  (What --invoke-diff-cmd and --invoke-diff3-cmd provide): Update svn
    help diff info.

* subversion/libsvn_subr/io.c

  (__create_custom_diff_cmd): Remove shell escape facility.  Change
    delimiters.

  (svn_io_run_diff2): Change call to __create_custom_diff_cmd to use
    the new delimiter schema.

  (svn_io_run_external_diff): Add scratch_pool and ensure destruction
    thereof.

* subversion/svn/svn.c

  (svn_cl__options[]): Update help info to reflect the new delimiter
    schema.

* subversion/tests/cmdline/diff_tests.py:
  
  (diff_invoke_external_diffcmd): Update test to use the new delimiter
    schema.

Modified:
    subversion/branches/invoke-diff-cmd-feature/BRANCH-README
    subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c
    subversion/branches/invoke-diff-cmd-feature/subversion/svn/svn.c
    subversion/branches/invoke-diff-cmd-feature/subversion/tests/cmdline/diff_tests.py

Modified: subversion/branches/invoke-diff-cmd-feature/BRANCH-README
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/BRANCH-README?rev=1533721&r1=1533720&r2=1533721&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/BRANCH-README (original)
+++ subversion/branches/invoke-diff-cmd-feature/BRANCH-README Sat Oct 19 09:24:59 2013
@@ -26,21 +26,20 @@ diff/merge program, from 'svn help diff'
 
   --invoke-diff-cmd ARG:
 
-   use ARG as format string for external diff command
-   invocation. 
-               
-   Substitutions: ;f1 original file                       
-                  ;f2 changed file                        
-                  ;l1 label of the original file          
-                  ;l2 label of the changed file           
-   Examples: --invoke-diff-cmd="diff -y ;f1 ;f2"        
-      --invoke-diff-cmd="kdiff3 -auto -o /home/u/log \  
-        +;f1 ;l2 --L1 ;l1 --L2 "Custom Label" "        
-
-   The delimiter ';' can be escaped by adding a ';', which will be
-   consumed in the process.  The delimiter can appear anywhere in the
-   string, ie, file=;f1 will expand as expected and file=;;f1+ will be
-   rendered as file=;f1+.
+       use ARG as format string for external diff command     
+        invocation. 
+                    
+        Substitutions: %svn_new% new file                      
+                       %svn_old% old file                      
+                       %svn_new_label%  label of the new file  
+                       %svn_old_label%  label of the old file  
+        Examples:                                              
+        --invoke-diff-cmd='diff -y %svn_new% %svn_old%'      
+        --invoke-diff-cmd="kdiff3 -auto -o /home/u/log \     
+              %svn_new% %svn_old% --L1 %svn_new_label% \      
+             --L2 "Custom Label" '                          
+        Other constructs possible are:                         
+        +%svn_new%, %svn_new%- and +++%svn_new_label%+++       
 
 
 Structure of the feature:

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c?rev=1533721&r1=1533720&r2=1533721&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/libsvn_subr/io.c Sat Oct 19 09:24:59 2013
@@ -3050,15 +3050,23 @@ __create_custom_diff_cmd(const char *lab
   {
     const char *delimiter;
     const char *replace;
-  } tokens_tab[] = { 
-    { ";l1", label1 },
-    { ";l2", label2 },
-    { ";l3", label3 },
-    { ";f1", from },  
-    { ";f2", to },    
-    { ";f3", base },    
+  } tokens_tab[] = {  /* Diff terminology */
+    { "%svn_old_label%", label1 },
+    { "%svn_new_label%", label2 },
+    { "%svn_base_label%", label3 },
+    { "%svn_old%", from },  
+    { "%svn_new%", to },    
+    { "%svn_base%", base },    
     { NULL, NULL }
   };
+ 
+  if (label3) /* Merge terminology */
+    {
+      tokens_tab[0].delimiter = "%svn_from_label%";
+      tokens_tab[1].delimiter = "%svn_to_label%";
+      tokens_tab[3].delimiter = "%svn_from%";
+      tokens_tab[4].delimiter = "%svn_to%";
+    }
 
   words = svn_cstring_split(cmd, " ", TRUE, scratch_pool);
 
@@ -3099,24 +3107,15 @@ __create_custom_diff_cmd(const char *lab
       for (i = 0; i < delimiters; i++)
         {
           char *found = strstr(word->data, tokens_tab[i].delimiter);
-          int len;
 
           if (!found)
             continue;
             
-          len = word->len - strlen(found) - 1;
-            
-          /* if we find a protective semi-colon in front of this, consume it */
-          if ( (len >= 0) && (word->data[len] == ';') )
-            svn_stringbuf_remove(word, len, 1);
-          else
-            {
-              svn_stringbuf_replace(word, found - word->data,
-                                    strlen(tokens_tab[i].delimiter),
-                                    tokens_tab[i].replace,
-                                    strlen(tokens_tab[i].replace));
-              i = delimiters;
-            }
+          svn_stringbuf_replace(word, found - word->data,
+                                strlen(tokens_tab[i].delimiter),
+                                tokens_tab[i].replace,
+                                strlen(tokens_tab[i].replace));
+          i = delimiters;
         }
       result[argv] = word->data;
     }  
@@ -3140,17 +3139,19 @@ svn_io_run_external_diff(const char *dir
   int exitcode;
   const char ** cmd;
 
+  apr_pool_t *scratch_pool = svn_pool_create(pool); 
+
   if (0 == strlen(external_diff_cmd)) 
      return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL, NULL);
 
   cmd = __create_custom_diff_cmd(label1, label2, NULL, 
                                  tmpfile1, tmpfile2, NULL, 
-                                 external_diff_cmd, pool);
+                                 external_diff_cmd, scratch_pool);
   if (pexitcode == NULL)
      pexitcode = &exitcode;
   
   SVN_ERR(svn_io_run_cmd(dir, cmd[0], cmd, pexitcode, NULL, TRUE,
-                         NULL, outfile, errfile, pool));
+                         NULL, outfile, errfile, scratch_pool));
   
   /* The man page for (GNU) diff describes the return value as:
 
@@ -3170,13 +3171,15 @@ svn_io_run_external_diff(const char *dir
       for (i = 0; cmd[i]; ++i)
           failed_command = apr_pstrcat(pool, failed_command, 
                                        cmd[i], " ", (char*) NULL);
-
+      svn_pool_destroy(scratch_pool);
       return svn_error_createf(SVN_ERR_EXTERNAL_PROGRAM, NULL,
                                _("'%s' was expanded to '%s' and returned %d"),
                                external_diff_cmd,
                                failed_command,
                                *pexitcode);
     }
+  else
+    svn_pool_destroy(scratch_pool);
   return SVN_NO_ERROR;
 }
 
@@ -3186,8 +3189,8 @@ svn_io_run_diff2(const char *dir,
                  int num_user_args,
                  const char *label1,
                  const char *label2,
-                 const char *from,
-                 const char *to,
+                 const char *old,
+                 const char *new,
                  int *pexitcode,
                  apr_file_t *outfile,
                  apr_file_t *errfile,
@@ -3216,18 +3219,18 @@ svn_io_run_diff2(const char *dir,
     svn_stringbuf_appendcstr(com, "-u "); 
 
   if (label1 != NULL)
-    svn_stringbuf_appendcstr(com,"-L ;l1 ");
+    svn_stringbuf_appendcstr(com,"-L %svn_old_label% ");
 
   if (label2 != NULL)
-    svn_stringbuf_appendcstr(com,"-L ;l2 ");
+    svn_stringbuf_appendcstr(com,"-L %svn_new_label% ");
 
-  svn_stringbuf_appendcstr(com,";f1 ;f2 "); 
+  svn_stringbuf_appendcstr(com,"%svn_old% %svn_new%"); 
 
   return svn_io_run_external_diff(dir,
                                   label1,
                                   label2,
-                                  from,
-                                  to,
+                                  old,
+                                  new,
                                   pexitcode,
                                   outfile,
                                   errfile,

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svn/svn.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svn/svn.c?rev=1533721&r1=1533720&r2=1533721&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svn/svn.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svn/svn.c Sat Oct 19 09:24:59 2013
@@ -345,34 +345,32 @@ const apr_getopt_option_t svn_cl__option
   {"diff", opt_diff, 0, N_("produce diff output")}, /* maps to show_diff */
   /* diff options */
   {"diff-cmd",      opt_diff_cmd, 1, N_("use ARG as diff command")},
-  {"invoke-diff-cmd",      opt_invoke_diff_cmd, 1, 
-                   N_("use ARG as format string for external diff command\n"
+  {"invoke-diff-cmd", opt_invoke_diff_cmd, 1, 
+                   N_("use ARG as format string for external diff command     \n"
                       "                             "
                       "invocation. \n                                         \n" 
                       "                             "
-                      "Substitutions: ;f1 original file                       \n"
+                      "Substitutions: %svn_new% new file                      \n"
                       "                             "
-                      "               ;f2 changed file                        \n"
+                      "               %svn_old% old file                      \n"
                       "                             "
-                      "               ;l1 label of the original file          \n"
+                      "               %svn_new_label%  label of the new file  \n"
                       "                             "
-                      "               ;l2 label of the changed file           \n"
+                      "               %svn_old_label%  label of the old file  \n"
                       "                             "
-                      "Examples: --invoke-diff-cmd=\"diff -y ;f1 ;f2\"        \n"          
+                      "Examples:                                              \n"
                       "                             "
-                      "   --invoke-diff-cmd=\"kdiff3 -auto -o /home/u/log \\  \n"
+                      "--invoke-diff-cmd=\'diff -y %svn_new% %svn_old%\'      \n"          
                       "                             "
-                      "     +;f1 ;l2 --L1 ;l1 --L2 \"Custom Label\" \"        \n"
+                      "--invoke-diff-cmd=\"kdiff3 -auto -o /home/u/log \\     \n"
                       "                             "
-                      "The delimiter ';' can be escaped by adding a ';', which\n"
+                      "      %svn_new% %svn_old% --L1 %svn_new_label% \\      \n"
                       "                             "
-                      "will be consumed in the process.  The delimiter can    \n"
+                      "     --L2 \"Custom Label\" \'                          \n"
                       "                             "
-                      "appear anywhere in the string, ie, file=;f1 will expand\n"
+                      "Other constructs possible are:                         \n"
                       "                             "
-                      "as expected and file=;;f1+ will be rendered as         \n"
-                      "                             "
-                      "file=;f1+.\n"
+                      "+%svn_new%, %svn_new%- and +++%svn_new_label%+++       \n"
      )},
   {"internal-diff", opt_internal_diff, 0,
                        N_("override diff-cmd specified in config file")},

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/tests/cmdline/diff_tests.py
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/tests/cmdline/diff_tests.py?rev=1533721&r1=1533720&r2=1533721&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/tests/cmdline/diff_tests.py (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/tests/cmdline/diff_tests.py Sat Oct 19 09:24:59 2013
@@ -3282,32 +3282,30 @@ def diff_invoke_external_diffcmd(sbox):
   expected_output = svntest.verify.ExpectedOutput([
       "Index: iota\n",
       "===================================================================\n",
-      # correct label ;l1 -> label 1
+      # correct label %svn_old_label% -> label 1
       "iota	(revision 1)\n",   
 
-      # correct file ;f1 -> file1
+      # correct file %svn_old% -> old
       os.path.abspath(svntest.wc.text_base_path("iota")) + "\n",
 
-      # correct label ;l2 -> label 2
+      # correct label %svn_new_label% -> label 2
       "iota	(working copy)\n",
 
-      # correct file ;f2 -> file2
+      # correct file %svn_new% -> new
       os.path.abspath("iota") + "\n",
 
       # preservation of quoted string  "X Y Z"-> "X Y Z"
       "\"X Y Z\"\n",
 
-      # correct insertion of filename into string "+;f2+" -> "+" + file2 + "+"
+      # correct insertion of filename into string "+%svn_new%+" -> "+" + new + "+"
       "+" + os.path.abspath("iota") + "+\n",
 
-      # removal of protective ';' ";;f1" -> ";f1"
-      ";f1\n",
       ])
   
   svntest.actions.run_and_verify_svn(None, expected_output, [],
    'diff',
    '--invoke-diff-cmd='+diff_script_path+
-   ' ;l1 ;f1 ;l2 ;f2 \"X Y Z\" +;f2+ ;;f1',
+   ' %svn_old_label% %svn_old% %svn_new_label% %svn_new% \"X Y Z\" +%svn_new%+',
   iota_path)