diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2008-02-03 17:20:15 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2008-02-03 17:20:15 +0000 |
commit | 59f57d2e74e3e3c8cd9e4db61a68a644bfe31552 (patch) | |
tree | 434d6a029a9edefe972477c530bcecea73bf2ef4 /usr.bin/cvs | |
parent | c5bee9b77e859fa642c97be06613bd046d890c7f (diff) |
better CVSROOT/module support, includes remote support and modules
that are not aliases (-a);
OK tobias@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/checkout.c | 27 | ||||
-rw-r--r-- | usr.bin/cvs/client.c | 48 | ||||
-rw-r--r-- | usr.bin/cvs/config.h | 16 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.h | 5 | ||||
-rw-r--r-- | usr.bin/cvs/modules.c | 44 | ||||
-rw-r--r-- | usr.bin/cvs/server.c | 21 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 20 |
7 files changed, 132 insertions, 49 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 76721694965..56a5f22cc39 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.118 2008/02/03 15:20:10 tobias Exp $ */ +/* $OpenBSD: checkout.c,v 1.119 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -147,9 +147,9 @@ static void checkout_check_repository(int argc, char **argv) { int i; - char *module; char repo[MAXPATHLEN]; struct cvs_recursion cr; + struct module_checkout *mc; build_dirs = print_stdout ? 0 : 1; @@ -198,28 +198,37 @@ checkout_check_repository(int argc, char **argv) cvs_directory_tag = cvs_specified_tag; for (i = 0; i < argc; i++) { - module = cvs_module_lookup(argv[i]); + mc = cvs_module_lookup(argv[i]); + current_module = mc; (void)xsnprintf(repo, sizeof(repo), "%s/%s", - current_cvsroot->cr_dir, module); + current_cvsroot->cr_dir, mc->mc_repo); - switch (checkout_classify(repo, module)) { + if (!(mc->mc_flags & MODULE_ALIAS)) + module_repo_root = mc->mc_repo; + + switch (checkout_classify(repo, mc->mc_repo)) { case CVS_FILE: cr.fileproc = cvs_update_local; cr.flags = flags; if (build_dirs == 1) - cvs_mkpath(dirname(module), cvs_specified_tag); - cvs_file_run(1, &(module), &cr); + cvs_mkpath(dirname(mc->mc_wdir), + cvs_specified_tag); + cvs_file_run(1, &(mc->mc_repo), &cr); break; case CVS_DIR: if (build_dirs == 1) - cvs_mkpath(module, cvs_specified_tag); - checkout_repository(repo, module); + cvs_mkpath(mc->mc_wdir, cvs_specified_tag); + checkout_repository(repo, mc->mc_wdir); break; default: break; } + + xfree(mc->mc_wdir); + xfree(mc->mc_repo); + xfree(mc); } } diff --git a/usr.bin/cvs/client.c b/usr.bin/cvs/client.c index a5a2d71b9d2..c0fc5ebc46e 100644 --- a/usr.bin/cvs/client.c +++ b/usr.bin/cvs/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.97 2008/02/03 15:57:25 tobias Exp $ */ +/* $OpenBSD: client.c,v 1.98 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -108,7 +108,7 @@ struct cvs_req cvs_requests[] = { { "", -1, NULL, 0 } }; -static void client_check_directory(char *); +static void client_check_directory(char *, char *); static char *client_get_supported_responses(void); static char *lastdir = NULL; static int end_of_response = 0; @@ -153,13 +153,22 @@ client_get_supported_responses(void) } static void -client_check_directory(char *data) +client_check_directory(char *data, char *repository) { CVSENTRIES *entlist; - char entry[CVS_ENT_MAXLINELEN], *parent, *base; + char entry[CVS_ENT_MAXLINELEN], *parent, *base, *p; STRIP_SLASH(data); + /* first directory we get is our module root */ + if (module_repo_root == NULL) { + p = repository + strlen(current_cvsroot->cr_dir) + 1; + module_repo_root = xstrdup(p); + p = strrchr(module_repo_root, '/'); + if (p != NULL) + *p = '\0'; + } + cvs_mkpath(data, NULL); if (cvs_cmdop == CVS_OP_EXPORT) @@ -658,19 +667,18 @@ cvs_client_updated(char *data) struct timeval tv[2]; char repo[MAXPATHLEN], entry[CVS_ENT_MAXLINELEN]; char timebuf[CVS_TIME_BUFSZ], revbuf[CVS_REV_BUFSZ]; - char *en, *mode, *len, *fpath, *rpath, *wdir; - char sticky[CVS_ENT_MAXLINELEN]; + char *en, *mode, *len, *rpath; + char sticky[CVS_ENT_MAXLINELEN], fpath[MAXPATHLEN]; if (data == NULL) fatal("Missing argument for Updated"); - client_check_directory(data); - rpath = cvs_remote_input(); en = cvs_remote_input(); mode = cvs_remote_input(); len = cvs_remote_input(); + client_check_directory(data, rpath); cvs_get_repository_path(".", repo, MAXPATHLEN); STRIP_SLASH(repo); @@ -678,9 +686,8 @@ cvs_client_updated(char *data) if (strlen(repo) + 1 > strlen(rpath)) fatal("received a repository path that is too short"); - fpath = rpath + strlen(repo) + 1; - if ((wdir = dirname(fpath)) == NULL) - fatal("cvs_client_updated: dirname: %s", strerror(errno)); + (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", data, + strrchr(rpath, '/')); flen = strtonum(len, 0, INT_MAX, &errstr); if (errstr != NULL) @@ -712,7 +719,7 @@ cvs_client_updated(char *data) cvs_ent_free(e); if (cvs_cmdop != CVS_OP_EXPORT) { - ent = cvs_ent_open(wdir); + ent = cvs_ent_open(data); cvs_ent_add(ent, entry); cvs_ent_close(ent, ENT_SYNC); } @@ -754,13 +761,13 @@ cvs_client_merged(char *data) if (data == NULL) fatal("Missing argument for Merged"); - client_check_directory(data); - rpath = cvs_remote_input(); entry = cvs_remote_input(); mode = cvs_remote_input(); len = cvs_remote_input(); + client_check_directory(data, rpath); + repo = xmalloc(MAXPATHLEN); cvs_get_repository_path(".", repo, MAXPATHLEN); @@ -921,13 +928,12 @@ cvs_client_set_sticky(char *data) STRIP_SLASH(data); dir = cvs_remote_input(); - xfree(dir); tag = cvs_remote_input(); if (cvs_cmdop == CVS_OP_EXPORT) goto out; - client_check_directory(data); + client_check_directory(data, dir); (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG); @@ -940,6 +946,7 @@ cvs_client_set_sticky(char *data) (void)fclose(fp); out: xfree(tag); + xfree(dir); } void @@ -953,15 +960,18 @@ cvs_client_clear_sticky(char *data) STRIP_SLASH(data); dir = cvs_remote_input(); - xfree(dir); - if (cvs_cmdop == CVS_OP_EXPORT) + if (cvs_cmdop == CVS_OP_EXPORT) { + xfree(dir); return; + } - client_check_directory(data); + client_check_directory(data, dir); (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG); (void)unlink(tagpath); + + xfree(dir); } diff --git a/usr.bin/cvs/config.h b/usr.bin/cvs/config.h index 17e22a56902..fb2cd1a9ab5 100644 --- a/usr.bin/cvs/config.h +++ b/usr.bin/cvs/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.3 2008/02/02 19:32:28 joris Exp $ */ +/* $OpenBSD: config.h,v 1.4 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -30,13 +30,23 @@ void modules_parse_line(char *); /* module stuff */ -char *cvs_module_lookup(char *); +#define MODULE_ALIAS 0x01 +#define MODULE_TARGETDIR 0x02 +#define MODULE_NORECURSE 0x04 + +struct module_checkout { + char *mc_repo; + char *mc_wdir; + int mc_flags; +}; struct module_info { char *mi_name; char *mi_repository; + int mi_flags; - TAILQ_ENTRY(module_info) m_list; + TAILQ_ENTRY(module_info) m_list; }; +struct module_checkout *cvs_module_lookup(char *); #endif diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index b50bf72191a..d65441c6fe4 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.150 2008/02/01 17:18:59 tobias Exp $ */ +/* $OpenBSD: cvs.h,v 1.151 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -287,6 +287,9 @@ typedef struct cvs_entries { TAILQ_HEAD(, cvs_ent_line) cef_ent; } CVSENTRIES; +extern struct module_checkout *current_module; +extern char *module_repo_root; + extern struct cvs_wklhead temp_files; extern volatile sig_atomic_t sig_received; extern volatile sig_atomic_t cvs_quit; diff --git a/usr.bin/cvs/modules.c b/usr.bin/cvs/modules.c index 16c37ee902a..b7eb4021fe0 100644 --- a/usr.bin/cvs/modules.c +++ b/usr.bin/cvs/modules.c @@ -1,4 +1,4 @@ -/* $OpenBSD: modules.c,v 1.2 2008/02/02 19:35:39 joris Exp $ */ +/* $OpenBSD: modules.c,v 1.3 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2008 Joris Vink <joris@openbsd.org> * @@ -27,6 +27,9 @@ TAILQ_HEAD(, module_info) modules; +struct module_checkout *current_module = NULL; +char *module_repo_root = NULL; + void cvs_parse_modules(void) { @@ -83,6 +86,21 @@ modules_parse_line(char *line) switch (val[1]) { case 'a': + if (flags & MODULE_TARGETDIR) { + cvs_log(LP_NOTICE, "cannot use -a with -d"); + return; + } + flags |= MODULE_ALIAS; + break; + case 'd': + if (flags & MODULE_ALIAS) { + cvs_log(LP_NOTICE, "cannot use -d with -a"); + return; + } + flags |= MODULE_TARGETDIR; + break; + case 'l': + flags |= MODULE_NORECURSE; break; } @@ -92,18 +110,34 @@ modules_parse_line(char *line) mi = xmalloc(sizeof(*mi)); mi->mi_name = xstrdup(module); mi->mi_repository = xstrdup(val); + mi->mi_flags = flags; TAILQ_INSERT_TAIL(&modules, mi, m_list); } -char * +struct module_checkout * cvs_module_lookup(char *name) { + struct module_checkout *mc; struct module_info *mi; + mc = xmalloc(sizeof(*mc)); + TAILQ_FOREACH(mi, &modules, m_list) { - if (!strcmp(name, mi->mi_name)) - return (mi->mi_repository); + if (!strcmp(name, mi->mi_name)) { + mc = xmalloc(sizeof(*mc)); + mc->mc_repo = xstrdup(mi->mi_repository); + if (mi->mi_flags & MODULE_ALIAS) + mc->mc_wdir = xstrdup(mi->mi_repository); + else + mc->mc_wdir = xstrdup(mi->mi_name); + mc->mc_flags = mi->mi_flags; + return (mc); + } } - return (name); + mc->mc_repo = xstrdup(name); + mc->mc_wdir = xstrdup(name); + mc->mc_flags |= MODULE_ALIAS; + + return (mc); } diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 6229633748e..1aaf74aa794 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.80 2008/02/01 17:18:59 tobias Exp $ */ +/* $OpenBSD: server.c,v 1.81 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -168,6 +168,7 @@ cvs_server_root(char *data) fatal("Invalid Root specified!"); cvs_parse_configfile(); + cvs_parse_modules(); umask(cvs_umask); } @@ -752,8 +753,13 @@ cvs_server_set_sticky(char *dir, char *tag) { char fpath[MAXPATHLEN]; - (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", - current_cvsroot->cr_dir, dir); + if (module_repo_root != NULL) { + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s", + current_cvsroot->cr_dir, module_repo_root, dir); + } else { + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + current_cvsroot->cr_dir, dir); + } cvs_server_send_response("Set-sticky %s", dir); cvs_remote_output(fpath); @@ -765,8 +771,13 @@ cvs_server_clear_sticky(char *dir) { char fpath[MAXPATHLEN]; - (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", - current_cvsroot->cr_dir, dir); + if (module_repo_root != NULL) { + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s", + current_cvsroot->cr_dir, module_repo_root, dir); + } else { + (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", + current_cvsroot->cr_dir, dir); + } cvs_server_send_response("Clear-sticky %s", dir); cvs_remote_output(fpath); diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index c9a37b6bd1e..d69adfcfc83 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.129 2008/01/31 22:11:38 joris Exp $ */ +/* $OpenBSD: util.c,v 1.130 2008/02/03 17:20:14 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -590,15 +590,21 @@ cvs_mkpath(const char *path, char *tag) if (dp != NULL) *(dp++) = '\0'; - if (repo[0] != '\0') { - len = strlcat(repo, "/", sizeof(repo)); + if (sp == dir && module_repo_root != NULL) { + len = strlcpy(repo, module_repo_root, sizeof(repo)); if (len >= (int)sizeof(repo)) fatal("cvs_mkpath: overflow"); - } + } else { + if (repo[0] != '\0') { + len = strlcat(repo, "/", sizeof(repo)); + if (len >= (int)sizeof(repo)) + fatal("cvs_mkpath: overflow"); + } - len = strlcat(repo, sp, sizeof(repo)); - if (len >= (int)sizeof(repo)) - fatal("cvs_mkpath: overflow"); + len = strlcat(repo, sp, sizeof(repo)); + if (len >= (int)sizeof(repo)) + fatal("cvs_mkpath: overflow"); + } if (rpath[0] != '\0') { len = strlcat(rpath, "/", sizeof(rpath)); |