Here is a little dev toy for casual submitters and people who just
want to have a quick play with the svn source, or perhaps use svn as a framework to explore one of the API's that svn uses.

The patch sets up a new option for the svn diff command called
'InstantPlayground' and puts a function called
InstantPlaygroundFunction into subversion/libsvn_client/diff.c
together with all the parameters needed for playing with the svn
diff code.

It also demonstrates how to set up a command line option, so
people who want something different should easily be able to use
this as a guide, even if the patch eventually goes 'out of date'.

It's not meant for committing, but I thought that other people
might find this little tool as useful as I do, so here it is :)

To use it, apply the patch, then open diff.c and find the InstantPlaygroundFunction, where your code will go.

[[[

This is a demonstration patch that shows how to add a new sub command
to the svn command line structure for the diff command.

This is aimed at casual submitters or anyone who wants a quick
'ready-to-play' set-up to explore svn or to use svn as a framework
to to play with the API's svn uses.

To call your code from the command line, do:

  svn diff --InstantPlayground="your input here"

* subversion/include/svn_client.h (svn_client_diff6):
  Add the InstantPlayground char* parameter that contains the input
  string to the parameter list.

* subversion/libsvn_client/deprecated.c
  (svn_client_diff5): Add the InstantPlayground char* parameter to
  the call this deprecated function makes to svn_client_diff6.

  (InstantPlaygroundFunction): Your code goes here.  The parameter
  'diff_cmd_baton' contains everything that would be normally passed
  into the svn diff domain.

* subversion/libsvn_client/diff.c (diff_cmd_baton):
  Define the char* InstantPlayground variable within the
  diff_cmd_baton structure.

  (svn_client_diff6): Add the InstantPlayground char* parameter that
  contains the input string to the parameter list, assign it to
  diff_cmd_baton and reroute the call to the InstantPlaygroundFunction
  instead of do_diff).

* subversion/svn/cl.h (svn_cl__opt_state_t):
  Add the char* InstantPlayground field to the diff command structure
  contained within the svn diff command options.

* subversion/svn/diff-cmd.c
  (svn_cl__diff): Call svnclient_diff6 with the new parameter char *
  InstantPlayground added.

* subversion/svn/svn.c
  (svn_cl__longopt_t): Define the opt_InstantPlayground parameter to the
  long options list that do not have a short option.

  (svn_cl__options): This is the main list of svn command line options
  and we're adding the opt_InstantPlayground as a sub option to the
  diff group within.

  (svn_cl__cmd_table): Add opt_InstantPlayground to the list of diff
  sub options that can be called.

  (sub_main): Assign the input string passed on the command line to the
  opt_InstantPlayground variable.

]]]
Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h	(revision 1466727)
+++ subversion/include/svn_client.h	(working copy)
@@ -3031,8 +3031,9 @@ svn_client_diff6(const apr_array_header_t *diff_op
                  svn_stream_t *errstream,
                  const apr_array_header_t *changelists,
                  svn_client_ctx_t *ctx,
-                 apr_pool_t *pool);
-
+                 apr_pool_t *pool,
+		 char *InstantPlayground);
+ 
 /** Similar to svn_client_diff6(), but with @a outfile and @a errfile,
  * instead of @a outstream and @a errstream, and with @a
  * no_diff_added, @a ignore_properties, and @a properties_only always
Index: subversion/libsvn_client/deprecated.c
===================================================================
--- subversion/libsvn_client/deprecated.c	(revision 1466727)
+++ subversion/libsvn_client/deprecated.c	(working copy)
@@ -943,7 +943,9 @@ svn_client_diff5(const apr_array_header_t *diff_op
                           ignore_content_type, FALSE /* ignore_properties */,
                           FALSE /* properties_only */, use_git_diff_format,
                           header_encoding,
-                          outstream, errstream, changelists, ctx, pool);
+                          outstream, errstream, changelists, ctx, pool, 
+/* remove the last parameter to remove the InstantPlayground! */
+                          NULL);
 }
 
 svn_error_t *
Index: subversion/libsvn_client/diff.c
===================================================================
--- subversion/libsvn_client/diff.c	(revision 1466727)
+++ subversion/libsvn_client/diff.c	(working copy)
@@ -609,6 +609,7 @@ struct diff_cmd_baton {
   /* The anchor to prefix before wc paths */
   const char *anchor;
 
+  const char *InstantPlayground;
   /* Whether the local diff target of a repos->wc diff is a copy. */
   svn_boolean_t repos_wc_diff_target_is_copy;
 };
@@ -2500,6 +2501,15 @@ set_up_diff_cmd_and_options(struct diff_cmd_baton
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+InstantPlaygroundFunction(struct diff_cmd_baton diff_cmd_baton, apr_pool_t *pool)
+{
+ /* Welcome to the Subversion Playground -- code goes here! */
+  printf("Welcome to the Subversion Playground!\n Your input was: %s\n",diff_cmd_baton.InstantPlayground);
+  return SVN_NO_ERROR;
+}
+
+
 /*----------------------------------------------------------------------- */
 
 /*** Public Interfaces. ***/
@@ -2557,7 +2567,8 @@ svn_client_diff6(const apr_array_header_t *options
                  svn_stream_t *errstream,
                  const apr_array_header_t *changelists,
                  svn_client_ctx_t *ctx,
-                 apr_pool_t *pool)
+                 apr_pool_t *pool,
+		 char *InstantPlayground)
 {
   struct diff_cmd_baton diff_cmd_baton = { 0 };
   svn_opt_revision_t peg_revision;
@@ -2595,7 +2606,15 @@ svn_client_diff6(const apr_array_header_t *options
   diff_cmd_baton.wc_ctx = ctx->wc_ctx;
   diff_cmd_baton.ra_session = NULL;
   diff_cmd_baton.anchor = NULL;
+  
+  diff_cmd_baton.InstantPlayground = InstantPlayground;
 
+  if (diff_cmd_baton.InstantPlayground) 
+  {
+    InstantPlaygroundFunction(diff_cmd_baton, pool);
+    return SVN_NO_ERROR;
+  }  
+
   return do_diff(&diff_callbacks, &diff_cmd_baton, ctx,
                  path_or_url1, path_or_url2, revision1, revision2,
                  &peg_revision,
Index: subversion/svn/cl.h
===================================================================
--- subversion/svn/cl.h	(revision 1466727)
+++ subversion/svn/cl.h	(working copy)
@@ -180,6 +180,7 @@ typedef struct svn_cl__opt_state_t
   svn_boolean_t no_auth_cache;   /* do not cache authentication information */
   struct
     {
+  const char *InstantPlayground;    
   const char *diff_cmd;              /* the external diff command to use */
   svn_boolean_t internal_diff;       /* override diff_cmd in config file */
   svn_boolean_t no_diff_added;       /* do not show diffs for deleted files */
Index: subversion/svn/diff-cmd.c
===================================================================
--- subversion/svn/diff-cmd.c	(revision 1466727)
+++ subversion/svn/diff-cmd.c	(working copy)
@@ -407,7 +407,9 @@ svn_cl__diff(apr_getopt_t *os,
                      outstream,
                      errstream,
                      opt_state->changelists,
-                     ctx, iterpool));
+                     ctx, 
+                     iterpool,
+                     opt_state->diff.InstantPlayground));
         }
       else
         {
Index: subversion/svn/svn.c
===================================================================
--- subversion/svn/svn.c	(revision 1466727)
+++ subversion/svn/svn.c	(working copy)
@@ -81,6 +81,7 @@ typedef enum svn_cl__longopt_t {
   opt_notice_ancestry,
   opt_summarize,
   opt_use_git_diff_format,
+  opt_InstantPlayground,
   opt_ignore_properties,
   opt_properties_only,
   opt_patch_compatible,
@@ -336,6 +337,7 @@ const apr_getopt_option_t svn_cl__options[] =
   {"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")},
+  {"InstantPlayground", opt_InstantPlayground, 1, N_("InstantPlayground command")},
   {"internal-diff", opt_internal_diff, 0,
                        N_("override diff-cmd specified in config file")},
   {"no-diff-added", opt_no_diff_added, 0,
@@ -575,7 +577,8 @@ const svn_opt_subcommand_desc2_t svn_cl__cmd_table
      opt_internal_diff, 'x', opt_no_diff_added, opt_no_diff_deleted,
      opt_ignore_properties, opt_properties_only,
      opt_show_copies_as_adds, opt_notice_ancestry, opt_summarize, opt_changelist,
-     opt_force, opt_xml, opt_use_git_diff_format, opt_patch_compatible} },
+     opt_force, opt_xml, opt_use_git_diff_format, opt_patch_compatible,
+     opt_InstantPlayground} },
   { "export", svn_cl__export, {0}, N_
     ("Create an unversioned copy of a tree.\n"
      "usage: 1. export [-r REV] URL[@PEGREV] [PATH]\n"
@@ -2088,6 +2091,9 @@ sub_main(int argc, const char *argv[], apr_pool_t
       case opt_diff_cmd:
         opt_state.diff.diff_cmd = apr_pstrdup(pool, opt_arg);
         break;
+      case opt_InstantPlayground:
+        opt_state.diff.InstantPlayground = apr_pstrdup(pool, opt_arg);
+        break;
       case opt_merge_cmd:
         opt_state.merge_cmd = apr_pstrdup(pool, opt_arg);
         break;

Reply via email to