diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2007-01-18 16:45:53 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2007-01-18 16:45:53 +0000 |
commit | 1d2bf3c06fb24ab6e3c6d60346f8d9e6359384fc (patch) | |
tree | c63f3694e6fb2b2c77ae81bc879caafcad1316d2 /usr.bin | |
parent | 836bc0a4c096fe519947f933469838dd10809ec3 (diff) |
import improvements:
- add support for remote import in opencvs client and server.
- do not free already free'd buffers in import_update()
- do not append a '\0' to the loaded file buffer, this was bad behaviour
makes import work fine both locally and remotely.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/client.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 60 | ||||
-rw-r--r-- | usr.bin/cvs/remote.c | 5 | ||||
-rw-r--r-- | usr.bin/cvs/remote.h | 3 | ||||
-rw-r--r-- | usr.bin/cvs/server.c | 13 |
5 files changed, 57 insertions, 28 deletions
diff --git a/usr.bin/cvs/client.c b/usr.bin/cvs/client.c index 28df816f35b..02b49110118 100644 --- a/usr.bin/cvs/client.c +++ b/usr.bin/cvs/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.48 2007/01/17 17:54:50 joris Exp $ */ +/* $OpenBSD: client.c,v 1.49 2007/01/18 16:45:52 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -74,7 +74,7 @@ struct cvs_req cvs_requests[] = { { "rdiff", 0, NULL, 0 }, { "tag", 0, cvs_server_tag, 0 }, { "rtag", 0, NULL, 0 }, - { "import", 0, NULL, 0 }, + { "import", 0, cvs_server_import, 0 }, { "admin", 0, cvs_server_admin, 0 }, { "export", 0, NULL, 0 }, { "history", 0, NULL, 0 }, diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index 666fb470c31..8586363a060 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.63 2007/01/14 23:10:56 joris Exp $ */ +/* $OpenBSD: import.c,v 1.64 2007/01/18 16:45:52 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -20,6 +20,7 @@ #include "cvs.h" #include "diff.h" #include "log.h" +#include "remote.h" int cvs_import(int, char **); void cvs_import_local(struct cvs_file *); @@ -91,6 +92,28 @@ cvs_import(int argc, char **argv) vendor_tag = argv[1]; release_tag = argv[2]; + if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) { + cvs_client_connect_to_server(); + + cvs_client_send_request("Argument -b%s", IMPORT_DEFAULT_BRANCH); + cvs_client_send_request("Argument -m%s", logmsg); + cvs_client_send_request("Argument %s", import_repository); + cvs_client_send_request("Argument %s", vendor_tag); + cvs_client_send_request("Argument %s", release_tag); + + cr.enterdir = NULL; + cr.leavedir = NULL; + cr.fileproc = cvs_client_sendfile; + cr.flags = CR_RECURSE_DIRS; + + cvs_file_run(1, &arg, &cr); + cvs_client_senddir("."); + cvs_client_send_request("import"); + + cvs_client_get_responses(); + return (0); + } + if (cvs_path_cat(current_cvsroot->cr_dir, import_repository, repo, sizeof(repo)) >= sizeof(repo)) fatal("cvs_import: truncation"); @@ -197,8 +220,6 @@ import_new(struct cvs_file *cf) if ((bp = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL) fatal("import_new: failed to load %s", cf->file_path); - cvs_buf_putc(bp, '\0'); - if ((brev = rcsnum_brtorev(branch)) == NULL) fatal("import_new: failed to get first branch revision"); @@ -247,9 +268,10 @@ import_new(struct cvs_file *cf) static void import_update(struct cvs_file *cf) { + int ret; BUF *b1, *b2, *d; char branch[16]; - RCSNUM *newrev, *rev, *brev; + RCSNUM *newrev, *rev, *brev, *hrev; cvs_log(LP_TRACE, "import_update(%s)", cf->file_path); @@ -266,11 +288,9 @@ import_update(struct cvs_file *cf) fatal("import_update: failed to load %s", cf->file_path); - if (cvs_buf_differ(b1, b2) == 0) { + ret = cvs_buf_differ(b1, b2); + if (ret == 0) { import_tag(cf, brev, rev); - cvs_printf("U %s/%s\n", import_repository, - cf->file_path); - rcsnum_free(rev); rcsnum_free(brev); rcs_write(cf->file_rcs); return; @@ -284,7 +304,9 @@ import_update(struct cvs_file *cf) d = import_get_rcsdiff(cf, rev); newrev = rcsnum_inc(rev); } else { - d = import_get_rcsdiff(cf, rcs_head_get(cf->file_rcs)); + hrev = rcs_head_get(cf->file_rcs); + d = import_get_rcsdiff(cf, hrev); + rcsnum_free(hrev); newrev = rcsnum_brtorev(brev); } @@ -294,7 +316,6 @@ import_update(struct cvs_file *cf) if (rcs_deltatext_set(cf->file_rcs, newrev, d) == -1) fatal("import_update: failed to set deltatext"); - cvs_buf_free(d); import_tag(cf, brev, newrev); if (cf->file_rcs->rf_branch == NULL || cf->file_rcs->rf_inattic == 1 || @@ -305,10 +326,7 @@ import_update(struct cvs_file *cf) cvs_printf("U %s/%s\n", import_repository, cf->file_path); } - if (rev != NULL) - rcsnum_free(rev); rcsnum_free(brev); - rcs_write(cf->file_rcs); } @@ -332,12 +350,13 @@ import_get_rcsdiff(struct cvs_file *cf, RCSNUM *rev) char *p1, *p2; BUF *b1, *b2; - if ((b1 = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL) - fatal("import_get_rcsdiff: failed loading %s", cf->file_path); - b2 = cvs_buf_alloc(128, BUF_AUTOEXT); if (cvs_noexec != 1) { + if ((b1 = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL) + fatal("import_get_rcsdiff: failed loading %s", + cf->file_path); + (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir); cvs_buf_write_stmp(b1, p1, NULL); cvs_buf_free(b1); @@ -352,14 +371,9 @@ import_get_rcsdiff(struct cvs_file *cf, RCSNUM *rev) (void)unlink(p1); (void)unlink(p2); - if (p1 != NULL) - xfree(p1); - if (p2 != NULL) - xfree(p2); + xfree(p1); + xfree(p2); } - if (b1 != NULL) - cvs_buf_free(b1); - return (b2); } diff --git a/usr.bin/cvs/remote.c b/usr.bin/cvs/remote.c index f5094ff96a8..c1f83b00e54 100644 --- a/usr.bin/cvs/remote.c +++ b/usr.bin/cvs/remote.c @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.c,v 1.6 2007/01/13 15:29:34 joris Exp $ */ +/* $OpenBSD: remote.c,v 1.7 2007/01/18 16:45:52 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -245,5 +245,8 @@ cvs_remote_classify_file(struct cvs_file *cf) } else if (cf->fd == -1) { cf->file_status = FILE_UNKNOWN; } + + if (cvs_cmdop == CVS_OP_IMPORT && cf->file_type == CVS_FILE) + cf->file_status = FILE_MODIFIED; } diff --git a/usr.bin/cvs/remote.h b/usr.bin/cvs/remote.h index f7a55e032f6..cf1d0b9f93b 100644 --- a/usr.bin/cvs/remote.h +++ b/usr.bin/cvs/remote.h @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.h,v 1.19 2007/01/17 17:54:50 joris Exp $ */ +/* $OpenBSD: remote.h,v 1.20 2007/01/18 16:45:52 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -87,6 +87,7 @@ void cvs_server_update_patches(char *); void cvs_server_update_entry(const char *, struct cvs_file *cf); void cvs_server_add(char *); +void cvs_server_import(char *); void cvs_server_admin(char *); void cvs_server_annotate(char *); void cvs_server_commit(char *); diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index c27ebd77527..70ef3f0a398 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.49 2007/01/17 17:54:50 joris Exp $ */ +/* $OpenBSD: server.c,v 1.50 2007/01/18 16:45:52 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -482,6 +482,17 @@ cvs_server_add(char *data) } void +cvs_server_import(char *data) +{ + if (chdir(server_currentdir) == -1) + fatal("cvs_server_import: %s", strerror(errno)); + + cvs_cmdop = CVS_OP_IMPORT; + cvs_import(server_argc, server_argv); + cvs_server_send_response("ok"); +} + +void cvs_server_admin(char *data) { if (chdir(server_currentdir) == -1) |