Date: Sat, 27 Mar 2010 18:40:08 +0000 (UTC) From: Dag-Erling Smorgrav <des@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r205774 - in user/des/svnsup/src: distill libsvnsup Message-ID: <201003271840.o2RIe8Qg068782@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: des Date: Sat Mar 27 18:40:08 2010 New Revision: 205774 URL: http://svn.freebsd.org/changeset/base/205774 Log: Canonicalize the session URL. Split it into root + subdir and use that information to rewrite file and directory paths from absolute to relative to the session URL. Modified: user/des/svnsup/src/distill/distill.c user/des/svnsup/src/distill/distill.h user/des/svnsup/src/libsvnsup/svnsup.h user/des/svnsup/src/libsvnsup/svnsup_delta.c Modified: user/des/svnsup/src/distill/distill.c ============================================================================== --- user/des/svnsup/src/distill/distill.c Sat Mar 27 18:24:27 2010 (r205773) +++ user/des/svnsup/src/distill/distill.c Sat Mar 27 18:40:08 2010 (r205774) @@ -31,6 +31,7 @@ #include "config.h" #endif +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -49,6 +50,7 @@ distill(const char *url, unsigned long r svn_auth_provider_object_t *auth_provider; apr_array_header_t *auth_providers; svn_ra_session_t *ra_session; + const char *root, *subdir, *uuid; svn_error_t *error; svnsup_delta_t sd; svnsup_err_t err; @@ -57,6 +59,9 @@ distill(const char *url, unsigned long r status = apr_pool_create(&pool, NULL); SVNSUP_APR_ERROR(status, "apr_pool_create()"); + /* canonicalize URL */ + url = svn_path_canonicalize(url, pool); + /* set up our authentication system */ /* XXX check for errors */ auth_providers = apr_array_make(pool, 1, sizeof auth_provider); @@ -72,9 +77,30 @@ distill(const char *url, unsigned long r NULL, config, pool); SVNSUP_SVN_ERROR(error, "svn_ra_open3()"); + /* get repo uuid */ + error = svn_ra_get_uuid2(ra_session, &uuid, pool); + SVNSUP_SVN_ERROR(error, "svn_ra_get_uuid2()"); + + /* get repo root */ + error = svn_ra_get_repos_root2(ra_session, &root, pool); + SVNSUP_SVN_ERROR(error, "svn_ra_get_repos_root2()"); + + /* get subdirectory; libsvn guarantees root is a prefix of url */ + assert(strstr(url, root) == url); + subdir = url + strlen(root); + assert(*subdir == '/' || *subdir == '\0'); + if (*subdir == '/') + ++subdir; + /* XXX create delta */ err = svnsup_create_delta(&sd); SVNSUP_SVNSUP_ERROR(err, "svnsup_delta_create()"); + err = svnsup_delta_root(sd, root); + SVNSUP_SVNSUP_ERROR(err, "svnsup_delta_root()"); + err = svnsup_delta_uuid(sd, uuid); + SVNSUP_SVNSUP_ERROR(err, "svnsup_delta_uuid()"); + err = svnsup_delta_path(sd, subdir); + SVNSUP_SVNSUP_ERROR(err, "svnsup_delta_path()"); /* get revision metadata */ error = svn_ra_get_log2(ra_session, NULL, revision, revision, 0, Modified: user/des/svnsup/src/distill/distill.h ============================================================================== --- user/des/svnsup/src/distill/distill.h Sat Mar 27 18:24:27 2010 (r205773) +++ user/des/svnsup/src/distill/distill.h Sat Mar 27 18:40:08 2010 (r205774) @@ -40,6 +40,7 @@ #include <subversion-1/svn_client.h> #include <subversion-1/svn_delta.h> #include <subversion-1/svn_error.h> +#include <subversion-1/svn_path.h> #include <subversion-1/svn_ra.h> #include "svnsup.h" Modified: user/des/svnsup/src/libsvnsup/svnsup.h ============================================================================== --- user/des/svnsup/src/libsvnsup/svnsup.h Sat Mar 27 18:24:27 2010 (r205773) +++ user/des/svnsup/src/libsvnsup/svnsup.h Sat Mar 27 18:40:08 2010 (r205774) @@ -46,6 +46,9 @@ typedef struct svnsup_delta_file *svnsup int svnsup_create_delta(svnsup_delta_t *); int svnsup_close_delta(svnsup_delta_t); +int svnsup_delta_root(svnsup_delta_t, const char *); +int svnsup_delta_uuid(svnsup_delta_t, const char *); +int svnsup_delta_path(svnsup_delta_t, const char *); int svnsup_delta_comment(svnsup_delta_t, const char *, ...); int svnsup_delta_meta(svnsup_delta_t, const char *, const char *, ...); int svnsup_delta_create_directory(svnsup_delta_t, const char *); Modified: user/des/svnsup/src/libsvnsup/svnsup_delta.c ============================================================================== --- user/des/svnsup/src/libsvnsup/svnsup_delta.c Sat Mar 27 18:24:27 2010 (r205773) +++ user/des/svnsup/src/libsvnsup/svnsup_delta.c Sat Mar 27 18:40:08 2010 (r205774) @@ -45,6 +45,9 @@ struct svnsup_delta { FILE *f; + const char *root; + const char *uuid; + const char *path; struct svnsup_delta_file *sdf; unsigned int ntxt; }; @@ -72,7 +75,7 @@ svnsup_delta_file_alloc(svnsup_delta_t s return (sdf); } -void +static void svnsup_delta_file_free(svnsup_delta_file_t sdf) { @@ -81,6 +84,18 @@ svnsup_delta_file_free(svnsup_delta_file free(sdf); } +static const char * +svnsup_delta_shorten_path(svnsup_delta_t sd, const char *pn) +{ + + assert(strstr(pn, sd->path) == pn); + pn += strlen(sd->path); + assert(*pn == '/' || *pn == '\0'); + if (*pn == '/') + ++pn; + return (pn); +} + /* * Create an svnsup delta. */ @@ -144,10 +159,71 @@ svnsup_delta_comment(svnsup_delta_t sd, int svnsup_delta_meta(svnsup_delta_t sd, const char *key, const char *fmt, ...) { + va_list ap; + char *value; + + assert(sd != NULL); + assert(key != NULL); + assert(fmt != NULL); + va_start(ap, fmt); + vasprintf(&value, fmt, ap); + va_end(ap); + fprintf(sd->f, "@meta "); + svnsup_string_fencode(sd->f, key); + fprintf(sd->f, " "); + svnsup_string_fencode(sd->f, value); + fprintf(sd->f, "\n"); + return (SVNSUP_ERR_NONE); +} + +/* + * Repository root + */ +int +svnsup_delta_root(svnsup_delta_t sd, const char *root) +{ - (void)sd; - (void)key; - (void)fmt; + assert(sd->root == NULL); + sd->root = strdup(root); + if (sd->root == NULL) + return (SVNSUP_ERR_MEMORY); + fprintf(sd->f, "@root "); + svnsup_string_fencode(sd->f, sd->root); + fprintf(sd->f, "\n"); + return (SVNSUP_ERR_NONE); +} + +/* + * Repository UUID + */ +int +svnsup_delta_uuid(svnsup_delta_t sd, const char *uuid) +{ + + assert(sd->uuid == NULL); + sd->uuid = strdup(uuid); + if (sd->uuid == NULL) + return (SVNSUP_ERR_MEMORY); + fprintf(sd->f, "@uuid "); + svnsup_string_fencode(sd->f, sd->uuid); + fprintf(sd->f, "\n"); + return (SVNSUP_ERR_NONE); +} + +/* + * Repository path (branch / subdir) + */ +int +svnsup_delta_path(svnsup_delta_t sd, const char *path) +{ + + assert(sd->path == NULL); + sd->path = strdup(path); + if (sd->path == NULL) + return (SVNSUP_ERR_MEMORY); + fprintf(sd->f, "@path "); + svnsup_string_fencode(sd->f, sd->path); + fprintf(sd->f, "\n"); return (SVNSUP_ERR_NONE); } @@ -161,6 +237,7 @@ svnsup_delta_create_directory(svnsup_del assert(sd != NULL); assert(dn != NULL && *dn != '\0'); assert(sd->sdf == NULL); + dn = svnsup_delta_shorten_path(sd, dn); fprintf(sd->f, "@mkdir "); svnsup_string_fencode(sd->f, dn); fprintf(sd->f, "\n"); @@ -177,6 +254,7 @@ svnsup_delta_remove(svnsup_delta_t sd, c assert(sd != NULL); assert(fn != NULL && *fn != '\0'); assert(sd->sdf == NULL); + fn = svnsup_delta_shorten_path(sd, fn); fprintf(sd->f, "@remove "); svnsup_string_fencode(sd->f, fn); fprintf(sd->f, "\n"); @@ -215,6 +293,7 @@ svnsup_delta_create_file(svnsup_delta_t assert(sd->sdf == NULL); assert(sdfp != NULL); assert(fn != NULL && *fn != '\0'); + fn = svnsup_delta_shorten_path(sd, fn); if ((sdf = svnsup_delta_file_alloc(sd, fn)) == NULL) return (SVNSUP_ERR_MEMORY); sdf->create = 1; @@ -238,6 +317,7 @@ svnsup_delta_open_file(svnsup_delta_t sd assert(sd->sdf == NULL); assert(sdfp != NULL); assert(fn != NULL && *fn != '\0'); + fn = svnsup_delta_shorten_path(sd, fn); if ((sdf = svnsup_delta_file_alloc(sd, fn)) == NULL) return (SVNSUP_ERR_MEMORY); *sdfp = sdf;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003271840.o2RIe8Qg068782>