Author: julianfoad
Date: Fri Mar 23 18:08:36 2018
New Revision: 1827590

URL: http://svn.apache.org/viewvc?rev=1827590&view=rev
Log:
Minor refactoring.

* subversion/libsvn_client/diff.c
  (diff_driver_info_t): Move higher up the file. Move 'wc_ctx' into here...
  (diff_writer_info_t): ... from here.
  (print_git_diff_header): Calculate repos-relpaths inside here...
  (display_prop_diffs,
   diff_content_changed): ... instead of in these callers.
  (diff_props_changed,
   get_diff_processor): Adjust.

Modified:
    subversion/trunk/subversion/libsvn_client/diff.c

Modified: subversion/trunk/subversion/libsvn_client/diff.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/diff.c?rev=1827590&r1=1827589&r2=1827590&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/diff.c (original)
+++ subversion/trunk/subversion/libsvn_client/diff.c Fri Mar 23 18:08:36 2018
@@ -66,6 +66,26 @@
                           _("Path '%s' must be an immediate child of " \
                             "the directory '%s'"), path, relative_to_dir)
 
+/* State provided by the diff drivers; used by the diff writer */
+typedef struct diff_driver_info_t
+{
+  /* The anchor to prefix before wc paths */
+  const char *anchor;
+
+   /* Relative path of ra session from repos_root_url */
+  const char *session_relpath;
+
+  svn_wc_context_t *wc_ctx;
+
+  /* The original targets passed to the diff command.  We may need
+     these to construct distinctive diff labels when comparing the
+     same relative path in the same revision, under different anchors
+     (for example, when comparing a trunk against a branch). */
+  const char *orig_path_1;
+  const char *orig_path_2;
+} diff_driver_info_t;
+
+
 /* Calculate the repository relative path of DIFF_RELPATH, using
  * SESSION_RELPATH and WC_CTX, and return the result in *REPOS_RELPATH.
  * ORIG_TARGET is the related original target passed to the diff command,
@@ -383,28 +403,33 @@ maybe_print_mode_change(svn_stream_t *os
 }
 
 /* Print a git diff header showing the OPERATION to the stream OS using
- * HEADER_ENCODING. Return suitable diff labels for the git diff in *LABEL1
- * and *LABEL2. REPOS_RELPATH1 and REPOS_RELPATH2 are relative to reposroot.
- * are the paths passed to the original diff command. REV1 and REV2 are
- * revisions being diffed. COPYFROM_PATH and COPYFROM_REV indicate where the
+ * HEADER_ENCODING.
+ *
+ * Return suitable diff labels for the git diff in *LABEL1 and *LABEL2.
+ *
+ * REV1 and REV2 are the revisions being diffed.
+ * COPYFROM_PATH and COPYFROM_REV indicate where the
  * diffed item was copied from.
  * Use SCRATCH_POOL for temporary allocations. */
 static svn_error_t *
 print_git_diff_header(svn_stream_t *os,
                       const char **label1, const char **label2,
                       svn_diff_operation_kind_t operation,
-                      const char *repos_relpath1,
-                      const char *repos_relpath2,
                       svn_revnum_t rev1,
                       svn_revnum_t rev2,
+                      const char *diff_relpath,
                       const char *copyfrom_path,
                       svn_revnum_t copyfrom_rev,
                       apr_hash_t *left_props,
                       apr_hash_t *right_props,
                       const char *git_index_shas,
                       const char *header_encoding,
+                      const diff_driver_info_t *ddi,
                       apr_pool_t *scratch_pool)
 {
+  const char *repos_relpath1;
+  const char *repos_relpath2;
+  const char *copyfrom_repos_relpath = NULL;
   svn_boolean_t exec_bit1 = (svn_prop_get_value(left_props,
                                                 SVN_PROP_EXECUTABLE) != NULL);
   svn_boolean_t exec_bit2 = (svn_prop_get_value(right_props,
@@ -414,6 +439,26 @@ print_git_diff_header(svn_stream_t *os,
   svn_boolean_t symlink_bit2 = (svn_prop_get_value(right_props,
                                                    SVN_PROP_SPECIAL) != NULL);
 
+  SVN_ERR(make_repos_relpath(&repos_relpath1, diff_relpath,
+                             ddi->orig_path_1,
+                             ddi->session_relpath,
+                             ddi->wc_ctx,
+                             ddi->anchor,
+                             scratch_pool, scratch_pool));
+  SVN_ERR(make_repos_relpath(&repos_relpath2, diff_relpath,
+                             ddi->orig_path_2,
+                             ddi->session_relpath,
+                             ddi->wc_ctx,
+                             ddi->anchor,
+                             scratch_pool, scratch_pool));
+  if (copyfrom_path)
+    SVN_ERR(make_repos_relpath(&copyfrom_repos_relpath, copyfrom_path,
+                               ddi->orig_path_2,
+                               ddi->session_relpath,
+                               ddi->wc_ctx,
+                               ddi->anchor,
+                               scratch_pool, scratch_pool));
+
   if (operation == svn_diff_op_deleted)
     {
       SVN_ERR(print_git_diff_header_deleted(os, header_encoding,
@@ -494,24 +539,20 @@ print_git_diff_header(svn_stream_t *os,
    ### FIXME needs proper docstring
 
    If USE_GIT_DIFF_FORMAT is TRUE, pring git diff headers, which always
-   show paths relative to the repository root. RA_SESSION and WC_CTX are
-   needed to normalize paths relative the repository root, and are ignored
-   if USE_GIT_DIFF_FORMAT is FALSE.
+   show paths relative to the repository root. DDI->session_relpath and
+   DDI->wc_ctx are needed to normalize paths relative the repository root,
+   and are ignored if USE_GIT_DIFF_FORMAT is FALSE.
 
    If @a pretty_print_mergeinfo is true, then describe 'svn:mergeinfo'
    property changes in a human-readable form that says what changes were
    merged or reverse merged; otherwise (or if the mergeinfo property values
    don't parse correctly) display them just like any other property.
-
-   ANCHOR is the local path where the diff editor is anchored. */
+ */
 static svn_error_t *
 display_prop_diffs(const apr_array_header_t *propchanges,
                    apr_hash_t *left_props,
                    apr_hash_t *right_props,
                    const char *diff_relpath,
-                   const char *anchor,
-                   const char *orig_path1,
-                   const char *orig_path2,
                    svn_revnum_t rev1,
                    svn_revnum_t rev2,
                    const char *encoding,
@@ -520,32 +561,27 @@ display_prop_diffs(const apr_array_heade
                    svn_boolean_t show_diff_header,
                    svn_boolean_t use_git_diff_format,
                    svn_boolean_t pretty_print_mergeinfo,
-                   const char *ra_session_relpath,
+                   const diff_driver_info_t *ddi,
                    svn_cancel_func_t cancel_func,
                    void *cancel_baton,
-                   svn_wc_context_t *wc_ctx,
                    apr_pool_t *scratch_pool)
 {
   const char *repos_relpath1 = NULL;
-  const char *repos_relpath2 = NULL;
   const char *index_path = diff_relpath;
-  const char *adjusted_path1 = orig_path1;
-  const char *adjusted_path2 = orig_path2;
+  const char *adjusted_path1 = ddi->orig_path_1;
+  const char *adjusted_path2 = ddi->orig_path_2;
 
   if (use_git_diff_format)
     {
-      SVN_ERR(make_repos_relpath(&repos_relpath1, diff_relpath, orig_path1,
-                                 ra_session_relpath, wc_ctx, anchor,
-                                 scratch_pool, scratch_pool));
-      SVN_ERR(make_repos_relpath(&repos_relpath2, diff_relpath, orig_path2,
-                                 ra_session_relpath, wc_ctx, anchor,
+      SVN_ERR(make_repos_relpath(&repos_relpath1, diff_relpath, 
ddi->orig_path_1,
+                                 ddi->session_relpath, ddi->wc_ctx, 
ddi->anchor,
                                  scratch_pool, scratch_pool));
     }
 
   /* If we're creating a diff on the wc root, path would be empty. */
   SVN_ERR(adjust_paths_for_diff_labels(&index_path, &adjusted_path1,
                                        &adjusted_path2,
-                                       relative_to_dir, anchor,
+                                       relative_to_dir, ddi->anchor,
                                        scratch_pool, scratch_pool));
 
   if (show_diff_header)
@@ -567,13 +603,12 @@ display_prop_diffs(const apr_array_heade
       if (use_git_diff_format)
         SVN_ERR(print_git_diff_header(outstream, &label1, &label2,
                                       svn_diff_op_modified,
-                                      repos_relpath1, repos_relpath2,
-                                      rev1, rev2, NULL,
-                                      SVN_INVALID_REVNUM,
-                                      left_props,
-                                      right_props,
+                                      rev1, rev2,
+                                      diff_relpath,
+                                      NULL, SVN_INVALID_REVNUM,
+                                      left_props, right_props,
                                       NULL,
-                                      encoding, scratch_pool));
+                                      encoding, ddi, scratch_pool));
 
       /* --- label1
        * +++ label2 */
@@ -605,24 +640,6 @@ display_prop_diffs(const apr_array_heade
 
 /*** Callbacks for 'svn diff', invoked by the repos-diff editor. ***/
 
-/* State provided by the diff drivers; used by the diff writer */
-typedef struct diff_driver_info_t
-{
-  /* The anchor to prefix before wc paths */
-  const char *anchor;
-
-   /* Relative path of ra session from repos_root_url */
-  const char *session_relpath;
-
-  /* The original targets passed to the diff command.  We may need
-     these to construct distinctive diff labels when comparing the
-     same relative path in the same revision, under different anchors
-     (for example, when comparing a trunk against a branch). */
-  const char *orig_path_1;
-  const char *orig_path_2;
-} diff_driver_info_t;
-
-
 /* Diff writer state */
 typedef struct diff_writer_info_t
 {
@@ -680,8 +697,6 @@ typedef struct diff_writer_info_t
   /* Empty files for creating diffs or NULL if not used yet */
   const char *empty_file;
 
-  svn_wc_context_t *wc_ctx;
-
   svn_cancel_func_t cancel_func;
   void *cancel_baton;
 
@@ -717,9 +732,6 @@ diff_props_changed(const char *diff_relp
        * dir_props_changed(). */
       SVN_ERR(display_prop_diffs(props, left_props, right_props,
                                  diff_relpath,
-                                 dwi->ddi.anchor,
-                                 dwi->ddi.orig_path_1,
-                                 dwi->ddi.orig_path_2,
                                  rev1,
                                  rev2,
                                  dwi->header_encoding,
@@ -728,10 +740,9 @@ diff_props_changed(const char *diff_relp
                                  show_diff_header,
                                  dwi->use_git_diff_format,
                                  dwi->pretty_print_mergeinfo,
-                                 dwi->ddi.session_relpath,
+                                 &dwi->ddi,
                                  dwi->cancel_func,
                                  dwi->cancel_baton,
-                                 dwi->wc_ctx,
                                  scratch_pool));
     }
 
@@ -896,40 +907,17 @@ diff_content_changed(svn_boolean_t *wrot
         {
           svn_stream_t *left_stream;
           svn_stream_t *right_stream;
-          const char *repos_relpath1;
-          const char *repos_relpath2;
-          const char *copyfrom_repos_relpath = NULL;
-
-          SVN_ERR(make_repos_relpath(&repos_relpath1, diff_relpath,
-                                      dwi->ddi.orig_path_1,
-                                      dwi->ddi.session_relpath,
-                                      dwi->wc_ctx,
-                                      dwi->ddi.anchor,
-                                      scratch_pool, scratch_pool));
-          SVN_ERR(make_repos_relpath(&repos_relpath2, diff_relpath,
-                                      dwi->ddi.orig_path_2,
-                                      dwi->ddi.session_relpath,
-                                      dwi->wc_ctx,
-                                      dwi->ddi.anchor,
-                                      scratch_pool, scratch_pool));
-          if (copyfrom_path)
-            SVN_ERR(make_repos_relpath(&copyfrom_repos_relpath, copyfrom_path,
-                                        dwi->ddi.orig_path_2,
-                                        dwi->ddi.session_relpath,
-                                        dwi->wc_ctx,
-                                        dwi->ddi.anchor,
-                                        scratch_pool, scratch_pool));
-          SVN_ERR(print_git_diff_header(outstream, &label1, &label2,
+
+          SVN_ERR(print_git_diff_header(outstream,
+                                        &label1, &label2,
                                         operation,
-                                        repos_relpath1, repos_relpath2,
                                         rev1, rev2,
-                                        copyfrom_repos_relpath,
-                                        copyfrom_rev,
-                                        left_props,
-                                        right_props,
+                                        diff_relpath,
+                                        copyfrom_path, copyfrom_rev,
+                                        left_props, right_props,
                                         index_shas,
                                         dwi->header_encoding,
-                                        scratch_pool));
+                                        &dwi->ddi, scratch_pool));
 
           SVN_ERR(svn_stream_open_readonly(&left_stream, tmpfile1,
                                            scratch_pool, scratch_pool));
@@ -1069,41 +1057,16 @@ diff_content_changed(svn_boolean_t *wrot
 
           if (dwi->use_git_diff_format)
             {
-              const char *repos_relpath1;
-              const char *repos_relpath2;
-              const char *copyfrom_repos_relpath = NULL;
-
-              SVN_ERR(make_repos_relpath(&repos_relpath1, diff_relpath,
-                                         dwi->ddi.orig_path_1,
-                                         dwi->ddi.session_relpath,
-                                         dwi->wc_ctx,
-                                         dwi->ddi.anchor,
-                                         scratch_pool, scratch_pool));
-              SVN_ERR(make_repos_relpath(&repos_relpath2, diff_relpath,
-                                         dwi->ddi.orig_path_2,
-                                         dwi->ddi.session_relpath,
-                                         dwi->wc_ctx,
-                                         dwi->ddi.anchor,
-                                         scratch_pool, scratch_pool));
-              if (copyfrom_path)
-                SVN_ERR(make_repos_relpath(&copyfrom_repos_relpath,
-                                           copyfrom_path,
-                                           dwi->ddi.orig_path_2,
-                                           dwi->ddi.session_relpath,
-                                           dwi->wc_ctx,
-                                           dwi->ddi.anchor,
-                                           scratch_pool, scratch_pool));
-              SVN_ERR(print_git_diff_header(outstream, &label1, &label2,
+              SVN_ERR(print_git_diff_header(outstream,
+                                            &label1, &label2,
                                             operation,
-                                            repos_relpath1, repos_relpath2,
                                             rev1, rev2,
-                                            copyfrom_repos_relpath,
-                                            copyfrom_rev,
-                                            left_props,
-                                            right_props,
+                                            diff_relpath,
+                                            copyfrom_path, copyfrom_rev,
+                                            left_props, right_props,
                                             index_shas,
                                             dwi->header_encoding,
-                                            scratch_pool));
+                                            &dwi->ddi, scratch_pool));
             }
 
           /* Output the actual diff */
@@ -2547,7 +2510,7 @@ get_diff_processor(svn_diff_tree_process
   dwi->cancel_func = ctx->cancel_func;
   dwi->cancel_baton = ctx->cancel_baton;
 
-  dwi->wc_ctx = ctx->wc_ctx;
+  dwi->ddi.wc_ctx = ctx->wc_ctx;
   dwi->ddi.session_relpath = NULL;
   dwi->ddi.anchor = NULL;
 


Reply via email to