Author: stefan2
Date: Wed Jul  8 00:46:48 2015
New Revision: 1689778

URL: http://svn.apache.org/r1689778
Log:
On the svn-mergeinfo-normalizer branch:
Implement a new sub-command, 'remove-branches' that allows the user to
selectively remove branches from mergeinfo.

The idea is to internally run a 'normalize --remove-obsoletes' but with
a fixed set of branches in the LOOKUP structure.

* tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h
  (svn_min__branch_lookup_t): Move up, no further change.
  (svn_min__opt_state_t): Add field for contents provided by '--file'.
  (svn_min__cmd_baton_t): Add optional branch LOOKUP structure.
  (svn_min__remove_branches): Declare new sub-command.
  (svn_min__branch_lookup_from_paths): Declare new constructor.

* tools/client-side/svn-mergeinfo-normalizer/logic.c
  (svn_min__run_normalize): Only create a branch lookup structure if
                            none is provided by the command itself.

* tools/client-side/svn-mergeinfo-normalizer/missing-branches.c
  (svn_min__branch_lookup_t): Session is now optional.
  (svn_min__branch_lookup_from_paths): Implement new constructor.
  (svn_min__branch_lookup): If the session is not given, all lookup
                            is strictly local.

* tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
  New file implementing the new command.

* tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c
  (svn_min__options): Add the '--file' option.
  (svn_min__cmd_table): Add the 'remove-branches' sub-command.
  (sub_main): Always initialize all elements of the command baton, i.e.
              default LOOKUP to NULL.  Process the new '--file' option.

Added:
    
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
   (with props)
Modified:
    
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/logic.c
    
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h
    
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/missing-branches.c
    
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c

Modified: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/logic.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/logic.c?rev=1689778&r1=1689777&r2=1689778&view=diff
==============================================================================
--- 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/logic.c
 (original)
+++ 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/logic.c
 Wed Jul  8 00:46:48 2015
@@ -828,7 +828,7 @@ svn_min__run_normalize(apr_getopt_t *os,
     {
       apr_array_header_t *wc_mergeinfo;
       svn_min__log_t *log = NULL;
-      svn_min__branch_lookup_t *lookup = NULL;
+      svn_min__branch_lookup_t *lookup = cmd_baton->lookup;
       const char *url;
       const char *common_path;
 
@@ -857,7 +857,7 @@ svn_min__run_normalize(apr_getopt_t *os,
         }
 
       /* open RA session */
-      if (needs_session(cmd_baton->opt_state))
+      if (!lookup && needs_session(cmd_baton->opt_state))
         {
           svn_ra_session_t *session;
 

Modified: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h?rev=1689778&r1=1689777&r2=1689778&view=diff
==============================================================================
--- 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h
 (original)
+++ 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/mergeinfo-normalizer.h
 Wed Jul  8 00:46:48 2015
@@ -42,6 +42,8 @@ extern "C" {
 
 /*** Command dispatch. ***/
 
+typedef struct svn_min__branch_lookup_t svn_min__branch_lookup_t;
+
 /* Hold results of option processing that are shared by multiple
    commands. */
 typedef struct svn_min__opt_state_t
@@ -61,6 +63,7 @@ typedef struct svn_min__opt_state_t
   svn_boolean_t dry_run;         /* try operation but make no changes */
   const char *config_dir;        /* over-riding configuration directory */
   apr_array_header_t *config_options; /* over-riding configuration options */
+  svn_stringbuf_t *filedata;     /* contents read from --file argument */
 
   /* Selected normalization operations. */
   svn_boolean_t remove_obsoletes;
@@ -87,6 +90,8 @@ typedef struct svn_min__cmd_baton_t
   const char *local_abspath;
   const char *wc_root;
   const char *repo_root;
+
+  svn_min__branch_lookup_t *lookup;
 } svn_min__cmd_baton_t;
 
 
@@ -94,7 +99,8 @@ typedef struct svn_min__cmd_baton_t
 svn_opt_subcommand_t
   svn_min__help,
   svn_min__normalize,
-  svn_min__analyze;
+  svn_min__analyze,
+  svn_min__remove_branches;
 
 /* See definition in svn.c for documentation. */
 extern const svn_opt_subcommand_desc2_t svn_min__cmd_table[];
@@ -189,12 +195,14 @@ svn_error_t *
 svn_min__print_log_stats(svn_min__log_t *log,
                          apr_pool_t *scratch_pool);
 
-typedef struct svn_min__branch_lookup_t svn_min__branch_lookup_t;
-
 svn_min__branch_lookup_t *
 svn_min__branch_lookup_create(svn_ra_session_t *session,
                               apr_pool_t *result_pool);
 
+svn_min__branch_lookup_t *
+svn_min__branch_lookup_from_paths(apr_array_header_t *paths,
+                                  apr_pool_t *result_pool);
+
 svn_error_t *
 svn_min__branch_lookup(svn_boolean_t *deleted,
                        svn_min__branch_lookup_t *lookup,

Modified: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/missing-branches.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/missing-branches.c?rev=1689778&r1=1689777&r2=1689778&view=diff
==============================================================================
--- 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/missing-branches.c
 (original)
+++ 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/missing-branches.c
 Wed Jul  8 00:46:48 2015
@@ -41,7 +41,8 @@
 
 struct svn_min__branch_lookup_t
 {
-  /* Connection to the repository where we are looking for paths. */
+  /* Connection to the repository where we are looking for paths.
+     If this is NULL, then only local lookups may be performed. */
   svn_ra_session_t *session;
 
   /* Keyed by const char * FS paths that are known not to exist.
@@ -234,6 +235,27 @@ svn_min__branch_lookup_create(svn_ra_ses
   return result;
 }
 
+svn_min__branch_lookup_t *
+svn_min__branch_lookup_from_paths(apr_array_header_t *paths,
+                                  apr_pool_t *result_pool)
+{
+  svn_min__branch_lookup_t *result
+    = svn_min__branch_lookup_create(NULL, result_pool);
+
+  int i;
+  for (i = 0; i < paths->nelts; ++i)
+    {
+      const char *path = APR_ARRAY_IDX(paths, i, const char *);
+      if (strlen(path) > 0)
+        {
+          path = apr_pstrdup(result_pool, path);
+          svn_hash_sets(result->deleted, path, path);
+        }
+    }
+
+  return result;
+}
+
 svn_error_t *
 svn_min__branch_lookup(svn_boolean_t *deleted,
                        svn_min__branch_lookup_t *lookup,
@@ -253,8 +275,9 @@ svn_min__branch_lookup(svn_boolean_t *de
 
       default:
         /* If the state is unknown and we are only allowed to do a local
-           lookup, default to a possible false negative. */
-        if (local_only)
+           lookup, default to a possible false negative.  Note that not
+           having the session available implies local-only lookup. */
+        if (local_only || !lookup->session)
           {
             *deleted = FALSE;
             return SVN_NO_ERROR;

Added: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c?rev=1689778&view=auto
==============================================================================
--- 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
 (added)
+++ 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
 Wed Jul  8 00:46:48 2015
@@ -0,0 +1,59 @@
+/*
+ * remove-branches-cmd.c -- Remove specific branch entries from all mergeinfo
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+
+/* ==================================================================== */
+
+
+
+/*** Includes. ***/
+
+#include "mergeinfo-normalizer.h"
+
+#include "svn_private_config.h"
+
+
+/*** Code. ***/
+
+/* This implements the `svn_opt_subcommand_t' interface. */
+svn_error_t *
+svn_min__remove_branches(apr_getopt_t *os,
+                         void *baton,
+                         apr_pool_t *pool)
+{
+  apr_array_header_t *branches;
+  svn_min__cmd_baton_t *cmd_baton = baton;
+
+  if (! cmd_baton->opt_state->filedata)
+    return svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
+                            _("Parameter --file not given"));
+
+  branches = svn_cstring_split(cmd_baton->opt_state->filedata->data,
+                               "\n\r", FALSE, pool);
+
+  cmd_baton->opt_state->remove_obsoletes = TRUE;
+  cmd_baton->lookup = svn_min__branch_lookup_from_paths(branches, pool);
+
+  SVN_ERR(svn_min__run_normalize(os, baton, pool));
+
+  return SVN_NO_ERROR;
+}

Propchange: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/remove-branches-cmd.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c?rev=1689778&r1=1689777&r2=1689778&view=diff
==============================================================================
--- 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c
 (original)
+++ 
subversion/branches/svn-mergeinfo-normalizer/tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c
 Wed Jul  8 00:46:48 2015
@@ -101,6 +101,7 @@ const apr_getopt_option_t svn_min__optio
   {NULL,            '?', 0, N_("show help on a subcommand")},
   {"quiet",         'q', 0, N_("print nothing, or only summary information")},
   {"version",       opt_version, 0, N_("show program version information")},
+  {"file",          'F', 1, N_("read log message from file ARG")},
   {"verbose",       'v', 0, N_("print extra information")},
   {"username",      opt_auth_username, 1, N_("specify a username ARG")},
   {"password",      opt_auth_password, 1,
@@ -233,10 +234,16 @@ const svn_opt_subcommand_desc2_t svn_min
   { "analyze", svn_min__analyze, { "analyse" }, N_
     ("Generate a report of which part of the sub-tree mergeinfo\n"
      "can be removed and which part can't.\n"
-     "usage: remove-ranges [WCPATH...]\n"),
+     "usage: analyze [WCPATH...]\n"),
     {opt_targets, opt_depth, 'v',
      opt_remove_obsoletes, opt_remove_redundant, opt_combine_ranges} },
 
+  { "remove-branches", svn_min__remove_branches, { 0 }, N_
+    ("Read a list of branch names from the given file and remove all\n"
+     "mergeinfo referring to these branches from the given targets.\n"
+     "usage: remove-branches [WCPATH...] --file FILE\n"),
+    {opt_targets, opt_depth, opt_dry_run, 'q', 'v', 'F'} },
+
   { NULL, NULL, {0}, NULL, {0} }
 };
 
@@ -303,7 +310,7 @@ sub_main(int *exit_code, int argc, const
   apr_array_header_t *received_opts;
   int i;
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
-  svn_min__cmd_baton_t command_baton;
+  svn_min__cmd_baton_t command_baton = { 0 };
   svn_auth_baton_t *ab;
   svn_config_t *cfg_config;
   svn_boolean_t interactive_conflicts = FALSE;
@@ -372,6 +379,12 @@ sub_main(int *exit_code, int argc, const
       case 'v':
         opt_state.verbose = TRUE;
         break;
+      case 'F':
+        /* We read the raw file content here. */
+        SVN_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
+        SVN_ERR(svn_stringbuf_from_file2(&(opt_state.filedata),
+                                         utf8_opt_arg, pool));
+        break;
       case opt_targets:
         {
           svn_stringbuf_t *buffer, *buffer_utf8;


Reply via email to