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

[PATCH] if (err) return err; -> SVN_ERR ();

From: Garrett Rooney <rooneg_at_electricjellyfish.net>
Date: 2002-01-22 00:34:43 CET

when going through some of the wc code this weekend, i noticed some
"if (err) return err;" type code that could easily be changed to use
the (much clearer and more in line with the rest of the code) SVN_ERR
macro.

i asked on IRC, and Ben said such a patch was welcome, so here it is
for your perusal. it's simply the result of grepping through the .c
files in the tree looking for 'if (err) ret', and replacing as many as
i could with SVN_ERR. there likely are some more out there that could
be replaced, as my grep didn't catch things like:

if (err)
  return err;

but this should get a lot of them.

-garrett

* subversion/libsvn_wc/props.c
  replace if (err) return err style code with SVN_ERR. no functional
  changes.
* subversion/libsvn_wc/entries.c
  ditto.
* subversion/libsvn_wc/get_editor.c
  ditto.
* subversion/libsvn_delta/text_delta.c
  ditto.

Index: ./subversion/libsvn_wc/props.c
===================================================================
--- ./subversion/libsvn_wc/props.c
+++ ./subversion/libsvn_wc/props.c Mon Jan 21 17:56:23 2002
@@ -235,14 +235,12 @@
                         apr_hash_t *hash,
                         apr_pool_t *pool)
 {
- svn_error_t *err;
   enum svn_node_kind kind;
 
   /* ### be nice to remove this... */
   svn_stringbuf_t *pathbuf = svn_stringbuf_create (propfile_path, pool);
 
- err = svn_io_check_path (pathbuf, &kind, pool);
- if (err) return err;
+ SVN_ERR (svn_io_check_path (pathbuf, &kind, pool));
 
   if (kind == svn_node_file)
     {
@@ -389,7 +387,6 @@
                            apr_hash_t **conflicts)
 {
   int i;
- svn_error_t *err;
   svn_boolean_t is_dir;
   const char * str;
   apr_off_t len;
@@ -435,29 +432,22 @@
     }
 
   /* Get paths to the local and pristine property files. */
- err = svn_wc__prop_path (&local_propfile_path, full_path, 0, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_path (&local_propfile_path, full_path, 0, pool));
   
- err = svn_wc__prop_base_path (&base_propfile_path, full_path, 0, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_base_path (&base_propfile_path, full_path, 0, pool));
 
   /* Load the base & working property files into hashes */
   localhash = apr_hash_make (pool);
   basehash = apr_hash_make (pool);
   
- err = svn_wc__load_prop_file (base_propfile_path->data,
- basehash, pool);
- if (err) return err;
-
- err = svn_wc__load_prop_file (local_propfile_path->data,
- localhash, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__load_prop_file (base_propfile_path->data, basehash, pool));
+
+ SVN_ERR (svn_wc__load_prop_file (local_propfile_path->data, localhash, pool));
   
   /* Deduce any local propchanges the user has made since the last
      update. */
- err = svn_wc__get_local_propchanges (&local_propchanges,
- localhash, basehash, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__get_local_propchanges (&local_propchanges,
+ localhash, basehash, pool));
   
   /* Looping over the array of `update' propchanges we want to apply: */
   for (i = 0; i < propchanges->nelts; i++)
@@ -530,17 +520,15 @@
                 svn_stringbuf_t *tmpname;
 
                 /* Get path to /temporary/ local prop file */
- err = svn_wc__prop_path (&tmppath, full_path, 1, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_path (&tmppath, full_path, 1, pool));
 
                 /* Reserve a .prej file based on it. */
- err = svn_io_open_unique_file (&reject_tmp_fp,
- &reject_tmp_path,
- tmppath,
- SVN_WC__PROP_REJ_EXT,
- FALSE,
- pool);
- if (err) return err;
+ SVN_ERR (svn_io_open_unique_file (&reject_tmp_fp,
+ &reject_tmp_path,
+ tmppath,
+ SVN_WC__PROP_REJ_EXT,
+ FALSE,
+ pool));
 
                 /* reject_tmp_path is an absolute path at this point,
                    but that's no good for us. We need to convert this
@@ -571,10 +559,9 @@
               }
 
             /* Append the conflict to the open tmp/PROPS/---.prej file */
- err = append_prop_conflict (reject_tmp_fp,
- conflict_description,
- pool);
- if (err) return err;
+ SVN_ERR (append_prop_conflict (reject_tmp_fp,
+ conflict_description,
+ pool));
 
             continue; /* skip to the next update_change */
           }
@@ -592,21 +579,17 @@
   paths computed are ABSOLUTE pathnames, which is what our disk
   routines require.*/
 
- err = svn_wc__prop_base_path (&base_prop_tmp_path, full_path, 1, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_base_path (&base_prop_tmp_path, full_path, 1, pool));
 
- err = svn_wc__prop_path (&local_prop_tmp_path, full_path, 1, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_path (&local_prop_tmp_path, full_path, 1, pool));
   
   /* Write the merged pristine prop hash to either
      path/.svn/tmp/prop-base/name or path/.svn/tmp/dir-prop-base */
- err = svn_wc__save_prop_file (base_prop_tmp_path->data, basehash, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__save_prop_file (base_prop_tmp_path->data, basehash, pool));
   
   /* Write the merged local prop hash to path/.svn/tmp/props/name or
      path/.svn/tmp/dir-props */
- err = svn_wc__save_prop_file (local_prop_tmp_path->data, localhash, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__save_prop_file (local_prop_tmp_path->data, localhash, pool));
   
   /* Compute pathnames for the "mv" log entries. Notice that these
      paths are RELATIVE pathnames (each beginning with ".svn/"), so
@@ -667,11 +650,10 @@
                                   
       /* Now try to get the name of a pre-existing .prej file from the
          entries file */
- err = svn_wc__get_existing_prop_reject_file (&reject_path,
- path,
- entryname,
- pool);
- if (err) return err;
+ SVN_ERR (svn_wc__get_existing_prop_reject_file (&reject_path,
+ path,
+ entryname,
+ pool));
 
       /* ### it would be nice if the XML funcs too an svn_string_t */
       if (reject_path != NULL)
@@ -693,13 +675,12 @@
           else
             svn_path_add_component_nts (full_reject_path, name);
 
- err = svn_io_open_unique_file (&reject_fp,
- &reserved_path,
- full_reject_path,
- SVN_WC__PROP_REJ_EXT,
- FALSE,
- pool);
- if (err) return err;
+ SVN_ERR (svn_io_open_unique_file (&reject_fp,
+ &reserved_path,
+ full_reject_path,
+ SVN_WC__PROP_REJ_EXT,
+ FALSE,
+ pool));
 
           status = apr_file_close (reject_fp);
           if (status)
@@ -903,7 +884,6 @@
                   const char *path,
                   apr_pool_t *pool)
 {
- svn_error_t *err;
   enum svn_node_kind pkind;
   svn_stringbuf_t *prop_path;
 
@@ -913,12 +893,10 @@
   *props = apr_hash_make (pool);
 
   /* Construct a path to the relevant property file */
- err = svn_wc__prop_path (&prop_path, pathbuf, 0, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__prop_path (&prop_path, pathbuf, 0, pool));
 
   /* Does the property file exist? */
- err = svn_io_check_path (prop_path, &pkind, pool);
- if (err) return err;
+ SVN_ERR (svn_io_check_path (prop_path, &pkind, pool));
   
   if (pkind == svn_node_none)
     /* No property file exists. Just go home, with an empty hash. */
@@ -926,8 +904,7 @@
   
   /* else... */
 
- err = svn_wc__load_prop_file (prop_path->data, *props, pool);
- if (err) return err;
+ SVN_ERR (svn_wc__load_prop_file (prop_path->data, *props, pool));
 
   return SVN_NO_ERROR;
 }
Index: ./subversion/libsvn_wc/entries.c
===================================================================
--- ./subversion/libsvn_wc/entries.c
+++ ./subversion/libsvn_wc/entries.c Mon Jan 21 17:42:00 2002
@@ -50,17 +50,14 @@
                       svn_stringbuf_t *url,
                       apr_pool_t *pool)
 {
- svn_error_t *err;
   apr_status_t apr_err;
   apr_file_t *f = NULL;
   svn_stringbuf_t *accum = NULL;
   char *initial_revstr = apr_psprintf (pool, "%d", 0);
 
   /* Create the entries file, which must not exist prior to this. */
- err = svn_wc__open_adm_file (&f, path, SVN_WC__ADM_ENTRIES,
- (APR_WRITE | APR_CREATE | APR_EXCL), pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc__open_adm_file (&f, path, SVN_WC__ADM_ENTRIES,
+ (APR_WRITE | APR_CREATE | APR_EXCL), pool));
 
   /* Make a the XML standard header, to satisfy bureacracy. */
   svn_xml_make_header (&accum, pool);
@@ -106,9 +103,7 @@
 
   /* Now we have a `entries' file with exactly one entry, an entry
      for this dir. Close the file and sync it up. */
- err = svn_wc__close_adm_file (f, path, SVN_WC__ADM_ENTRIES, 1, pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc__close_adm_file (f, path, SVN_WC__ADM_ENTRIES, 1, pool));
 
   return SVN_NO_ERROR;
 }
@@ -586,10 +581,8 @@
   struct entries_accumulator *accum;
 
   /* Open the entries file. */
- err = svn_wc__open_adm_file (&infile, path, SVN_WC__ADM_ENTRIES,
- APR_READ, pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc__open_adm_file (&infile, path, SVN_WC__ADM_ENTRIES,
+ APR_READ, pool));
 
   /* Set up userData for the XML parser. */
   accum = apr_palloc (pool, sizeof (*accum));
@@ -624,9 +617,7 @@
   } while (!APR_STATUS_IS_EOF(apr_err));
 
   /* Close the entries file. */
- err = svn_wc__close_adm_file (infile, path, SVN_WC__ADM_ENTRIES, 0, pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc__close_adm_file (infile, path, SVN_WC__ADM_ENTRIES, 0, pool));
 
   /* Clean up the xml parser */
   svn_xml_free_parser (svn_parser);
@@ -644,16 +635,13 @@
               svn_stringbuf_t *path,
               apr_pool_t *pool)
 {
- svn_error_t *err;
   enum svn_node_kind kind;
   apr_hash_t *entries = apr_hash_make (pool);
   svn_boolean_t is_wc;
 
   *entry = NULL;
 
- err = svn_io_check_path (path, &kind, pool);
- if (err)
- return err;
+ SVN_ERR (svn_io_check_path (path, &kind, pool));
 
   /* ### todo:
      Make an innocent way to discover that a dir/path is or is not
@@ -664,18 +652,14 @@
 
   if (kind == svn_node_dir)
     {
- err = svn_wc_check_wc (path, &is_wc, pool);
- if (err)
- return err;
- else if (! is_wc)
+ SVN_ERR (svn_wc_check_wc (path, &is_wc, pool));
+ if (! is_wc)
         return svn_error_createf
           (SVN_ERR_WC_OBSTRUCTED_UPDATE, 0, NULL, pool,
            "svn_wc_entry: %s is not a working copy directory", path->data);
 
 
- err = svn_wc_entries_read (&entries, path, pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc_entries_read (&entries, path, pool));
 
       *entry
         = apr_hash_get (entries, SVN_WC_ENTRY_THIS_DIR, APR_HASH_KEY_STRING);
@@ -700,17 +684,13 @@
       if (svn_path_is_empty (dir))
         svn_stringbuf_set (dir, ".");
 
- err = svn_wc_check_wc (dir, &is_wc, pool);
- if (err)
- return err;
- else if (! is_wc)
+ SVN_ERR (svn_wc_check_wc (dir, &is_wc, pool));
+ if (! is_wc)
         return svn_error_createf
           (SVN_ERR_WC_OBSTRUCTED_UPDATE, 0, NULL, pool,
            "svn_wc_entry: %s is not a working copy directory", path->data);
       
- err = svn_wc_entries_read (&entries, dir, pool);
- if (err)
- return err;
+ SVN_ERR (svn_wc_entries_read (&entries, dir, pool));
       
       *entry = apr_hash_get (entries, basename->data, basename->len);
     }
@@ -1360,7 +1340,6 @@
                       apr_pool_t *pool,
                       ...)
 {
- svn_error_t *err;
   svn_wc_entry_t *entry_before, *entry_after;
   svn_boolean_t entry_was_deleted_p = FALSE;
   apr_hash_t *entries = NULL;
@@ -1369,8 +1348,7 @@
   va_start (ap, pool);
 
   /* Load whole entries file */
- err = svn_wc_entries_read (&entries, path, pool);
- if (err) return err;
+ SVN_ERR (svn_wc_entries_read (&entries, path, pool));
   
   if (name == NULL)
     name = svn_stringbuf_create (SVN_WC_ENTRY_THIS_DIR, pool);
Index: ./subversion/libsvn_wc/get_editor.c
===================================================================
--- ./subversion/libsvn_wc/get_editor.c
+++ ./subversion/libsvn_wc/get_editor.c Mon Jan 21 17:28:51 2002
@@ -767,12 +767,11 @@
         return err;
       
       /* Open log file */
- err = svn_wc__open_adm_file (&log_fp,
- db->path,
- SVN_WC__ADM_LOG,
- (APR_WRITE | APR_CREATE), /* not excl */
- db->pool);
- if (err) return err;
+ SVN_ERR (svn_wc__open_adm_file (&log_fp,
+ db->path,
+ SVN_WC__ADM_LOG,
+ (APR_WRITE | APR_CREATE), /* not excl */
+ db->pool));
 
       /* Merge pending properties into temporary files and detect
          conflicts. */
@@ -802,10 +801,9 @@
 
 
       /* Are the directory's props locally modified? */
- err = svn_wc_props_modified_p (&prop_modified,
- db->path,
- db->pool);
- if (err) return err;
+ SVN_ERR (svn_wc_props_modified_p (&prop_modified,
+ db->path,
+ db->pool));
 
       /* Log entry which sets a new property timestamp, but *only* if
          there are no local changes to the props. */
@@ -836,20 +834,17 @@
         }
       
       /* The log is ready to run, close it. */
- err = svn_wc__close_adm_file (log_fp,
- db->path,
- SVN_WC__ADM_LOG,
- 1, /* sync */
- db->pool);
- if (err) return err;
+ SVN_ERR (svn_wc__close_adm_file (log_fp,
+ db->path,
+ SVN_WC__ADM_LOG,
+ 1, /* sync */
+ db->pool));
 
       /* Run the log. */
- err = svn_wc__run_log (db->path, db->pool);
- if (err) return err;
+ SVN_ERR (svn_wc__run_log (db->path, db->pool));
 
       /* Unlock, we're done modifying directory props. */
- err = svn_wc__unlock (db->path, db->pool);
- if (err) return err;
+ SVN_ERR (svn_wc__unlock (db->path, db->pool));
     }
 
 
@@ -1951,10 +1946,9 @@
       svn_boolean_t prop_modified;
 
       /* Are the working file's props locally modified? */
- err = svn_wc_props_modified_p (&prop_modified,
- fb->path,
- fb->pool);
- if (err) return err;
+ SVN_ERR (svn_wc_props_modified_p (&prop_modified,
+ fb->path,
+ fb->pool));
 
       /* Log entry which sets a new property timestamp, but only if
          there are no local changes to the props. */
Index: ./subversion/libsvn_delta/text_delta.c
===================================================================
--- ./subversion/libsvn_delta/text_delta.c
+++ ./subversion/libsvn_delta/text_delta.c Mon Jan 21 18:06:07 2002
@@ -506,12 +506,10 @@
   window.pool = pool;
 
   /* Push the one window at the handler. */
- err = (*handler) (&window, handler_baton);
- if (err) return err;
+ SVN_ERR ((*handler) (&window, handler_baton));
   
   /* Push a NULL at the handler, because we're done. */
- err = (*handler) (NULL, handler_baton);
- if (err) return err;
+ SVN_ERR ((*handler) (NULL, handler_baton));
   
   return SVN_NO_ERROR;
 }

-- 
garrett rooney                     Unix was not designed to stop you from 
rooneg@electricjellyfish.net       doing stupid things, because that would  
http://electricjellyfish.net/      stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:57 2006

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.