Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r2014 - trunk: . fsvs/src

fsvs
Discussion topic

Back to topic list

svn commit: r2014 - trunk: . fsvs/src

Author pmarek
Full name P.Marek
Date 2008-11-05 23:14:43 PST
Message Author: pmarek
Date: 2008-11-05 23:14:43-0800
New Revision: 2014

Modified:
   trunk/ (props changed)
   trunk/fsvs/src/checkout.c
   trunk/fsvs/src/url.c
   trunk/fsvs/src/waa.c
   trunk/fsvs/src/waa.h

Log:
Refactor the working copy base initialization, by splitting into a new
function for path MD5 calculation, and two others for setting the WC base
and creating the WC base paths.




Modified: trunk/fsvs/src/checkout.c
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/che​ckout.c?view=diff​&rev=2014&p1=tr​unk/fsvs/src/checkou​t.c&p2=trunk/fsv​s/src/checkout.c​&r1=2013&r2=2014​
====================​====================​====================​==================
--- trunk/fsvs/src/checkout.c (original)
+++ trunk/fsvs/src/checkout.c 2008-11-05 23:14:43-0800
@@ -109,9 +109,14 @@
         STOPIF_CODE_ERR( chdir(path)==-1, errno,
                 "!Cannot use the directory \"%s\";\nmaybe you meant to give an URL?", path);
 
+
     root->arg=path ? path : ".";
     opt_verbose++;
 
+ STOPIF( waa__save_cwd( &path, NULL, 0), NULL);
+ STOPIF( waa__create_working_copy(path), NULL);
+ free(path);
+
     /* We don't use the loop above, because the user might give the same URL
      * twice - and we'd overwrite the fetched files. */
     for(l=0; l<urllist_count; l++)

Modified: trunk/fsvs/src/url.c
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/url​.c?view=diff&rev​=2014&p1=trunk/f​svs/src/url.c&p2​=trunk/fsvs/src/url.​c&r1=2013&r2​=2014
====================​====================​====================​==================
--- trunk/fsvs/src/url.c (original)
+++ trunk/fsvs/src/url.c 2008-11-05 23:14:43-0800
@@ -1139,8 +1139,7 @@
 
     STOPIF( waa__given_or_current_wd(NULL, &dir), NULL );
     /* The current directory is the WC root. */
- wc_path=dir;
- wc_path_len=strlen(wc_path);
+ STOPIF( waa__set_working_copy(dir), NULL);
 
     /* If there's \b no parameter given, we default to dump.
      * - Use goto?
@@ -1208,18 +1207,11 @@
         }
     } /* if load_from_stdin */
 
- /* Create the necessary WAA base directory. */
- STOPIF( waa__get_waa_directory( wc_path, &dir, NULL, NULL,
- GWD_WAA | GWD_MKDIR), NULL);
- STOPIF( waa__mkdir(dir, 1), NULL);
+ STOPIF( waa__create_working_copy(dir), NULL);
 
     /* Write the URL list */
     STOPIF( url__output_list(), NULL);
 
- /* Make an informational link to the base directory. */
- /* Should we ignore errors? */
- STOPIF( waa__make_info_link(dir, "_base", dir), NULL);
-
 ex:
     return status;
 }

Modified: trunk/fsvs/src/waa.c
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/waa​.c?view=diff&rev​=2014&p1=trunk/f​svs/src/waa.c&p2​=trunk/fsvs/src/waa.​c&r1=2013&r2​=2014
====================​====================​====================​==================
--- trunk/fsvs/src/waa.c (original)
+++ trunk/fsvs/src/waa.c 2008-11-05 23:14:43-0800
@@ -392,30 +392,16 @@
 }
 
 
-/** -.
- *
- * In \a erg a pointer to an static buffer (at least as far as the caller
- * should mind!) is returned; \a eos, if not \c NULL, is set to the end of
- * the string. \a start_of_spec points at the first character specific to
- * this file, ie. after the constant part of \c $FSVS_WAA or \c $FSVS_CONF
- * and the \c PATH_SEPARATOR.
- *
- * \a flags tell whether the path is in the WAA (\ref GWD_WAA) or in the
- * configuration area (\ref GWD_CONF); furthermore you can specify that
- * directories should be created as needed with \ref GWD_MKDIR.
- *
- * The intermediate directories are created, so files can be created
- * or read directly after calling this function. */
-int waa__get_waa_directory(char *path,
- char **erg, char **eos, char **start_of_spec,
- int flags)
+/** Returns the MD5 of the given path, taking the softroot into account. */
+int waa___get_path_md5(const char const *path,
+ unsigned char digest[APR_MD5_DIGESTSIZE])
 {
- static int waa_init_for_wc = 0;
- int status, len, plen, wdlen;
+ int status;
+ int plen, wdlen;
     char *cp;
- unsigned char digest[APR_MD5_DIGESTSIZE], *p2dig;
     static const char root[]= { PATH_SEPARATOR, 0};
 
+
     status=0;
     cp=NULL;
     plen=strlen(path);
@@ -458,14 +444,52 @@
         plen=strlen(path);
     }
 
+ DEBUGP("md5 of %s", path);
+ apr_md5(digest, path, plen);
+ IF_FREE(cp);
+
+ex:
+ return status;
+}
+
+
+/** -.
+ *
+ * In \a erg a pointer to an static buffer (at least as far as the caller
+ * should mind!) is returned; \a eos, if not \c NULL, is set to the end of
+ * the string. \a start_of_spec points at the first character specific to
+ * this file, ie. after the constant part of \c $FSVS_WAA or \c $FSVS_CONF
+ * and the \c PATH_SEPARATOR.
+ *
+ * \a flags tell whether the path is in the WAA (\ref GWD_WAA) or in the
+ * configuration area (\ref GWD_CONF); furthermore you can specify that
+ * directories should be created as needed with \ref GWD_MKDIR.
+ *
+ * The intermediate directories are created, so files can be created
+ * or read directly after calling this function. */
+int waa__get_waa_directory(char *path,
+ char **erg, char **eos, char **start_of_spec,
+ int flags)
+{
+ static int waa_init_for_wc = 0;
+ int status, len;
+ char *cp;
+ unsigned char digest[APR_MD5_DIGESTSIZE], *p2dig;
+
+ status=0;
+ cp=NULL;
 
     /* Do that before the apr_md5 call, so we can use the digest. */
     if ((flags & GWD_WAA) && !waa_init_for_wc)
     {
+ waa_init_for_wc=1;
+
         /* We avoid that if it's 0 (backward compatibility). */
         if (WAA_WC_MD5_CHARS)
         {
- apr_md5(digest, wc_path, wc_path_len);
+ BUG_ON(!wc_path);
+
+ STOPIF( waa___get_path_md5(wc_path, digest), NULL);
 
             /* We have enough space for the full MD5, even if it's overwritten
              * later on; and as it's no hot path (in fact it's called only once),
@@ -479,15 +503,11 @@
         /* Termination is needed only for the output below. */
         *waa_tmp_fn = 0;
 
- DEBUGP("init wc base:%s %s", wc_path, waa_tmp_path);
- waa_init_for_wc=1;
+ DEBUGP("init wc base:%s %s", wc_path+opt__get_int​(OPT__SOFTROOT), waa_tmp_path);
     }
 
 
- DEBUGP("md5 of %s", path);
- apr_md5(digest, path, plen);
- IF_FREE(cp);
-
+ STOPIF( waa___get_path_md5(path, digest), NULL);
 
     p2dig=digest;
     len=APR_MD5_DIGESTSIZE;
@@ -2921,3 +2941,53 @@
     return status;
 }
 
+/** -.
+ * The \a dir must be absolute; this function makes an own copy, so the
+ * value will be unchanged. */
+int waa__set_working_copy(const char const *wc_dir)
+{
+ int status;
+
+ status=0;
+ BUG_ON(*wc_dir != PATH_SEPARATOR);
+ wc_path=strdup(wc_dir);
+ STOPIF_ENOMEM(!wc_path);
+
+ wc_path_len=strlen(wc_path);
+
+ex:
+ return status;
+}
+
+
+/** -.
+ * The \a dir must be absolute; this function makes an own copy, so the
+ * value will be unchanged. */
+int waa__create_working_copy(const char const *wc_dir)
+{
+ int status;
+ char *dir;
+
+ if (wc_dir)
+ STOPIF(waa__set_work​ing_copy(wc_dir), NULL);
+
+ BUG_ON(!wc_path);
+
+ /* Create the WAA base directory. */
+ STOPIF( waa__get_waa_directory( wc_path, &dir, NULL, NULL,
+ GWD_WAA | GWD_MKDIR), NULL);
+ STOPIF( waa__mkdir(dir, 1), NULL);
+
+ /* Create the CONF base directory. */
+ STOPIF( waa__get_waa_directory( wc_path, &dir, NULL, NULL,
+ GWD_CONF | GWD_MKDIR), NULL);
+ STOPIF( waa__mkdir(dir, 1), NULL);
+
+ /* Make an informational link to the base directory. */
+ /* Should we ignore errors? */
+ STOPIF( waa__make_info_link(wc_path, "_base", wc_path), NULL);
+
+ex:
+ return status;
+}
+

Modified: trunk/fsvs/src/waa.h
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/waa​.h?view=diff&rev​=2014&p1=trunk/f​svs/src/waa.h&p2​=trunk/fsvs/src/waa.​h&r1=2013&r2​=2014
====================​====================​====================​==================
--- trunk/fsvs/src/waa.h (original)
+++ trunk/fsvs/src/waa.h 2008-11-05 23:14:43-0800
@@ -270,6 +270,12 @@
  * of a WC root. */
 int waa__find_base(struct estat *root, int *argc, char ***args);
 
+/** Creates the WAA and CONF directories needed for \a wc_path. */
+int waa__create_working_copy(const char const *wc_dir);
+/** Stores the path of the working copy.
+ * Not needed if waa__find_common_base or similar is called. */
+int waa__set_working_copy(const char const *wc_dir);
+
 
 /** \name Building paths for FSVS's datafiles.
  * @{ */

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r2014 - trunk: . fsvs/src pmarek P.Marek 2008-11-05 23:14:43 PST
Messages per page: