You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2010/06/29 10:49:59 UTC

svn commit: r958881 - in /subversion/trunk/subversion: include/svn_client.h libsvn_client/deprecated.c libsvn_client/diff.c svn/cl.h svn/diff-cmd.c svn/log-cmd.c svn/main.c

Author: dannas
Date: Tue Jun 29 08:49:58 2010
New Revision: 958881

URL: http://svn.apache.org/viewvc?rev=958881&view=rev
Log:
Introduce a new flag --git-diff for svn diff, specifying that we want to use
git's extended diff format.

With the diff format, a delete, copy or move may be described with only a
header.  Non-git-aware patch applications can not process such a patch, thus
the need for a flag to stay backward compatible with our old diff format.

With the flag there is no need for the SVN_EXPERIMENTAL_PATCH ifdefs.

Note: We don't yet create diff headers for copied or moved paths.

* subversion/svn/cl.h
  (svn_cl__opt_state_t): Add USE_GIT_DIFF_FORMAT member.

* subversion/svn/main.c
  (svn_cl__longopt_t): Add OPT_USE_GIT_DIFF_FORMAT.
  (svn_cl__options): Add and document the new --git-diff option.
  (svn_cl__cmd_table): Make svn diff accept the --git-diff option.
  (main): Handle --git-diff options.

* subversion/include/svn_client.h
  (svn_client_diff5,
   svn_client_diff_peg5): Add USE_GIT_DIFF_FORMAT parameter.
  (svn_client_diff4,
   svn_client_diff_peg4): Mention in the doc string that 
    USE_GIT_DIFF_FORMAT defaults to FALSE.

* subversion/libsvn_client/diff.c
  (diff_parameters): Add USE_GIT_DIFF_FORMAT member.
  (print_git_diff_header_added,
   print_git_diff_header_modified,
   print_git_diff_header_deleted,
   print_git_diff_header_copied,
   print_git_diff_header_moved):  Remove SVN_EXPERIMENTAL_PATCH ifdefs
  (diff_content_changed): Check for USE_GIT_DIFF_FORMAT instead of
    having the parts dealing with git diffs inside SVN_EXPERIMENTAL 
    ifdefs.
  (svn_client_diff5,
   svn_client_diff_peg5): TODO

* subversion/libsvn_client/deprecated.c
  (svn_client_diff4,
   svn_client_diff_peg4): Call the new functions with USE_GIT_DIFF_FORMAT
    set to FALSE.

* subversion/svn/diff-cmd.c
  (svn_cl__diff): Adjust calls to include USE_GIT_DIFF_FORMAT.

* subversion/svn/log-cmd.c
  (log_entry_reciever): Adjust callers of svn_client_diff5() and 
    svn_client_diff_peg5().

Modified:
    subversion/trunk/subversion/include/svn_client.h
    subversion/trunk/subversion/libsvn_client/deprecated.c
    subversion/trunk/subversion/libsvn_client/diff.c
    subversion/trunk/subversion/svn/cl.h
    subversion/trunk/subversion/svn/diff-cmd.c
    subversion/trunk/subversion/svn/log-cmd.c
    subversion/trunk/subversion/svn/main.c

Modified: subversion/trunk/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_client.h?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_client.h (original)
+++ subversion/trunk/subversion/include/svn_client.h Tue Jun 29 08:49:58 2010
@@ -2524,6 +2524,10 @@ svn_client_blame(const char *path_or_url
  * against their copyfrom source, and will appear in the diff output
  * in their entirety, as if they were newly added.
  *
+ * If @a use_git_diff_format is TRUE, then the git's extended diff format
+ * will be used.
+ * ### Do we need to say more about the format? A reference perhaps?
+ *
  * Generated headers are encoded using @a header_encoding.
  *
  * Diff output will not be generated for binary files, unless @a
@@ -2568,6 +2572,7 @@ svn_client_diff5(const apr_array_header_
                  svn_boolean_t no_diff_deleted,
                  svn_boolean_t show_copies_as_adds,
                  svn_boolean_t ignore_content_type,
+                 svn_boolean_t use_git_diff_format,
                  const char *header_encoding,
                  apr_file_t *outfile,
                  apr_file_t *errfile,
@@ -2577,7 +2582,7 @@ svn_client_diff5(const apr_array_header_
 
 /**
  * Similar to svn_client_diff5(), but with @a show_copies_as_adds set to
- * @c FALSE.
+ * @c FALSE and @a use_git_diff_format set to @c FALSE.
  *
  * @deprecated Provided for backward compatibility with the 1.6 API.
  *
@@ -2701,6 +2706,7 @@ svn_client_diff_peg5(const apr_array_hea
                      svn_boolean_t no_diff_deleted,
                      svn_boolean_t show_copies_as_adds,
                      svn_boolean_t ignore_content_type,
+                     svn_boolean_t use_git_diff_format,
                      const char *header_encoding,
                      apr_file_t *outfile,
                      apr_file_t *errfile,
@@ -2710,7 +2716,7 @@ svn_client_diff_peg5(const apr_array_hea
 
 /**
  * Similar to svn_client_diff_peg5(), but with @a show_copies_as_adds set to
- * @c FALSE.
+ * @c FALSE and @a use_git_diff_format set to @c FALSE.
  *
  * @since New in 1.5.
  */

Modified: subversion/trunk/subversion/libsvn_client/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/deprecated.c?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_client/deprecated.c Tue Jun 29 08:49:58 2010
@@ -640,7 +640,7 @@ svn_client_diff4(const apr_array_header_
   return svn_client_diff5(options, path1, revision1, path2,
                           revision2, relative_to_dir, depth,
                           ignore_ancestry, no_diff_deleted, FALSE,
-                          ignore_content_type, header_encoding,
+                          FALSE, ignore_content_type, header_encoding,
                           outfile, errfile, changelists, ctx, pool);
 }
 
@@ -736,6 +736,7 @@ svn_client_diff_peg4(const apr_array_hea
                               ignore_ancestry,
                               no_diff_deleted,
                               FALSE,
+                              FALSE,
                               ignore_content_type,
                               header_encoding,
                               outfile,

Modified: subversion/trunk/subversion/libsvn_client/diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/diff.c?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/diff.c (original)
+++ subversion/trunk/subversion/libsvn_client/diff.c Tue Jun 29 08:49:58 2010
@@ -306,7 +306,6 @@ display_prop_diffs(const apr_array_heade
   return SVN_NO_ERROR;
 }
 
-#ifdef SVN_EXPERIMENTAL_PATCH
 
 /*
  * Print a git diff header for PATH to the stream OS using HEADER_ENCODING.
@@ -391,7 +390,6 @@ print_git_diff_header_modified(svn_strea
                                       path, path, APR_EOL_STR));
   return SVN_NO_ERROR;
 }
-#endif
 
 /*-----------------------------------------------------------------*/
 
@@ -451,6 +449,8 @@ struct diff_cmd_baton {
   /* The directory that diff target paths should be considered as
      relative to for output generation (see issue #2723). */
   const char *relative_to_dir;
+
+  svn_boolean_t use_git_diff_format;
 };
 
 /* Generate a label for the diff output for file PATH at revision REVNUM.
@@ -694,47 +694,50 @@ diff_content_changed(const char *path,
                   (os, diff_cmd_baton->header_encoding, subpool,
                    "Index: %s" APR_EOL_STR "%s" APR_EOL_STR,
                    path, equal_string));
-#ifdef SVN_EXPERIMENTAL_PATCH
 
-          /* Add git headers and adjust the labels. 
-           * ### Once we're using the git format everywhere, we can create
-           * ### one func that sets the correct labels in one place. */
-          if (operation == svn_diff_op_deleted)
+          if (diff_cmd_baton->use_git_diff_format)
             {
-              SVN_ERR(print_git_diff_header_deleted(
-                                            os, 
-                                            diff_cmd_baton->header_encoding,
-                                            path, subpool));
-              svn_pool_destroy(subpool);
 
-              /* We only display the git diff header for deletes. */
-              return SVN_NO_ERROR;
+            /* Add git headers and adjust the labels. 
+             * ### Once we're using the git format everywhere, we can create
+             * ### one func that sets the correct labels in one place. */
+            if (operation == svn_diff_op_deleted)
+              {
+                SVN_ERR(print_git_diff_header_deleted(
+                                              os, 
+                                              diff_cmd_baton->header_encoding,
+                                              path, subpool));
+                svn_pool_destroy(subpool);
+
+                /* We only display the git diff header for deletes. */
+                return SVN_NO_ERROR;
+
+              }
+            else if (operation == svn_diff_op_added)
+              {
+                SVN_ERR(print_git_diff_header_added(
+                                              os, 
+                                              diff_cmd_baton->header_encoding,
+                                              path, subpool));
+                label1 = diff_label("/dev/null", rev1, subpool);
+                label2 = diff_label(apr_psprintf(subpool, "b/%s", path2), rev2,
+                                    subpool);
+              }
+            else if (operation == svn_diff_op_modified)
+              {
+                SVN_ERR(print_git_diff_header_modified(
+                                              os, 
+                                              diff_cmd_baton->header_encoding,
+                                              path, subpool));
+                label1 = diff_label(apr_psprintf(subpool, "a/%s", path1), rev1,
+                                    subpool);
+                label2 = diff_label(apr_psprintf(subpool, "b/%s", path2), rev2,
+                                    subpool);
+              }
 
-            }
-          else if (operation == svn_diff_op_added)
-            {
-              SVN_ERR(print_git_diff_header_added(
-                                            os, 
-                                            diff_cmd_baton->header_encoding,
-                                            path, subpool));
-              label1 = diff_label("/dev/null", rev1, subpool);
-              label2 = diff_label(apr_psprintf(subpool, "b/%s", path2), rev2,
-                                  subpool);
-            }
-          else if (operation == svn_diff_op_modified)
-            {
-              SVN_ERR(print_git_diff_header_modified(
-                                            os, 
-                                            diff_cmd_baton->header_encoding,
-                                            path, subpool));
-              label1 = diff_label(apr_psprintf(subpool, "a/%s", path1), rev1,
-                                  subpool);
-              label2 = diff_label(apr_psprintf(subpool, "b/%s", path2), rev2,
-                                  subpool);
-            }
+            /* ### Print git headers for copies and renames too. */
+          }
 
-          /* ### Print git headers for copies and renames too. */
-#endif
           /* Output the actual diff */
           SVN_ERR(svn_diff_file_output_unified3
                   (os, diff, tmpfile1, tmpfile2, label1, label2,
@@ -1855,6 +1858,7 @@ svn_client_diff5(const apr_array_header_
                  svn_boolean_t no_diff_deleted,
                  svn_boolean_t show_copies_as_adds,
                  svn_boolean_t ignore_content_type,
+                 svn_boolean_t use_git_diff_format,
                  const char *header_encoding,
                  apr_file_t *outfile,
                  apr_file_t *errfile,
@@ -1909,6 +1913,7 @@ svn_client_diff5(const apr_array_header_
   diff_cmd_baton.force_empty = FALSE;
   diff_cmd_baton.force_binary = ignore_content_type;
   diff_cmd_baton.relative_to_dir = relative_to_dir;
+  diff_cmd_baton.use_git_diff_format = use_git_diff_format;
 
   return do_diff(&diff_params, &diff_callbacks, &diff_cmd_baton, ctx, pool);
 }
@@ -1925,6 +1930,7 @@ svn_client_diff_peg5(const apr_array_hea
                      svn_boolean_t no_diff_deleted,
                      svn_boolean_t show_copies_as_adds,
                      svn_boolean_t ignore_content_type,
+                     svn_boolean_t use_git_diff_format,
                      const char *header_encoding,
                      apr_file_t *outfile,
                      apr_file_t *errfile,
@@ -1975,6 +1981,7 @@ svn_client_diff_peg5(const apr_array_hea
   diff_cmd_baton.force_empty = FALSE;
   diff_cmd_baton.force_binary = ignore_content_type;
   diff_cmd_baton.relative_to_dir = relative_to_dir;
+  diff_cmd_baton.use_git_diff_format = use_git_diff_format;
 
   return do_diff(&diff_params, &diff_callbacks, &diff_cmd_baton, ctx, pool);
 }

Modified: subversion/trunk/subversion/svn/cl.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/cl.h?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/cl.h (original)
+++ subversion/trunk/subversion/svn/cl.h Tue Jun 29 08:49:58 2010
@@ -228,6 +228,7 @@ typedef struct svn_cl__opt_state_t
                                       patching */
   svn_boolean_t show_diff;        /* produce diff output */
   svn_boolean_t internal_diff;    /* override diff_cmd in config file */
+  svn_boolean_t use_git_diff_format; /* Use git's extended diff format */
 } svn_cl__opt_state_t;
 
 

Modified: subversion/trunk/subversion/svn/diff-cmd.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/diff-cmd.c?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/diff-cmd.c (original)
+++ subversion/trunk/subversion/svn/diff-cmd.c Tue Jun 29 08:49:58 2010
@@ -349,6 +349,7 @@ svn_cl__diff(apr_getopt_t *os,
                      opt_state->no_diff_deleted,
                      opt_state->show_copies_as_adds,
                      opt_state->force,
+                     opt_state->use_git_diff_format,
                      svn_cmdline_output_encoding(pool),
                      outfile,
                      errfile,
@@ -393,6 +394,7 @@ svn_cl__diff(apr_getopt_t *os,
                      opt_state->no_diff_deleted,
                      opt_state->show_copies_as_adds,
                      opt_state->force,
+                     opt_state->use_git_diff_format,
                      svn_cmdline_output_encoding(pool),
                      outfile,
                      errfile,

Modified: subversion/trunk/subversion/svn/log-cmd.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/log-cmd.c?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/log-cmd.c (original)
+++ subversion/trunk/subversion/svn/log-cmd.c Tue Jun 29 08:49:58 2010
@@ -305,6 +305,7 @@ log_entry_receiver(void *baton,
                              TRUE, /* no diff deleted */
                              FALSE, /* show copies as adds */
                              FALSE, /* ignore content type */
+                             FALSE, /* use git diff format */
                              svn_cmdline_output_encoding(pool),
                              outfile,
                              errfile,
@@ -337,6 +338,7 @@ log_entry_receiver(void *baton,
                                          TRUE, /* no diff deleted */
                                          FALSE, /* show copies as adds */
                                          FALSE, /* ignore content type */
+                                         FALSE, /* use git diff format */
                                          svn_cmdline_output_encoding(iterpool),
                                          outfile,
                                          errfile,

Modified: subversion/trunk/subversion/svn/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/main.c?rev=958881&r1=958880&r2=958881&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/main.c (original)
+++ subversion/trunk/subversion/svn/main.c Tue Jun 29 08:49:58 2010
@@ -121,6 +121,7 @@ typedef enum {
   opt_ignore_whitespace,
   opt_show_diff,
   opt_internal_diff,
+  opt_use_git_diff_format,
 } svn_cl__longopt_t;
 
 /* Option codes and descriptions for the command line client.
@@ -367,6 +368,9 @@ const apr_getopt_option_t svn_cl__option
                        N_("override diff-cmd specified in config file\n"
                        "                             "
                        "[alias: --idiff]")},
+  {"git-diff", opt_use_git_diff_format, 0,
+                       N_("use git's extended diff format\n")},
+                  
   /* Long-opt Aliases
    *
    * These have NULL desriptions, but an option code that matches some
@@ -571,7 +575,8 @@ const svn_opt_subcommand_desc2_t svn_cl_
      "  Use just 'svn diff' to display local modifications in a working copy.\n"),
     {'r', 'c', opt_old_cmd, opt_new_cmd, 'N', opt_depth, opt_diff_cmd,
      opt_internal_diff, 'x', opt_no_diff_deleted, opt_show_copies_as_adds,
-     opt_notice_ancestry, opt_summarize, opt_changelist, opt_force, opt_xml} },
+     opt_notice_ancestry, opt_summarize, opt_changelist, opt_force, opt_xml,
+     opt_use_git_diff_format} },
   { "export", svn_cl__export, {0}, N_
     ("Create an unversioned copy of a tree.\n"
      "usage: 1. export [-r REV] URL[@PEGREV] [PATH]\n"
@@ -1764,6 +1769,8 @@ main(int argc, const char *argv[])
       case opt_internal_diff:
         opt_state.internal_diff = TRUE;
         break;
+      case opt_use_git_diff_format:
+        opt_state.use_git_diff_format = TRUE;
       default:
         /* Hmmm. Perhaps this would be a good place to squirrel away
            opts that commands like svn diff might need. Hmmm indeed. */