diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-05-20 05:13:45 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-05-20 05:13:45 +0000 |
commit | 92227c2873d2aa52cc72cac6ba11491f2ca43785 (patch) | |
tree | 882a1bd003526e597fff3b8ed9fe90a9bd50f95d /usr.bin | |
parent | 953436ae010ef8b64f902cafa1e45d52112eb747 (diff) |
execute the command callback at the same time we are building
the in-memory filelist. cuts down on execution time for larger trees.
"put it in!" jfb@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/checkout.c | 9 | ||||
-rw-r--r-- | usr.bin/cvs/cmd.c | 25 | ||||
-rw-r--r-- | usr.bin/cvs/commit.c | 32 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 51 | ||||
-rw-r--r-- | usr.bin/cvs/file.h | 6 |
5 files changed, 92 insertions, 31 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 0ca9bae9490..dbb7404e761 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.18 2005/04/12 14:58:40 joris Exp $ */ +/* $OpenBSD: checkout.c,v 1.19 2005/05/20 05:13:44 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -127,8 +127,13 @@ cvs_checkout_options(char *opt, int argc, char **argv, int *arg) int cvs_checkout_sendflags(struct cvsroot *root) { - if (cvs_senddir(root, cvs_files) < 0) + if (cvs_sendreq(root, CVS_REQ_DIRECTORY, ".") < 0) return (CVS_EX_PROTO); + if (cvs_sendraw(root, root->cr_dir, strlen(root->cr_dir)) < 0) + return (CVS_EX_PROTO); + if (cvs_sendraw(root, "\n", 1) < 0) + return (CVS_EX_PROTO); + if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0) cvs_log(LP_ERR, "failed to expand module"); diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c index 7d450a8ab80..6b020b49050 100644 --- a/usr.bin/cvs/cmd.c +++ b/usr.bin/cvs/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.16 2005/04/25 21:58:32 joris Exp $ */ +/* $OpenBSD: cmd.c,v 1.17 2005/05/20 05:13:44 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -66,19 +66,10 @@ cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv) argv += i; } - if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0) - cvs_files = cvs_file_getspec(argv, argc, c->file_flags); - else - cvs_files = cvs_file_get(".", c->file_flags); - - if (cvs_files == NULL) - return (CVS_EX_DATA); - if ((c->cmd_helper != NULL) && ((ret = c->cmd_helper()) != 0)) return (ret); - root = CVS_DIR_ROOT(cvs_files); - if (root == NULL && (root = cvsroot_get(".")) == NULL) + if ((root = cvsroot_get(".")) == NULL) return (CVS_EX_BADROOT); if (root->cr_method != CVS_METHOD_LOCAL) { @@ -109,8 +100,16 @@ cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv) if (cmd->cmd_op == CVS_OP_VERSION) return (0); - if (c->cmd_examine != NULL) - cvs_file_examine(cvs_files, c->cmd_examine, NULL); + if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0) { + cvs_files = cvs_file_getspec(argv, argc, c->file_flags, + c->cmd_examine, NULL); + } else { + cvs_files = cvs_file_get(".", c->file_flags, + c->cmd_examine, NULL); + } + + if (cvs_files == NULL) + return (CVS_EX_DATA); if (root->cr_method != CVS_METHOD_LOCAL) { if (c->cmd_flags & CVS_CMD_SENDDIR) { diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c index f6f2cb857f2..a4474608c3f 100644 --- a/usr.bin/cvs/commit.c +++ b/usr.bin/cvs/commit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commit.c,v 1.31 2005/04/24 02:06:27 joris Exp $ */ +/* $OpenBSD: commit.c,v 1.32 2005/05/20 05:13:44 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -58,6 +58,8 @@ struct cvs_cmd_info cvs_commit = { }; static char *mfile = NULL; +static char **commit_files = NULL; +static int commit_fcount = 0; int cvs_commit_options(char *opt, int argc, char **argv, int *arg) @@ -100,6 +102,10 @@ cvs_commit_options(char *opt, int argc, char **argv, int *arg) return (CVS_EX_DATA); *arg = optind; + + commit_files = (argv + optind); + commit_fcount = (argc - optind); + return (0); } @@ -108,16 +114,32 @@ cvs_commit_helper(void) { struct cvs_flist cl; CVSFILE *cfp; - + CVSFILE *tmp; + int flags = CF_RECURSE | CF_IGNORE | CF_SORT; + SIMPLEQ_INIT(&cl); - cvs_file_examine(cvs_files, cvs_commit_prepare, &cl); - if (SIMPLEQ_EMPTY(&cl)) + + if (commit_fcount != 0) { + tmp = cvs_file_getspec(commit_files, commit_fcount, + flags, cvs_commit_prepare, &cl); + } else { + tmp = cvs_file_get(".", flags, cvs_commit_prepare, &cl); + } + + if (tmp == NULL) + return (CVS_EX_DATA); + + if (SIMPLEQ_EMPTY(&cl)) { + cvs_file_free(tmp); return (0); + } if (cvs_msg == NULL) - cvs_msg = cvs_logmsg_get(CVS_FILE_NAME(cvs_files), + cvs_msg = cvs_logmsg_get(CVS_FILE_NAME(tmp), NULL, &cl, NULL); + cvs_file_free(tmp); + while (!SIMPLEQ_EMPTY(&cl)) { cfp = SIMPLEQ_FIRST(&cl); SIMPLEQ_REMOVE_HEAD(&cl, cf_list); diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index dbe220352f6..2161d0b3688 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.72 2005/05/20 05:01:34 jfb Exp $ */ +/* $OpenBSD: file.c,v 1.73 2005/05/20 05:13:44 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -107,8 +107,8 @@ static RCSNUM *cvs_addedrev; TAILQ_HEAD(, cvs_ignpat) cvs_ign_pats; +static int cvs_file_getdir(CVSFILE *, int, char *, int (*)(CVSFILE *, void *), void *); static int cvs_load_dirinfo (CVSFILE *, int); -static int cvs_file_getdir (CVSFILE *, int, char *); static int cvs_file_sort (struct cvs_flist *, u_int); static int cvs_file_cmp (const void *, const void *); static int cvs_file_cmpname (const char *, const char *); @@ -345,12 +345,13 @@ cvs_file_copy(CVSFILE *orig) */ CVSFILE* -cvs_file_get(const char *path, int flags) +cvs_file_get(const char *path, int flags, int (*cb)(CVSFILE *, void *), + void *arg) { char *files[1]; files[0] = path; - return cvs_file_getspec(files, 1, flags); + return cvs_file_getspec(files, 1, flags, cb, arg); } @@ -363,7 +364,8 @@ cvs_file_get(const char *path, int flags) * files. */ CVSFILE* -cvs_file_getspec(char **fspec, int fsn, int flags) +cvs_file_getspec(char **fspec, int fsn, int flags, int (*cb)(CVSFILE *, void *), + void *arg) { int i; int pwd; @@ -377,6 +379,14 @@ cvs_file_getspec(char **fspec, int fsn, int flags) if (base == NULL) return (NULL); + /* XXX - needed for some commands */ + if (cb != NULL) { + if (cb(base, arg) != CVS_EX_OK) { + cvs_file_free(base); + return (NULL); + } + } + for (i = 0; i < fsn; i++) { strlcpy(pcopy, fspec[i], sizeof(pcopy)); sp = pcopy; @@ -412,10 +422,15 @@ cvs_file_getspec(char **fspec, int fsn, int flags) if (np != NULL) *np++; - if (cvs_file_getdir(nf, flags, np) < 0) { + if (cvs_file_getdir(nf, flags, np, cb, arg) < 0) { cvs_file_free(base); return (NULL); } + } else { + if (cb != NULL) { + if (cb(nf, arg) != CVS_EX_OK) + return (NULL); + } } } @@ -591,7 +606,7 @@ cvs_load_dirinfo(CVSFILE *cf, int flags) * is performed by cvs_file_free(). */ static int -cvs_file_getdir(CVSFILE *cf, int flags, char *path) +cvs_file_getdir(CVSFILE *cf, int flags, char *path, int (*cb)(CVSFILE *, void *), void *arg) { int l; int check_entry; @@ -630,6 +645,12 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path) if ((flags & CF_KNOWN) && (cf->cf_cvstat == CVS_FST_UNKNOWN)) return (0); + /* callback for the directory entry */ + if (cb != NULL) { + if (cb(cf, arg) != CVS_EX_OK) + return (-1); + } + dirp = opendir(fpath); if (dirp == NULL) { cvs_log(LP_ERRNO, "failed to open directory %s", fpath); @@ -699,6 +720,14 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path) if (cfp->cf_type == DT_DIR) { ndirs++; SIMPLEQ_INSERT_TAIL(&dirs, cfp, cf_list); + } else { + /* callback for the file */ + if (cb != NULL) { + if (cb(cfp, arg) != CVS_EX_OK) { + closedir(dirp); + return (-1); + } + } } if (path != NULL) { @@ -743,6 +772,12 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path) ndirs++; SIMPLEQ_INSERT_TAIL(&dirs, cfp, cf_list); + } else { + /* callback for the file */ + if (cb != NULL) { + if (cb(cfp, arg) != CVS_EX_OK) + return (-1); + } } if (path != NULL) @@ -767,7 +802,7 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path) else cfp->cf_flags &= ~CVS_GDIR_IGNORE; - if (cvs_file_getdir(cfp, flags, np) < 0) { + if (cvs_file_getdir(cfp, flags, np, cb, arg) < 0) { cvs_log(LP_ERROR, "failed to get %s", CVS_FILE_NAME(cfp)); continue; diff --git a/usr.bin/cvs/file.h b/usr.bin/cvs/file.h index f26e4f73ca1..f610ca3c93d 100644 --- a/usr.bin/cvs/file.h +++ b/usr.bin/cvs/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.18 2005/05/12 23:35:42 joris Exp $ */ +/* $OpenBSD: file.h,v 1.19 2005/05/20 05:13:44 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -129,8 +129,8 @@ typedef struct cvs_file { int cvs_file_init (void); int cvs_file_ignore (const char *); int cvs_file_chkign (const char *); -CVSFILE* cvs_file_get (const char *, int); -CVSFILE* cvs_file_getspec (char **, int, int); +CVSFILE* cvs_file_get (const char *, int, int (*)(CVSFILE *, void *), void *); +CVSFILE* cvs_file_getspec (char **, int, int, int (*)(CVSFILE *, void *), void *); CVSFILE* cvs_file_create (CVSFILE *, const char *, u_int, mode_t); CVSFILE* cvs_file_copy (CVSFILE *); CVSFILE* cvs_file_find (CVSFILE *, const char *); |