subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@apache.org
Subject svn commit: r1591750 - in /subversion/trunk: subversion/include/svn_diff.h tools/diff/diff3.c
Date Thu, 01 May 2014 19:29:37 GMT
Author: philip
Date: Thu May  1 19:29:37 2014
New Revision: 1591750

URL: http://svn.apache.org/r1591750
Log:
Add --conflict-style to standalone tools/diff/diff3.

* tools/diff/diff3.c
  (do_diff3): Add conflict style parameter.
  (main): Make argv const, add option parsing, add token map, clear error,
   pass conflict style, extend usage text.

* subversion/include/svn_diff.h
  (enum svn_diff_conflict_display_style_t): Add maintenance comment.

Modified:
    subversion/trunk/subversion/include/svn_diff.h
    subversion/trunk/tools/diff/diff3.c

Modified: subversion/trunk/subversion/include/svn_diff.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_diff.h?rev=1591750&r1=1591749&r2=1591750&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_diff.h (original)
+++ subversion/trunk/subversion/include/svn_diff.h Thu May  1 19:29:37 2014
@@ -402,6 +402,9 @@ typedef enum svn_diff_conflict_display_s
   /** Like svn_diff_conflict_display_modified_original_latest, but
       *only* showing conflicts. */
   svn_diff_conflict_display_only_conflicts
+
+  /* IMPORTANT: If you extend this enum note that it is mapped in
+     tools/diff/diff3.c. */
 } svn_diff_conflict_display_style_t;
 
 

Modified: subversion/trunk/tools/diff/diff3.c
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/diff/diff3.c?rev=1591750&r1=1591749&r2=1591750&view=diff
==============================================================================
--- subversion/trunk/tools/diff/diff3.c (original)
+++ subversion/trunk/tools/diff/diff3.c Thu May  1 19:29:37 2014
@@ -28,11 +28,14 @@
 #include "svn_pools.h"
 #include "svn_diff.h"
 #include "svn_io.h"
+#include "svn_opt.h"
+#include "private/svn_token.h"
 
 
 static svn_error_t *
 do_diff3(svn_stream_t *ostream,
          const char *original, const char *modified, const char *latest,
+         svn_diff_conflict_display_style_t conflict_style,
          svn_boolean_t *has_changes,
          apr_pool_t *pool)
 {
@@ -46,35 +49,89 @@ do_diff3(svn_stream_t *ostream,
   SVN_ERR(svn_diff_file_output_merge2(ostream, diff,
                                       original, modified, latest,
                                       NULL, NULL, NULL, NULL,
-                                      svn_diff_conflict_display_modified_latest,
+                                      conflict_style,
                                       pool));
 
   return NULL;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
   apr_pool_t *pool;
   svn_stream_t *ostream;
   int rc;
-  svn_error_t *svn_err;
+  svn_error_t *svn_err = SVN_NO_ERROR;
+  apr_getopt_t *opts;
+  enum {
+    conflict_style_opt = SVN_OPT_FIRST_LONGOPT_ID
+  };
+  static const apr_getopt_option_t options[] = {
+    {"conflict-style", conflict_style_opt, 1, ""},
+    {NULL, 0, 0, NULL}
+  };
+  svn_diff_conflict_display_style_t conflict_style
+    = svn_diff_conflict_display_modified_latest;
+  const svn_token_map_t style_map[] = {
+    { "modified-latest",
+      svn_diff_conflict_display_modified_latest },
+    { "resolved-modified-latest",
+      svn_diff_conflict_display_resolved_modified_latest },
+    { "modified-original-latest",
+      svn_diff_conflict_display_modified_original_latest },
+    { "modified",
+      svn_diff_conflict_display_modified },
+    { "latest",
+      svn_diff_conflict_display_latest },
+    { "only-conflicts",
+      svn_diff_conflict_display_only_conflicts },
+    {NULL, 0}
+  };
 
   apr_initialize();
 
   pool = svn_pool_create(NULL);
 
-  svn_err = svn_stream_for_stdout(&ostream, pool);
+  apr_getopt_init(&opts, pool, argc, argv);
+  opts->interleave = 1;
+  while (!svn_err)
+    {
+      int opt;
+      const char *arg;
+      apr_status_t status = apr_getopt_long(opts, options, &opt, &arg);
+
+      if (APR_STATUS_IS_EOF(status))
+        break;
+      if (status != APR_SUCCESS)
+        {
+          svn_err = svn_error_wrap_apr(status, "getopt failure");
+          break;
+        }
+      switch (opt)
+        {
+        case conflict_style_opt:
+          {
+            int val;
+            svn_err = svn_token__from_word_err(&val, style_map, arg);
+            conflict_style = val;
+            break;
+          }
+        }
+    }
+
+  if (!svn_err)
+    svn_err = svn_stream_for_stdout(&ostream, pool);
   if (svn_err)
     {
       svn_handle_error2(svn_err, stdout, FALSE, "diff3: ");
+      svn_error_clear(svn_err);
       rc = 2;
     }
-  else if (argc == 4)
+  else if (argc - opts->ind == 3)
     {
       svn_boolean_t has_changes;
 
-      svn_err = do_diff3(ostream, argv[2], argv[1], argv[3],
-                         &has_changes, pool);
+      svn_err = do_diff3(ostream, argv[argc-2], argv[argc-3], argv[argc-1],
+                         conflict_style, &has_changes, pool);
       if (svn_err == NULL)
         {
           rc = has_changes ? 1 : 0;
@@ -88,8 +145,29 @@ int main(int argc, char *argv[])
   else
     {
       svn_error_clear(svn_stream_printf(ostream, pool,
-                                        "Usage: %s <mine> <older> <yours>\n",
-                                        argv[0]));
+        "Usage: %s [options] <mine> <older> <yours>\n"
+        "Options:\n"
+        "  --conflict-style STYLE\n"
+        "  where STYLE can be:\n"
+        "    %s\n"
+        "    %s\n"
+        "    %s\n"
+        "    %s\n"
+        "    %s\n"
+        "    %s\n",
+        argv[0],
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_modified_latest),
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_resolved_modified_latest),
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_modified_original_latest),
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_modified),
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_latest),
+        svn_token__to_word(style_map,
+                           svn_diff_conflict_display_only_conflicts)));
       rc = 2;
     }
 



Mime
View raw message