diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-05-30 07:00:31 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-05-30 07:00:31 +0000 |
commit | df74a5fa19af7348e725208f461eba1f45cb08b6 (patch) | |
tree | b1ab4f0157be8429224b0b3a1d57dc93cb27fe2d /usr.bin | |
parent | 8561952559451010d73753fc3b2808e45028853b (diff) |
hello import, only works for non-existing repositories right now,
but work is in progress for importing stuff into existing repositories.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/cvs/cmd.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 11 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 214 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 13 |
5 files changed, 237 insertions, 11 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile index 2bc56db4d13..efd6bbfff91 100644 --- a/usr.bin/cvs/Makefile +++ b/usr.bin/cvs/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.26 2006/05/29 05:34:31 joris Exp $ +# $OpenBSD: Makefile,v 1.27 2006/05/30 07:00:30 joris Exp $ PROG= opencvs MAN= cvs.1 cvsignore.5 cvsrc.5 cvswrappers.5 cvsintro.7 @@ -6,8 +6,8 @@ CPPFLAGS+=-I${.CURDIR} SRCS= cvs.c add.c commit.c config.c checkout.c buf.c cmd.c date.y diff.c \ diff3.c diff_internals.c entries.c fatal.c file.c getlog.c log.c \ - remove.c repository.c rcs.c rcsnum.c rcstime.c root.c status.c \ - worklist.c util.c update.c xmalloc.c + import.c remove.c repository.c rcs.c rcsnum.c rcstime.c root.c \ + status.c worklist.c util.c update.c xmalloc.c CFLAGS+=-Wall CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c index cc88f530bd2..afb63f01204 100644 --- a/usr.bin/cvs/cmd.c +++ b/usr.bin/cvs/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.47 2006/05/29 05:34:31 joris Exp $ */ +/* $OpenBSD: cmd.c,v 1.48 2006/05/30 07:00:30 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -36,6 +36,7 @@ struct cvs_cmd *cvs_cdt[] = { &cvs_cmd_commit, &cvs_cmd_checkout, &cvs_cmd_diff, + &cvs_cmd_import, &cvs_cmd_log, &cvs_cmd_update, &cvs_cmd_remove, @@ -48,7 +49,6 @@ struct cvs_cmd *cvs_cdt[] = { &cvs_cmd_editors, &cvs_cmd_export, &cvs_cmd_history, - &cvs_cmd_import, &cvs_cmd_init, #if 0 &cvs_cmd_login, diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index 8fc89245786..5d889b680ab 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.150 2006/05/29 06:05:56 joris Exp $ */ +/* $OpenBSD: file.c,v 1.151 2006/05/30 07:00:30 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> @@ -373,7 +373,8 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr) fpath = xmalloc(MAXPATHLEN); /* - * If we do not have a admin directory inside here, dont bother. + * If we do not have a admin directory inside here, dont bother, + * unless we are running import. */ l = snprintf(fpath, MAXPATHLEN, "%s/%s", cf->file_path, CVS_PATH_CVSDIR); @@ -381,7 +382,8 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr) fatal("cvs_file_walkdir: overflow"); l = stat(fpath, &st); - if (l == -1 || (l == 0 && !S_ISDIR(st.st_mode))) { + if (cvs_cmdop != CVS_OP_IMPORT && + (l == -1 || (l == 0 && !S_ISDIR(st.st_mode)))) { xfree(fpath); return; } @@ -554,7 +556,6 @@ cvs_file_classify(struct cvs_file *cf, int loud) } verbose = (verbosity > 1 && loud == 1); - entlist = cvs_ent_open(cf->file_wd); repo = xmalloc(MAXPATHLEN); rcsfile = xmalloc(MAXPATHLEN); @@ -572,6 +573,8 @@ cvs_file_classify(struct cvs_file *cf, int loud) } cf->file_rpath = xstrdup(rcsfile); + + entlist = cvs_ent_open(cf->file_wd); cf->file_ent = cvs_ent_get(entlist, cf->file_name); if (cf->file_ent != NULL) { diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c new file mode 100644 index 00000000000..2ac7e25bb4e --- /dev/null +++ b/usr.bin/cvs/import.c @@ -0,0 +1,214 @@ +/* $OpenBSD: import.c,v 1.45 2006/05/30 07:00:30 joris Exp $ */ +/* + * Copyright (c) 2006 Joris Vink <joris@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "includes.h" + +#include "cvs.h" +#include "diff.h" +#include "log.h" +#include "proto.h" + +int cvs_import(int, char **); +void cvs_import_local(struct cvs_file *); + +static void import_new(struct cvs_file *); +static void import_update(struct cvs_file *); + +#define IMPORT_DEFAULT_BRANCH "1.1.1" + +static char *import_branch = IMPORT_DEFAULT_BRANCH; +static char *logmsg = NULL; +static char *vendor_tag = NULL; +static char *release_tag = NULL; + +char *import_repository = NULL; + +struct cvs_cmd cvs_cmd_import = { + CVS_OP_IMPORT, CVS_REQ_IMPORT, "import", + { "im", "imp" }, + "Import sources into CVS, using vendor branches", + "[-b vendor branch id] [-m message] repository vendor-tag release-tags", + "b:m:", + NULL, + cvs_import +}; + +int +cvs_import(int argc, char **argv) +{ + int ch, l; + char repo[MAXPATHLEN], *arg = "."; + struct cvs_recursion cr; + + while ((ch = getopt(argc, argv, cvs_cmd_import.cmd_opts)) != -1) { + switch (ch) { + case 'b': + import_branch = optarg; + break; + case 'm': + logmsg = optarg; + break; + default: + fatal("%s", cvs_cmd_import.cmd_synopsis); + break; + } + } + + argc -= optind; + argv += optind; + + if (argc < 3) + fatal("%s", cvs_cmd_import.cmd_synopsis); + + if (logmsg == NULL) + fatal("please specify a logmessage using -m for now"); + + import_repository = argv[0]; + vendor_tag = argv[1]; + release_tag = argv[2]; + + l = snprintf(repo, sizeof(repo), "%s/%s", current_cvsroot->cr_dir, + import_repository); + if (l == -1 || l >= (int)sizeof(repo)) + fatal("cvs_import: overflow"); + + if (mkdir(repo, 0755) == -1 && errno != EEXIST) + fatal("cvs_import: %s: %s", repo, strerror(errno)); + + cr.enterdir = NULL; + cr.leavedir = NULL; + cr.remote = NULL; + cr.local = cvs_import_local; + cr.flags = CR_RECURSE_DIRS; + cvs_file_run(1, &arg, &cr); + + return (0); +} + +void +cvs_import_local(struct cvs_file *cf) +{ + int l; + int isnew; + struct stat st; + char repo[MAXPATHLEN]; + + cvs_log(LP_TRACE, "cvs_import_local(%s)", cf->file_path); + + cvs_file_classify(cf, 0); + + if (cf->file_type == CVS_DIR) { + if (!strcmp(cf->file_path, ".")) + return; + + if (verbosity > 1) + cvs_log(LP_NOTICE, "Importing %s", cf->file_path); + + + if (mkdir(cf->file_rpath, 0755) == -1 && errno != EEXIST) + fatal("cvs_import_local: %s: %s", cf->file_rpath, + strerror(errno)); + + return; + } + + isnew = 1; + l = snprintf(repo, sizeof(repo), "%s/%s/%s/%s%s", + current_cvsroot->cr_dir, cf->file_wd, CVS_PATH_ATTIC, + cf->file_name, RCS_FILE_EXT); + if (l == -1 || l >= (int)sizeof(repo)) + fatal("import_new: overflow"); + + if (cf->file_rcs != NULL || stat(repo, &st) != -1) + isnew = 0; + + if (isnew == 1) + import_new(cf); + else + import_update(cf); +} + +static void +import_new(struct cvs_file *cf) +{ + BUF *bp; + char *content; + struct rcs_branch *brp; + struct rcs_delta *rdp; + RCSNUM *branch, *brev; + + cvs_log(LP_TRACE, "import_new(%s)", cf->file_name); + + if ((branch = rcsnum_parse(import_branch)) == NULL) + fatal("import_new: failed to parse branch"); + + if ((bp = cvs_buf_load(cf->file_path, BUF_AUTOEXT)) == NULL) + fatal("import_new: failed to load %s", cf->file_path); + + cvs_buf_putc(bp, '\0'); + content = cvs_buf_release(bp); + + if ((brev = rcsnum_brtorev(branch)) == NULL) + fatal("import_new: failed to get first branch revision"); + + cf->repo_fd = open(cf->file_rpath, O_CREAT|O_TRUNC|O_WRONLY); + if (cf->repo_fd < 0) + fatal("import_new: %s: %s", cf->file_rpath, strerror(errno)); + + cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd, RCS_CREATE, 0444); + if (cf->file_rcs == NULL) + fatal("import_new: failed to create RCS file for %s", + cf->file_path); + + rcs_branch_set(cf->file_rcs, branch); + + if (rcs_sym_add(cf->file_rcs, vendor_tag, branch) == -1) + fatal("import_new: failed to add release tag"); + + if (rcs_sym_add(cf->file_rcs, release_tag, branch) == -1) + fatal("import_new: failed to add vendor tag"); + + if (rcs_rev_add(cf->file_rcs, brev, logmsg, -1, NULL) == -1) + fatal("import_new: failed to create first branch revision"); + + if (rcs_rev_add(cf->file_rcs, RCS_HEAD_REV, logmsg, -1, NULL) == -1) + fatal("import_new: failed to create first revision"); + + if ((rdp = rcs_findrev(cf->file_rcs, cf->file_rcs->rf_head)) == NULL) + fatal("import_new: cannot find newly added revision"); + + brp = xmalloc(sizeof(*brp)); + brp->rb_num = rcsnum_alloc(); + rcsnum_cpy(brev, brp->rb_num, 0); + TAILQ_INSERT_TAIL(&(rdp->rd_branches), brp, rb_list); + + if (rcs_deltatext_set(cf->file_rcs, + cf->file_rcs->rf_head, content) == -1) + fatal("import_new: failed to set deltatext"); + + rcs_write(cf->file_rcs); + cvs_printf("N %s\n", cf->file_path); + + rcsnum_free(branch); + rcsnum_free(brev); +} + +static void +import_update(struct cvs_file *cf) +{ + cvs_log(LP_TRACE, "import_update(%s)", cf->file_path); +} diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 4af0821217a..ab30a455400 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.83 2006/05/29 07:16:44 joris Exp $ */ +/* $OpenBSD: util.c,v 1.84 2006/05/30 07:00:30 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -598,7 +598,16 @@ cvs_get_repository_name(const char *dir, char *dst, size_t len) (void)fclose(fp); } else { - if (strlcpy(dst, dir, len) >= len) + dst[0] = '\0'; + + if (cvs_cmdop == CVS_OP_IMPORT) { + if (strlcpy(dst, import_repository, len) >= len) + fatal("cvs_get_repository_name: overflow"); + if (strlcat(dst, "/", len) >= len) + fatal("cvs_get_repository_name: overflow"); + } + + if (strlcat(dst, dir, len) >= len) fatal("cvs_get_repository_name: overflow"); } } |