[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Implement --ignore and associated config option

From: mark benedetto king <bking_at_inquira.com>
Date: 2002-08-13 19:50:56 CEST

Note: this patch may illustrate the need for a client-config callback
that gets passed around the system, rather than adding lots of parameters
to the various client, wc and ra functions as they become more configuration
driven.

* subversion/include/svn_config.h

  (svn_config_read_general): Prototype for new function, handles reading
  the "general" configuration information.

* subversion/include/svn_wc.h

  (svn_wc_statuses): Added "ignore" parameter.

* subversion/include/svn_client.h

  (svn_client_status): Added "ignore" parameter.

* subversion/libsvn_wc/status.c

  (add_default_ignores): Removed. Obsoleted by new functionality.
  (add_ignore_patterns): Added "ignore" parameter, handle ignore
  parameter by appending its components to the list of patterns
  to ignore.
  (add_unversioned_items): Added "ignore" parameter. Removed call
  to obsoleted add_default_ignores.
  (svn_wc_statuses): Added "ignore" parameter. Passed "ignore" on to
  appropriate callees.

* subversion/libsvn_subr/config_file.c

  (svn_config_ensure): Factored out replicated code into new function.
  Added intialization of "general" configuration file. Note: something
  analogous should be done for the Win32 properties implementation.
  (svn_config__write_file): The new function.

* subversion/libsvn_subr/config.c:

  (svn_config_read_general): New function that mirrors the behaviour of
  svn_config_read_proxies, but for general configuration.

* subversion/libsvn_subr/config_impl.h

  (SVN_CONFIG__USR_GENERAL_FILE): New #define to abstract the name
  of the general configuration file.

* subversion/libsvn_client/delete.c

  (svn_client__can_delete): Added "ignore" argument to svn_wc_statses.

* subversion/libsvn_client/status.c

  (svn_client_status): Added "ignore" parameter. Passed "ignore" on
  to appropriate callees.

* subversion/clients/cmdline/cl.h

  (svn_cl__longopt_t): Added scl_cl__no_ignore_opt enum-value.
  (scn_cl__opt_state_t): Added "ignore" member.

* subversion/clients/cmdline/status-cmd.c

  (svn_cl__status): Read "ignore" option from cmdline, if none specified,
  read from general config. Passed "ignore" to svn_client_status.

* subversion/clients/cmdline/main.c

  (svn_cl__options): Added --ignore.
  (svn_cl__cmd_table): Added support for --ignore for svn status.
  (main): handle --ignore.

Index: subversion/include/svn_config.h
===================================================================
--- subversion/include/svn_config.h
+++ subversion/include/svn_config.h Mon Aug 12 21:11:46 2002
@@ -67,6 +67,11 @@
 */
 svn_error_t *svn_config_read_proxies (svn_config_t **cfgp, apr_pool_t *pool);
 
+/*
+ Act like svn_config_read_proxies, but on general configuration.
+*/
+
+svn_error_t *svn_config_read_general (svn_config_t **cfgp, apr_pool_t *pool);
 
 /* Read configuration data from FILE (a file or registry path) into
    *CFGP, allocated in POOL.
Index: subversion/include/svn_wc.h
===================================================================
--- subversion/include/svn_wc.h
+++ subversion/include/svn_wc.h Mon Aug 12 21:11:46 2002
@@ -674,6 +674,7 @@
                               svn_boolean_t get_all,
                               svn_boolean_t strict,
                               svn_boolean_t no_ignore,
+ const char *ignore,
                               apr_pool_t *pool);
 
 
Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h
+++ subversion/include/svn_client.h Mon Aug 12 21:11:46 2002
@@ -533,6 +533,7 @@
                    svn_boolean_t get_all,
                    svn_boolean_t update,
                    svn_boolean_t no_ignore,
+ const char *ignore,
                    apr_pool_t *pool);
 
 
Index: subversion/libsvn_wc/status.c
===================================================================
--- subversion/libsvn_wc/status.c
+++ subversion/libsvn_wc/status.c Mon Aug 12 22:13:47 2002
@@ -35,25 +35,6 @@
 #include "props.h"
 
 
-static void add_default_ignores (apr_array_header_t *patterns)
-{
- static const char * const ignores[] =
- {
- "*.o", "*.lo", "*.la", "#*#", "*.rej", "*~", ".#*",
- /* what else? */
- NULL
- };
- int i;
-
- for (i = 0; ignores[i] != NULL; i++)
- {
- const char **ent = apr_array_push(patterns);
- *ent = ignores[i];
- }
-
-}
-
-
 /* Helper routine: add to *PATTERNS patterns from the value of
    the SVN_PROP_IGNORE property set on DIRPATH. If there is no such
    property, or the property contains no patterns, do nothing.
@@ -62,6 +43,7 @@
 static svn_error_t *
 add_ignore_patterns (const char *dirpath,
                      apr_array_header_t *patterns,
+ const char *ignore,
                      apr_pool_t *pool)
 {
   const svn_string_t *value;
@@ -72,6 +54,9 @@
   if (value != NULL)
     svn_cstring_split_append (patterns, value->data, "\n\r", FALSE, pool);
 
+ if (ignore != NULL)
+ svn_cstring_split_append (patterns, ignore, " ", FALSE, pool);
+
   return SVN_NO_ERROR;
 }
 
@@ -337,6 +322,7 @@
                        apr_hash_t *entries,
                        apr_hash_t *statushash,
                        svn_boolean_t no_ignore,
+ const char *ignore,
                        apr_pool_t *pool)
 {
   apr_pool_t *subpool = svn_pool_create (pool);
@@ -352,8 +338,7 @@
   patterns = apr_array_make (subpool, 1, sizeof(const char *));
   if (! no_ignore)
     {
- add_default_ignores (patterns);
- SVN_ERR (add_ignore_patterns (path, patterns, subpool));
+ SVN_ERR (add_ignore_patterns (path, patterns, ignore, subpool));
     }
 
   /* Add empty status structures for each of the unversioned things. */
@@ -447,6 +432,7 @@
                  svn_boolean_t get_all,
                  svn_boolean_t strict,
                  svn_boolean_t no_ignore,
+ const char *ignore,
                  apr_pool_t *pool)
 {
   enum svn_node_kind kind;
@@ -504,7 +490,7 @@
 
       /* Add the unversioned items to the status output. */
       SVN_ERR (add_unversioned_items (path, entries, statushash,
- no_ignore, pool));
+ no_ignore, ignore, pool));
 
       /* Loop over entries hash */
       for (hi = apr_hash_first (pool, entries); hi; hi = apr_hash_next (hi))
@@ -588,7 +574,7 @@
                     {
                       SVN_ERR (svn_wc_statuses (statushash, fullpath, descend,
                                                 get_all, strict, no_ignore,
- pool));
+ ignore, pool));
                     }
                 }
               else if ((kind == svn_node_file) || (kind == svn_node_none))
Index: subversion/libsvn_subr/config_file.c
===================================================================
--- subversion/libsvn_subr/config_file.c
+++ subversion/libsvn_subr/config_file.c Mon Aug 12 22:15:59 2002
@@ -453,6 +453,53 @@
   return err;
 }
 
+static svn_error_t *
+svn_config__write_file (const char *name, apr_pool_t *pool,
+ const char *contents, svn_boolean_t *give_up)
+{
+ enum svn_node_kind kind;
+ apr_status_t apr_err;
+ svn_error_t *err;
+ const char *path;
+
+ *give_up = TRUE;
+
+ SVN_ERR (svn_config__user_config_path
+ (&path, name, pool));
+
+ if (! path) /* highly unlikely, since a previous call succeeded */
+ return SVN_NO_ERROR;
+
+ err = svn_io_check_path (path, &kind, pool);
+ if (err)
+ return SVN_NO_ERROR;
+
+ if (kind == svn_node_none)
+ {
+ apr_file_t *f;
+
+ apr_err = apr_file_open (&f, path,
+ (APR_WRITE | APR_CREATE | APR_EXCL),
+ APR_OS_DEFAULT,
+ pool);
+
+ if (! apr_err)
+ {
+ apr_err = apr_file_write_full (f, contents, strlen (contents), NULL);
+ if (apr_err)
+ return svn_error_createf (apr_err, 0, NULL, pool,
+ "writing config file `%s'", path);
+
+ apr_err = apr_file_close (f);
+ if (apr_err)
+ return svn_error_createf (apr_err, 0, NULL, pool,
+ "closing config file `%s'", path);
+ }
+ }
+
+ *give_up = FALSE;
+ return SVN_NO_ERROR;
+}
 
 svn_error_t *
 svn_config_ensure (apr_pool_t *pool)
@@ -460,7 +507,7 @@
   const char *path;
   enum svn_node_kind kind;
   apr_status_t apr_err;
- svn_error_t *err;
+ svn_boolean_t give_up;
 
   /* Ensure that the user-specific config directory exists. */
   SVN_ERR (svn_config__user_config_path (&path, NULL, pool));
@@ -484,21 +531,9 @@
      success. There's no _need_ to init a config directory if
      something's preventing it. */
 
- /* Ensure that the `README' file exists. */
- SVN_ERR (svn_config__user_config_path
- (&path, SVN_CONFIG__USR_README_FILE, pool));
 
- if (! path) /* highly unlikely, since a previous call succeeded */
- return SVN_NO_ERROR;
-
- err = svn_io_check_path (path, &kind, pool);
- if (err)
- return SVN_NO_ERROR;
-
- if (kind == svn_node_none)
- {
- apr_file_t *f;
- const char *contents =
+ {
+ const char *contents =
    "This directory holds run-time configuration information for Subversion\n"
    "clients. The configuration files all share the same syntax, but you\n"
    "should examine a particular file to learn what configuration\n"
@@ -606,39 +641,13 @@
    " REGISTRY:HKCU\\Software\\Tigris.org\\Subversion\\Hairstyles\n"
    "\n";
 
- apr_err = apr_file_open (&f, path,
- (APR_WRITE | APR_CREATE | APR_EXCL),
- APR_OS_DEFAULT,
- pool);
+ SVN_ERR(svn_config__write_file(SVN_CONFIG__USR_README_FILE, pool,
+ contents, &give_up));
+ if (give_up) return SVN_NO_ERROR;
+ }
 
- if (! apr_err)
- {
- apr_err = apr_file_write_full (f, contents, strlen (contents), NULL);
- if (apr_err)
- return svn_error_createf (apr_err, 0, NULL, pool,
- "writing config file `%s'", path);
-
- apr_err = apr_file_close (f);
- if (apr_err)
- return svn_error_createf (apr_err, 0, NULL, pool,
- "closing config file `%s'", path);
- }
- }
 
- /* Ensure that the `proxies' file exists. */
- SVN_ERR (svn_config__user_config_path
- (&path, SVN_CONFIG__USR_PROXY_FILE, pool));
-
- if (! path) /* highly unlikely, since a previous call succeeded */
- return SVN_NO_ERROR;
-
- err = svn_io_check_path (path, &kind, pool);
- if (err)
- return SVN_NO_ERROR;
-
- if (kind == svn_node_none)
     {
- apr_file_t *f;
       const char *contents =
         "### This file determines which proxy servers to use, if\n"
         "### any, when contacting a remote repository.\n"
@@ -687,23 +696,29 @@
         "# username = defaultusername\n"
         "# password = defaultpassword\n";
 
- apr_err = apr_file_open (&f, path,
- (APR_WRITE | APR_CREATE | APR_EXCL),
- APR_OS_DEFAULT,
- pool);
+ SVN_ERR(svn_config__write_file(SVN_CONFIG__USR_PROXY_FILE, pool,
+ contents, &give_up));
+ if (give_up) return SVN_NO_ERROR;
+ }
 
- if (! apr_err)
- {
- apr_err = apr_file_write_full (f, contents, strlen (contents), NULL);
- if (apr_err)
- return svn_error_createf (apr_err, 0, NULL, pool,
- "writing config file `%s'", path);
-
- apr_err = apr_file_close (f);
- if (apr_err)
- return svn_error_createf (apr_err, 0, NULL, pool,
- "closing config file `%s'", path);
- }
+ {
+ const char *contents =
+ "### This file contains general Subversion configuration.\n"
+ "###\n"
+ "\n"
+ "[general]\n"
+ "\n"
+ "### The wildcards provided below are used to determine\n"
+ "### which files in your working copy should be ignored\n"
+ "### during \"status\" operations.\n"
+ "### This value can be overriden on a per-directory basis\n"
+ "### via the svn:ignore property.\n"
+ "\n"
+ "ignore = *.o *.lo *.la #*# *.rej *~ .#*\n"
+ "\n";
+
+ SVN_ERR(svn_config__write_file(SVN_CONFIG__USR_GENERAL_FILE, pool,
+ contents, &give_up));
     }
 
   return SVN_NO_ERROR;
Index: subversion/libsvn_subr/config.c
===================================================================
--- subversion/libsvn_subr/config.c
+++ subversion/libsvn_subr/config.c Mon Aug 12 21:11:46 2002
@@ -212,6 +212,36 @@
 }
 
 
+
+svn_error_t *
+svn_config_read_general (svn_config_t **cfgp, apr_pool_t *pool)
+{
+ const char *usr_reg_path, *sys_reg_path;
+ const char *usr_cfg_path, *sys_cfg_path;
+
+#ifdef SVN_WIN32
+ sys_reg_path = SVN_REGISTRY_SYS_CONFIG_GENERAL_PATH;
+ usr_reg_path = SVN_REGISTRY_USR_CONFIG_GENERAL_PATH;
+#else /* SVN_WIN32 */
+ sys_reg_path = usr_reg_path = NULL;
+#endif /* SVN_WIN32 */
+
+ SVN_ERR (svn_config__sys_config_path (&sys_cfg_path,
+ SVN_CONFIG__USR_GENERAL_FILE,
+ pool));
+
+ SVN_ERR (svn_config__user_config_path (&usr_cfg_path,
+ SVN_CONFIG__USR_GENERAL_FILE,
+ pool));
+
+ SVN_ERR (read_all (cfgp,
+ sys_reg_path, usr_reg_path,
+ sys_cfg_path, usr_cfg_path,
+ pool));
+
+ return SVN_NO_ERROR;
+}
+
 
 /* Iterate through CFG, passing BATON to CALLBACK for every (SECTION, OPTION)
    pair. Stop if CALLBACK returns TRUE. Allocate from POOL. */
Index: subversion/libsvn_subr/config_impl.h
===================================================================
--- subversion/libsvn_subr/config_impl.h
+++ subversion/libsvn_subr/config_impl.h Mon Aug 12 21:11:46 2002
@@ -112,6 +112,10 @@
 /* The proxy config file in SVN_CONFIG__DIRECTORY. */
 #define SVN_CONFIG__USR_PROXY_FILE "proxies"
 
+/* The general config file in SVN_CONFIG__DIRECTORY. */
+#define SVN_CONFIG__USR_GENERAL_FILE "general"
+
+
 
 /* Set *PATH_P to the path to config file FNAME in the system
    configuration area, allocated in POOL. If FNAME is NULL, set
Index: subversion/libsvn_client/delete.c
===================================================================
--- subversion/libsvn_client/delete.c
+++ subversion/libsvn_client/delete.c Mon Aug 12 21:13:00 2002
@@ -42,7 +42,8 @@
   apr_hash_t *hash = apr_hash_make (pool);
   apr_hash_index_t *hi;
 
- SVN_ERR (svn_wc_statuses (hash, path, TRUE, FALSE, FALSE, FALSE, pool));
+ SVN_ERR (svn_wc_statuses (hash, path, TRUE, FALSE, FALSE, FALSE,
+ NULL, pool));
   for (hi = apr_hash_first (pool, hash); hi; hi = apr_hash_next (hi))
     {
       const void *key;
Index: subversion/libsvn_client/status.c
===================================================================
--- subversion/libsvn_client/status.c
+++ subversion/libsvn_client/status.c Mon Aug 12 21:11:46 2002
@@ -147,6 +147,7 @@
                    svn_boolean_t get_all,
                    svn_boolean_t update,
                    svn_boolean_t no_ignore,
+ const char *ignore,
                    apr_pool_t *pool)
 {
   apr_hash_t *hash = apr_hash_make (pool);
@@ -169,7 +170,7 @@
      function understands these flags too, and will return the correct
      set of structures. */
   SVN_ERR (svn_wc_statuses (hash, path, descend, get_all,
- strict, no_ignore, pool));
+ strict, no_ignore, ignore, pool));
 
 
   /* If the caller wants us to contact the repository also... */
Index: subversion/clients/cmdline/cl.h
===================================================================
--- subversion/clients/cmdline/cl.h
+++ subversion/clients/cmdline/cl.h Mon Aug 12 22:07:42 2002
@@ -52,7 +52,8 @@
   svn_cl__targets_opt,
   svn_cl__xml_opt,
   svn_cl__strict_opt,
- svn_cl__no_ignore_opt
+ svn_cl__no_ignore_opt,
+ svn_cl__ignore_opt
 } svn_cl__longopt_t;
 
 
@@ -75,6 +76,7 @@
 
   const char *message; /* log message */
   const char *xml_file; /* xml source/target file */ /* UTF-8! */
+ const char *ignore; /* ignore wildcards */ /* UTF-8! */
   const char *ancestor_path; /* ### todo: who sets this? */
   svn_boolean_t force; /* be more forceful, as in "svn rm -f ..." */
   svn_boolean_t quiet; /* sssh...avoid unnecessary output */
Index: subversion/clients/cmdline/status-cmd.c
===================================================================
--- subversion/clients/cmdline/status-cmd.c
+++ subversion/clients/cmdline/status-cmd.c Mon Aug 12 22:14:15 2002
@@ -24,6 +24,7 @@
 
 #include "svn_wc.h"
 #include "svn_client.h"
+#include "svn_config.h"
 #include "svn_string.h"
 #include "svn_path.h"
 #include "svn_delta.h"
@@ -43,6 +44,7 @@
   int i;
   svn_client_auth_baton_t *auth_baton;
   svn_revnum_t youngest = SVN_INVALID_REVNUM;
+ const char *ignore;
 
   SVN_ERR (svn_cl__args_to_target_array (&targets, os, opt_state,
                                          FALSE, pool));
@@ -53,6 +55,16 @@
   /* Add "." if user passed 0 arguments */
   svn_cl__push_implicit_dot_target(targets, pool);
 
+ ignore = opt_state->ignore;
+ if (!ignore)
+ {
+ svn_config_t *cfg;
+
+ SVN_ERR(svn_config_read_general(&cfg, pool));
+
+ svn_config_get(cfg, &ignore, "general", "ignore", "");
+ }
+
   for (i = 0; i < targets->nelts; i++)
     {
       const char *target = ((const char **) (targets->elts))[i];
@@ -68,6 +80,7 @@
                                   opt_state->verbose,
                                   opt_state->update,
                                   opt_state->no_ignore,
+ ignore,
                                   pool));
 
       /* Now print the structures to the screen.
Index: subversion/clients/cmdline/main.c
===================================================================
--- subversion/clients/cmdline/main.c
+++ subversion/clients/cmdline/main.c Tue Aug 13 13:49:33 2002
@@ -51,6 +51,7 @@
   {
     {"force", svn_cl__force_opt, 0, "force operation to run"},
     {"help", 'h', 0, "show help on a subcommand"},
+ {"ignore", svn_cl__ignore_opt, 1, "set of wildcards to ignore"},
     {NULL, '?', 0, "show help on a subcommand"},
     {"message", 'm', 1, "specify commit message \"ARG\""},
     {"quiet", 'q', 0, "print as little as possible"},
@@ -380,7 +381,7 @@
     " M 965 687 joe ./buildcheck.sh\n",
     { 'u', 'v', 'N', 'q',
       svn_cl__auth_username_opt, svn_cl__auth_password_opt,
- svn_cl__no_ignore_opt } },
+ svn_cl__no_ignore_opt, svn_cl__ignore_opt } },
   
   { "switch", svn_cl__switch, {"sw"},
     "Update working copy to mirror a new URL\n"
@@ -1049,6 +1050,16 @@
                                                  TRUE, pool);
         }
         break;
+ case svn_cl__ignore_opt:
+ err = svn_utf_cstring_to_utf8 (&opt_state.ignore, opt_arg,
+ NULL, pool);
+ if (err)
+ {
+ svn_handle_error (err, stdout, FALSE);
+ svn_pool_destroy (pool);
+ return EXIT_FAILURE;
+ }
+ break;
       case svn_cl__force_opt:
         opt_state.force = TRUE;
         break;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Aug 13 23:47:00 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.