summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-03-30 17:43:05 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-03-30 17:43:05 +0000
commit5b986e03ce06f9622dda7f8bc1338d9de181b52d (patch)
treece3b8bcfcc5e2b1e7167a18b4f7ad8d770c7105b /usr.bin
parent25e5b3f683745187504de87e699abd81f29f67d8 (diff)
move all the client commands to the new command framework.
eliminates a lot of duplicate code. ok jfb@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/add.c82
-rw-r--r--usr.bin/cvs/admin.c198
-rw-r--r--usr.bin/cvs/annotate.c96
-rw-r--r--usr.bin/cvs/checkout.c103
-rw-r--r--usr.bin/cvs/commit.c88
-rw-r--r--usr.bin/cvs/cvs.c106
-rw-r--r--usr.bin/cvs/cvs.h36
-rw-r--r--usr.bin/cvs/diff.c102
-rw-r--r--usr.bin/cvs/getlog.c69
-rw-r--r--usr.bin/cvs/history.c112
-rw-r--r--usr.bin/cvs/import.c85
-rw-r--r--usr.bin/cvs/init.c42
-rw-r--r--usr.bin/cvs/proto.c4
-rw-r--r--usr.bin/cvs/remove.c61
-rw-r--r--usr.bin/cvs/status.c84
-rw-r--r--usr.bin/cvs/tag.c97
-rw-r--r--usr.bin/cvs/update.c73
-rw-r--r--usr.bin/cvs/version.c22
18 files changed, 580 insertions, 880 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c
index 666add75243..869c7389258 100644
--- a/usr.bin/cvs/add.c
+++ b/usr.bin/cvs/add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: add.c,v 1.14 2005/01/24 18:30:25 jfb Exp $ */
+/* $OpenBSD: add.c,v 1.15 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -41,26 +41,31 @@
extern char *__progname;
-int cvs_add_file (CVSFILE *, void *);
+int cvs_add_file(CVSFILE *, void *);
+int cvs_add_options(char *, int, char **, int *);
+int cvs_add_sendflags(struct cvsroot *);
+struct cvs_cmd_info cvs_add = {
+ cvs_add_options,
+ cvs_add_sendflags,
+ cvs_add_file,
+ NULL, NULL,
+ 0,
+ CVS_REQ_ADD,
+ CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
+};
+
+static int kflag = RCS_KWEXP_DEFAULT;
+static char *koptstr;
-/*
- * cvs_add()
- *
- * Handler for the `cvs add' command.
- * Returns 0 on success, or one of the known system exit codes on failure.
- */
int
-cvs_add(int argc, char **argv)
+cvs_add_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, kflag;
- char buf[16], *koptstr;
- struct cvsroot *root;
+ int ch;
- kflag = RCS_KWEXP_DEFAULT;
cvs_msg = NULL;
- while ((ch = getopt(argc, argv, "k:m:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'k':
koptstr = optarg;
@@ -83,52 +88,25 @@ cvs_add(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
- if (argc == 0)
- return (EX_USAGE);
-
- cvs_files = cvs_file_getspec(argv, argc, 0);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
- if (kflag != RCS_KWEXP_DEFAULT) {
- strlcpy(buf, "-k", sizeof(buf));
- strlcat(buf, koptstr, sizeof(buf));
- if (cvs_sendarg(root, buf, 0) < 0)
- return (EX_PROTOCOL);
- }
- }
-
- cvs_file_examine(cvs_files, cvs_add_file, NULL);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
+ *arg = optind;
+ return (0);
+}
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
+int
+cvs_add_sendflags(struct cvsroot *root)
+{
+ char buf[16];
- if (cvs_sendreq(root, CVS_REQ_ADD, NULL) < 0)
+ if (kflag != RCS_KWEXP_DEFAULT) {
+ strlcpy(buf, "-k", sizeof(buf));
+ strlcat(buf, koptstr, sizeof(buf));
+ if (cvs_sendarg(root, buf, 0) < 0)
return (EX_PROTOCOL);
}
return (0);
}
-
int
cvs_add_file(CVSFILE *cf, void *arg)
{
diff --git a/usr.bin/cvs/admin.c b/usr.bin/cvs/admin.c
index 5b4d74fa1ff..fa7dd9ce56e 100644
--- a/usr.bin/cvs/admin.c
+++ b/usr.bin/cvs/admin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: admin.c,v 1.6 2005/03/26 08:09:54 tedu Exp $ */
+/* $OpenBSD: admin.c,v 1.7 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
@@ -41,8 +41,6 @@
#include "proto.h"
-int cvs_admin_file (CVSFILE *, void *);
-
#define LOCK_SET 0x01
#define LOCK_REMOVE 0x02
@@ -51,32 +49,38 @@ int cvs_admin_file (CVSFILE *, void *);
#define FLAG_INTERACTIVE 0x04
#define FLAG_QUIET 0x08
-/*
- * cvs_admin()
- *
- * Handler for the `cvs admin' command.
- * Returns 0 on success, or one of the known exit codes on error.
- */
+int cvs_admin_options(char *, int, char **, int *);
+int cvs_admin_sendflags(struct cvsroot *);
+int cvs_admin_file(CVSFILE *, void *);
+
+struct cvs_cmd_info cvs_admin = {
+ cvs_admin_options,
+ cvs_admin_sendflags,
+ cvs_admin_file,
+ NULL, NULL,
+ CF_SORT | CF_IGNORE | CF_RECURSE,
+ CVS_REQ_ADMIN,
+ CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
+};
+
+static char *q, *Ntag, *ntag, *comment, *replace_msg;
+static char *alist, *subst, *lockrev_arg, *unlockrev_arg;
+static char *state, *userfile, *branch_arg, *elist, *range;
+static int runflags, kflag, lockrev, strictlock;
+
int
-cvs_admin(int argc, char **argv)
+cvs_admin_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, flags;
- int runflags, kflag, lockrev, strictlock;
- char *q, *Ntag, *ntag, *comment, *replace_msg;
- char *alist, *subst, *lockrev_arg, *unlockrev_arg;
- char *state, *userfile, *branch_arg, *elist, *range;
- struct cvsroot *root;
+ int ch;
RCSNUM *rcs;
runflags = strictlock = lockrev = 0;
Ntag = ntag = comment = replace_msg = NULL;
state = alist = subst = elist = lockrev_arg = NULL;
range = userfile = branch_arg = unlockrev_arg = NULL;
- flags = CF_SORT|CF_IGNORE|CF_RECURSE;
/* option-o-rama ! */
- while ((ch = getopt(argc, argv, "a:A:b::c:e::Ik:l::Lm:n:N:o:qs:t:u::U"))
- != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'a':
alist = optarg;
@@ -193,125 +197,97 @@ cvs_admin(int argc, char **argv)
*q = ':';
}
- if (argc == 0) {
- cvs_files = cvs_file_get(".", flags);
- } else {
- cvs_files = cvs_file_getspec(argv, argc, 0);
- }
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
+ *arg = optind;
+ return (0);
+}
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
+int
+cvs_admin_sendflags(struct cvsroot *root)
+{
+ if ((alist != NULL) && ((cvs_sendarg(root, "-a", 0) < 0) ||
+ (cvs_sendarg(root, alist, 0) < 0)))
+ return (EX_PROTOCOL);
- if ((alist != NULL) && ((cvs_sendarg(root, "-a", 0) < 0) ||
- (cvs_sendarg(root, alist, 0) < 0)))
- return (EX_PROTOCOL);
+ if ((userfile != NULL) && ((cvs_sendarg(root, "-A", 0) < 0) ||
+ (cvs_sendarg(root, userfile, 0) < 0)))
+ return (EX_PROTOCOL);
- if ((userfile != NULL) && ((cvs_sendarg(root, "-A", 0) < 0) ||
- (cvs_sendarg(root, userfile, 0) < 0)))
+ if (runflags & FLAG_BRANCH) {
+ if (cvs_sendarg(root, "-b", 0) < 0)
return (EX_PROTOCOL);
-
- if (runflags & FLAG_BRANCH) {
- if (cvs_sendarg(root, "-b", 0) < 0)
- return (EX_PROTOCOL);
- if ((branch_arg != NULL) &&
- (cvs_sendarg(root, branch_arg, 0) < 0))
- return (EX_PROTOCOL);
- }
-
- if ((comment != NULL) && ((cvs_sendarg(root, "-c", 0) < 0) ||
- (cvs_sendarg(root, comment, 0) < 0)))
+ if ((branch_arg != NULL) &&
+ (cvs_sendarg(root, branch_arg, 0) < 0))
return (EX_PROTOCOL);
+ }
- if (runflags & FLAG_DELUSER) {
- if (cvs_sendarg(root, "-e", 0) < 0)
- return (EX_PROTOCOL);
- if ((elist != NULL) &&
- (cvs_sendarg(root, elist, 0) < 0))
- return (EX_PROTOCOL);
- }
-
- if (runflags & FLAG_INTERACTIVE) {
- if (cvs_sendarg(root, "-I", 0) < 0)
- return (EX_PROTOCOL);
- }
+ if ((comment != NULL) && ((cvs_sendarg(root, "-c", 0) < 0) ||
+ (cvs_sendarg(root, comment, 0) < 0)))
+ return (EX_PROTOCOL);
- if ((subst != NULL) && ((cvs_sendarg(root, "-k", 0) < 0) ||
- (cvs_sendarg(root, subst, 0) < 0)))
+ if (runflags & FLAG_DELUSER) {
+ if (cvs_sendarg(root, "-e", 0) < 0)
return (EX_PROTOCOL);
-
- if (lockrev & LOCK_SET) {
- if (cvs_sendarg(root, "-l", 0) < 0)
- return (EX_PROTOCOL);
- if ((lockrev_arg != NULL) &&
- (cvs_sendarg(root, lockrev_arg, 0) < 0))
- return (0);
- }
-
- if ((strictlock & LOCK_SET) &&
- (cvs_sendarg(root, "-L", 0) < 0))
+ if ((elist != NULL) &&
+ (cvs_sendarg(root, elist, 0) < 0))
return (EX_PROTOCOL);
+ }
- if ((replace_msg != NULL) && ((cvs_sendarg(root, "-m", 0) < 0)
- || (cvs_sendarg(root, replace_msg, 0) < 0)))
+ if (runflags & FLAG_INTERACTIVE) {
+ if (cvs_sendarg(root, "-I", 0) < 0)
return (EX_PROTOCOL);
+ }
- if ((ntag != NULL) && ((cvs_sendarg(root, "-n", 0) < 0) ||
- (cvs_sendarg(root, ntag, 0) < 0)))
- return (EX_PROTOCOL);
+ if ((subst != NULL) && ((cvs_sendarg(root, "-k", 0) < 0) ||
+ (cvs_sendarg(root, subst, 0) < 0)))
+ return (EX_PROTOCOL);
- if ((Ntag != NULL) && ((cvs_sendarg(root, "-N", 0) < 0) ||
- (cvs_sendarg(root, Ntag, 0) < 0)))
+ if (lockrev & LOCK_SET) {
+ if (cvs_sendarg(root, "-l", 0) < 0)
return (EX_PROTOCOL);
+ if ((lockrev_arg != NULL) &&
+ (cvs_sendarg(root, lockrev_arg, 0) < 0))
+ return (0);
+ }
- if ((range != NULL) && ((cvs_sendarg(root, "-o", 0) < 0) ||
- (cvs_sendarg(root, range, 0) < 0)))
- return (EX_PROTOCOL);
+ if ((strictlock & LOCK_SET) &&
+ (cvs_sendarg(root, "-L", 0) < 0))
+ return (EX_PROTOCOL);
- if ((state != NULL) && ((cvs_sendarg(root, "-s", 0) < 0) ||
- (cvs_sendarg(root, state, 0) < 0)))
- return (EX_PROTOCOL);
+ if ((replace_msg != NULL) && ((cvs_sendarg(root, "-m", 0) < 0)
+ || (cvs_sendarg(root, replace_msg, 0) < 0)))
+ return (EX_PROTOCOL);
- if (lockrev & LOCK_REMOVE) {
- if (cvs_sendarg(root, "-u", 0) < 0)
- return (EX_PROTOCOL);
- if ((unlockrev_arg != NULL) &&
- (cvs_sendarg(root, unlockrev_arg, 0) < 0))
- return (EX_PROTOCOL);
- }
+ if ((ntag != NULL) && ((cvs_sendarg(root, "-n", 0) < 0) ||
+ (cvs_sendarg(root, ntag, 0) < 0)))
+ return (EX_PROTOCOL);
- if ((strictlock & LOCK_REMOVE) &&
- (cvs_sendarg(root, "-U", 0) < 0))
- return (EX_PROTOCOL);
- }
+ if ((Ntag != NULL) && ((cvs_sendarg(root, "-N", 0) < 0) ||
+ (cvs_sendarg(root, Ntag, 0) < 0)))
+ return (EX_PROTOCOL);
+
+ if ((range != NULL) && ((cvs_sendarg(root, "-o", 0) < 0) ||
+ (cvs_sendarg(root, range, 0) < 0)))
+ return (EX_PROTOCOL);
- cvs_file_examine(cvs_files, cvs_admin_file, NULL);
+ if ((state != NULL) && ((cvs_sendarg(root, "-s", 0) < 0) ||
+ (cvs_sendarg(root, state, 0) < 0)))
+ return (EX_PROTOCOL);
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
+ if (lockrev & LOCK_REMOVE) {
+ if (cvs_sendarg(root, "-u", 0) < 0)
return (EX_PROTOCOL);
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_ADMIN, NULL) < 0)
+ if ((unlockrev_arg != NULL) &&
+ (cvs_sendarg(root, unlockrev_arg, 0) < 0))
return (EX_PROTOCOL);
}
+ if ((strictlock & LOCK_REMOVE) &&
+ (cvs_sendarg(root, "-U", 0) < 0))
+ return (EX_PROTOCOL);
+
return (0);
}
-
/*
* cvs_admin_file()
*
diff --git a/usr.bin/cvs/annotate.c b/usr.bin/cvs/annotate.c
index fc7d545afa7..37b3caeef37 100644
--- a/usr.bin/cvs/annotate.c
+++ b/usr.bin/cvs/annotate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: annotate.c,v 1.4 2005/01/13 16:32:46 jfb Exp $ */
+/* $OpenBSD: annotate.c,v 1.5 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -41,27 +41,32 @@
#include "proto.h"
-int cvs_annotate_file (CVSFILE *, void *);
-int cvs_annotate_prune (CVSFILE *, void *);
+int cvs_annotate_file(CVSFILE *, void *);
+int cvs_annotate_prune(CVSFILE *, void *);
+int cvs_annotate_options(char *, int, char **, int *);
+int cvs_annotate_sendflags(struct cvsroot *);
+struct cvs_cmd_info cvs_annotate = {
+ cvs_annotate_options,
+ cvs_annotate_sendflags,
+ cvs_annotate_file,
+ NULL, NULL,
+ CF_SORT | CF_RECURSE | CF_IGNORE | CF_NOSYMS,
+ CVS_REQ_ANNOTATE,
+ CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
+};
+
+static char *date, *rev;
+static int usehead;
-/*
- * cvs_annotate()
- *
- * Handle the `cvs annotate' command.
- * Returns 0 on success, or the appropriate exit code on error.
- */
int
-cvs_annotate(int argc, char **argv)
+cvs_annotate_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, flags, usehead;
- char *date, *rev;
- struct cvsroot *root;
+ int ch;
usehead = 0;
date = NULL;
rev = NULL;
- flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_NOSYMS;
while ((ch = getopt(argc, argv, "D:flRr:")) != -1) {
switch (ch) {
@@ -72,10 +77,10 @@ cvs_annotate(int argc, char **argv)
usehead = 1;
break;
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_annotate.file_flags &= ~CF_RECURSE;
break;
case 'R':
- flags |= CF_RECURSE;
+ cvs_annotate.file_flags |= CF_RECURSE;
break;
case 'r':
rev = optarg;
@@ -91,62 +96,31 @@ cvs_annotate(int argc, char **argv)
return (EX_USAGE);
}
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- cvs_files = cvs_file_get(".", flags);
- } else {
- /* don't perform ignore on explicitly listed files */
- flags &= ~(CF_IGNORE | CF_RECURSE | CF_SORT);
- cvs_files = cvs_file_getspec(argv, argc, flags);
- }
- if (cvs_files == NULL)
- return (EX_DATAERR);
+ *arg = optind;
+ return (0);
+}
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
+int
+cvs_annotate_sendflags(struct cvsroot *root)
+{
+ if (usehead && (cvs_sendarg(root, "-f", 0) < 0))
+ return (EX_PROTOCOL);
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
- if (usehead && (cvs_sendarg(root, "-f", 0) < 0))
+ if (rev != NULL) {
+ if ((cvs_sendarg(root, "-r", 0) < 0) ||
+ (cvs_sendarg(root, rev, 0) < 0))
return (EX_PROTOCOL);
- if (rev != NULL) {
- if ((cvs_sendarg(root, "-r", 0) < 0) ||
- (cvs_sendarg(root, rev, 0) < 0))
- return (EX_PROTOCOL);
- }
- if (date != NULL) {
- if ((cvs_sendarg(root, "-D", 0) < 0) ||
- (cvs_sendarg(root, date, 0) < 0))
- return (EX_PROTOCOL);
- }
}
- cvs_file_examine(cvs_files, cvs_annotate_file, NULL);
-
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_ANNOTATE, NULL) < 0)
+ if (date != NULL) {
+ if ((cvs_sendarg(root, "-D", 0) < 0) ||
+ (cvs_sendarg(root, date, 0) < 0))
return (EX_PROTOCOL);
}
return (0);
}
-
/*
* cvs_annotate_file()
*
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c
index eeca51f859c..47f1e74272b 100644
--- a/usr.bin/cvs/checkout.c
+++ b/usr.bin/cvs/checkout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: checkout.c,v 1.13 2005/02/22 22:12:00 jfb Exp $ */
+/* $OpenBSD: checkout.c,v 1.14 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -42,26 +42,31 @@
#define CVS_LISTMOD 1
#define CVS_STATMOD 2
+int cvs_checkout_options(char *, int, char **, int *);
+int cvs_checkout_sendflags(struct cvsroot *);
+
+struct cvs_cmd_info cvs_checkout = {
+ cvs_checkout_options,
+ cvs_checkout_sendflags,
+ NULL, NULL, NULL,
+ 0,
+ CVS_REQ_CO,
+ CVS_CMD_SENDDIR | CVS_CMD_SENDARGS1 | CVS_CMD_SENDARGS2
+};
+
+static char *date, *rev, *koptstr, *tgtdir, *rcsid;
+static int statmod = 0;
+static int kflag = RCS_KWEXP_DEFAULT;
-/*
- * cvs_checkout()
- *
- * Handler for the `cvs checkout' command.
- * Returns 0 on success, or one of the known system exit codes on failure.
- */
int
-cvs_checkout(int argc, char **argv)
+cvs_checkout_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, statmod, kflag;
- char *date, *rev, *koptstr, *tgtdir, *rcsid;
- struct cvsroot *root;
+ int ch;
- statmod = 0;
- rcsid = NULL;
- tgtdir = NULL;
+ date = rev = koptstr = tgtdir = rcsid = NULL;
kflag = RCS_KWEXP_DEFAULT;
- while ((ch = getopt(argc, argv, "AcD:d:fj:k:lNnPRr:st:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'A':
break;
@@ -116,53 +121,29 @@ cvs_checkout(int argc, char **argv)
return (EX_USAGE);
}
- if ((cvs_files = cvs_file_get(".", 0)) == NULL)
- return (EX_USAGE);
+ *arg = optind;
+ return (0);
+}
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_DATAERR);
-
- /* first send the expand modules command */
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- break;
-
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0)
- cvs_log(LP_ERR, "failed to expand module");
-
- /* XXX not too sure why we have to send this arg */
- if (cvs_sendarg(root, "-N", 0) < 0)
- return (EX_PROTOCOL);
-
- if ((statmod == CVS_LISTMOD) &&
- (cvs_sendarg(root, "-c", 0) < 0))
- return (EX_PROTOCOL);
-
- if ((statmod == CVS_STATMOD) &&
- (cvs_sendarg(root, "-s", 0) < 0))
- return (EX_PROTOCOL);
-
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
-
- if ((cvs_senddir(root, cvs_files) < 0) ||
- (cvs_sendreq(root, CVS_REQ_CO, NULL) < 0)) {
- cvs_log(LP_ERR, "failed to checkout");
- return (EX_PROTOCOL);
- }
- }
+int
+cvs_checkout_sendflags(struct cvsroot *root)
+{
+ if (cvs_senddir(root, cvs_files) < 0)
+ return (EX_PROTOCOL);
+ if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0)
+ cvs_log(LP_ERR, "failed to expand module");
+
+ /* XXX not too sure why we have to send this arg */
+ if (cvs_sendarg(root, "-N", 0) < 0)
+ return (EX_PROTOCOL);
+
+ if ((statmod == CVS_LISTMOD) &&
+ (cvs_sendarg(root, "-c", 0) < 0))
+ return (EX_PROTOCOL);
+
+ if ((statmod == CVS_STATMOD) &&
+ (cvs_sendarg(root, "-s", 0) < 0))
+ return (EX_PROTOCOL);
return (0);
}
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index 2375cb8080c..d26ea940cdc 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.17 2005/03/29 15:06:01 joris Exp $ */
+/* $OpenBSD: commit.c,v 1.18 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -42,41 +42,40 @@
#include "proto.h"
+static int cvs_commit_prepare(CVSFILE *, void *);
+int cvs_commit_file(CVSFILE *, void *);
+int cvs_commit_options(char *, int, char **, int *);
+int cvs_commit_helper(void);
+struct cvs_cmd_info cvs_commit = {
+ cvs_commit_options,
+ NULL,
+ cvs_commit_file,
+ NULL,
+ cvs_commit_helper,
+ CF_RECURSE | CF_IGNORE | CF_SORT,
+ CVS_REQ_CI,
+ CVS_CMD_NEEDLOG | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
+};
-int cvs_commit_prepare (CVSFILE *, void *);
-int cvs_commit_file (CVSFILE *, void *);
+static char *mfile = NULL;
-
-/*
- * cvs_commit()
- *
- * Handler for the `cvs commit' command.
- */
int
-cvs_commit(int argc, char **argv)
+cvs_commit_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, flags;
- char *mfile;
- struct cvs_flist cl;
- CVSFILE *cfp;
- struct cvsroot *root;
-
- flags = CF_RECURSE|CF_IGNORE|CF_SORT;
- mfile = NULL;
- TAILQ_INIT(&cl);
+ int ch;
- while ((ch = getopt(argc, argv, "F:flm:Rr:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'F':
mfile = optarg;
break;
case 'f':
/* XXX half-implemented */
- flags &= ~CF_RECURSE;
+ cvs_commit.file_flags &= ~CF_RECURSE;
break;
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_commit.file_flags &= ~CF_RECURSE;
break;
case 'm':
cvs_msg = strdup(optarg);
@@ -86,7 +85,7 @@ cvs_commit(int argc, char **argv)
}
break;
case 'R':
- flags |= CF_RECURSE;
+ cvs_commit.file_flags |= CF_RECURSE;
break;
default:
return (EX_USAGE);
@@ -101,17 +100,17 @@ cvs_commit(int argc, char **argv)
if ((mfile != NULL) && (cvs_msg = cvs_logmsg_open(mfile)) == NULL)
return (EX_DATAERR);
- argc -= optind;
- argv += optind;
+ *arg = optind;
+ return (0);
+}
- if (argc == 0) {
- cvs_files = cvs_file_get(".", flags);
- } else {
- cvs_files = cvs_file_getspec(argv, argc, flags);
- }
- if (cvs_files == NULL)
- return (EX_DATAERR);
+int
+cvs_commit_helper(void)
+{
+ struct cvs_flist cl;
+ CVSFILE *cfp;
+ TAILQ_INIT(&cl);
cvs_file_examine(cvs_files, cvs_commit_prepare, &cl);
if (TAILQ_EMPTY(&cl))
return (0);
@@ -129,34 +128,9 @@ cvs_commit(int argc, char **argv)
if (cvs_msg == NULL)
return (1);
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
- if ((root->cr_method != CVS_METHOD_LOCAL) &&
- ((cvs_connect(root) < 0) || (cvs_logmsg_send(root, cvs_msg) < 0)))
- return (EX_PROTOCOL);
-
- cvs_file_examine(cvs_files, cvs_commit_file, &cl);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_CI, NULL) < 0)
- return (EX_PROTOCOL);
- }
-
return (0);
}
-
/*
* cvs_commit_prepare()
*
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c
index ae7c8ab32d2..bad1d2bce23 100644
--- a/usr.bin/cvs/cvs.c
+++ b/usr.bin/cvs/cvs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.c,v 1.44 2005/03/24 01:21:49 jfb Exp $ */
+/* $OpenBSD: cvs.c,v 1.45 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -87,90 +87,90 @@ static TAILQ_HEAD(, cvs_var) cvs_variables;
*/
struct cvs_cmd cvs_cdt[] = {
{
- CVS_OP_ADD, "add", { "ad", "new" }, cvs_add,
+ CVS_OP_ADD, "add", { "ad", "new" }, &cvs_add,
"[-k opt] [-m msg] file ...",
"k:m:",
"Add a new file/directory to the repository",
- NULL, NULL
+ NULL
},
{
- CVS_OP_ADMIN, "admin", { "adm", "rcs" }, cvs_admin,
- "",
+ CVS_OP_ADMIN, "admin", { "adm", "rcs" }, &cvs_admin,
"",
+ "a:A:b::c:e::Ik:l::Lm:n:N:o:qs:t:u::U",
"Administration front end for rcs",
- NULL, NULL
+ NULL
},
{
- CVS_OP_ANNOTATE, "annotate", { "ann" }, cvs_annotate,
+ CVS_OP_ANNOTATE, "annotate", { "ann" }, &cvs_annotate,
"[-flR] [-D date | -r rev] ...",
"D:flRr:",
"Show last revision where each line was modified",
- NULL, NULL
+ NULL
},
{
- CVS_OP_CHECKOUT, "checkout", { "co", "get" }, cvs_checkout,
+ CVS_OP_CHECKOUT, "checkout", { "co", "get" }, &cvs_checkout,
"[-AcflNnPpRs] [-D date | -r rev] [-d dir] [-j rev] [-k mode] "
"[-t id] module ...",
"AcD:d:fj:k:lNnPRr:st:",
"Checkout sources for editing",
- NULL, NULL
+ NULL
},
{
- CVS_OP_COMMIT, "commit", { "ci", "com" }, cvs_commit,
+ CVS_OP_COMMIT, "commit", { "ci", "com" }, &cvs_commit,
"[-flR] [-F logfile | -m msg] [-r rev] ...",
"F:flm:Rr:",
"Check files into the repository",
- NULL, NULL
+ NULL
},
{
- CVS_OP_DIFF, "diff", { "di", "dif" }, cvs_diff,
+ CVS_OP_DIFF, "diff", { "di", "dif" }, &cvs_diff,
"[-cilNpu] [-D date] [-r rev] ...",
"cD:ilNpr:u",
"Show differences between revisions",
- NULL, NULL
+ NULL
},
{
CVS_OP_EDIT, "edit", { }, NULL,
"",
"",
"Get ready to edit a watched file",
- NULL, NULL
+ NULL
},
{
CVS_OP_EDITORS, "editors", { }, NULL,
"",
"",
"See who is editing a watched file",
- NULL, NULL
+ NULL
},
{
CVS_OP_EXPORT, "export", { "ex", "exp" }, NULL,
"",
"",
"Export sources from CVS, similar to checkout",
- NULL, NULL
+ NULL
},
{
- CVS_OP_HISTORY, "history", { "hi", "his" }, cvs_history,
- "",
+ CVS_OP_HISTORY, "history", { "hi", "his" }, &cvs_history,
"",
+ "acelm:oTt:u:wx:z:",
"Show repository access history",
- NULL, NULL
+ NULL
},
{
- CVS_OP_IMPORT, "import", { "im", "imp" }, cvs_import,
+ CVS_OP_IMPORT, "import", { "im", "imp" }, &cvs_import,
"[-d] [-b branch] [-I ign] [-k subst] [-m msg] "
"repository vendor-tag release-tags ...",
"b:dI:k:m:",
"Import sources into CVS, using vendor branches",
- NULL, NULL
+ NULL
},
{
- CVS_OP_INIT, "init", { }, cvs_init,
+ CVS_OP_INIT, "init", { }, &cvs_init,
"",
"",
"Create a CVS repository if it doesn't exist",
- NULL, NULL
+ NULL
},
#if defined(HAVE_KERBEROS)
{
@@ -178,120 +178,120 @@ struct cvs_cmd cvs_cdt[] = {
"",
"",
"Start a Kerberos authentication CVS server",
- NULL, NULL
+ NULL
},
#endif
{
- CVS_OP_LOG, "log", { "lo" }, cvs_getlog,
+ CVS_OP_LOG, "log", { "lo" }, &cvs_getlog,
"[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
- "",
+ "d:hlRr:",
"Print out history information for files",
- NULL, NULL
+ NULL
},
{
-1, "login", {}, NULL,
"",
"",
"Prompt for password for authenticating server",
- NULL, NULL
+ NULL
},
{
-1, "logout", {}, NULL,
"",
"",
"Removes entry in .cvspass for remote repository",
- NULL, NULL
+ NULL
},
{
CVS_OP_RDIFF, "rdiff", {}, NULL,
"",
"",
"Create 'patch' format diffs between releases",
- NULL, NULL
+ NULL
},
{
CVS_OP_RELEASE, "release", {}, NULL,
"[-d]",
"d",
"Indicate that a Module is no longer in use",
- NULL, NULL
+ NULL
},
{
- CVS_OP_REMOVE, "remove", { "rm", "delete" }, cvs_remove,
+ CVS_OP_REMOVE, "remove", { "rm", "delete" }, &cvs_remove,
"[-flR] file ...",
"flR",
"Remove an entry from the repository",
- NULL, NULL
+ NULL
},
{
CVS_OP_RLOG, "rlog", {}, NULL,
"",
"",
"Print out history information for a module",
- NULL, NULL
+ NULL
},
{
CVS_OP_RTAG, "rtag", {}, NULL,
"",
"",
"Add a symbolic tag to a module",
- NULL, NULL
+ NULL
},
{
- CVS_OP_SERVER, "server", {}, cvs_server,
+ CVS_OP_SERVER, "server", {}, NULL,
"",
"",
"Server mode",
- NULL, NULL
+ NULL
},
{
- CVS_OP_STATUS, "status", { "st", "stat" }, cvs_status,
+ CVS_OP_STATUS, "status", { "st", "stat" }, &cvs_status,
"[-lRv]",
"lRv",
"Display status information on checked out files",
- NULL, NULL
+ NULL
},
{
- CVS_OP_TAG, "tag", { "ta", "freeze" }, cvs_tag,
+ CVS_OP_TAG, "tag", { "ta", "freeze" }, &cvs_tag,
"[-bcdFflR] [-D date | -r rev] tagname",
"bcD:dFflRr:",
"Add a symbolic tag to checked out version of files",
- NULL, NULL
+ NULL
},
{
CVS_OP_UNEDIT, "unedit", {}, NULL,
"",
"",
"Undo an edit command",
- NULL, NULL
+ NULL
},
{
- CVS_OP_UPDATE, "update", { "up", "upd" }, cvs_update,
+ CVS_OP_UPDATE, "update", { "up", "upd" }, &cvs_update,
"[-ACdflPpR] [-D date | -r rev] [-I ign] [-j rev] [-k mode] "
"[-t id] ...",
- "",
+ "ACD:dflPpQqRr:",
"Bring work tree in sync with repository",
- NULL, NULL
+ NULL
},
{
- CVS_OP_VERSION, "version", { "ve", "ver" }, cvs_version,
+ CVS_OP_VERSION, "version", { "ve", "ver" }, &cvs_version,
"", "",
"Show current CVS version(s)",
- NULL, NULL
+ NULL
},
{
CVS_OP_WATCH, "watch", {}, NULL,
"",
"",
"Set watches",
- NULL, NULL
+ NULL
},
{
CVS_OP_WATCHERS, "watchers", {}, NULL,
"",
"",
"See who is watching a file",
- NULL, NULL
+ NULL
},
};
@@ -398,7 +398,7 @@ main(int argc, char **argv)
exit(EX_USAGE);
}
- if (cmdp->cmd_hdlr == NULL) {
+ if (cmdp->cmd_info == NULL) {
cvs_log(LP_ERR, "command `%s' not implemented", cvs_command);
exit(1);
}
@@ -423,12 +423,14 @@ main(int argc, char **argv)
for (ret = 1; ret < argc; ret++)
cmd_argv[cmd_argc++] = argv[ret];
- ret = (*cmdp->cmd_hdlr)(cmd_argc, cmd_argv);
+ ret = cvs_startcmd(cmdp, cmd_argc, cmd_argv);
if (ret == EX_USAGE) {
fprintf(stderr, "Usage: %s %s %s\n", __progname, cvs_command,
cmdp->cmd_synopsis);
}
+ if (cmdp->cmd_info->cmd_cleanup != NULL)
+ cmdp->cmd_info->cmd_cleanup();
if (cvs_files != NULL)
cvs_file_free(cvs_files);
if (cvs_msg != NULL)
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 8ca318c9a90..5094c2fead1 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.46 2005/03/24 01:03:41 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.47 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -165,12 +165,11 @@ struct cvs_cmd {
int cmd_op;
char cmd_name[CVS_CMD_MAXNAMELEN];
char cmd_alias[CVS_CMD_MAXALIAS][CVS_CMD_MAXNAMELEN];
- int (*cmd_hdlr)(int, char **);
+ struct cvs_cmd_info *cmd_info;
char *cmd_synopsis;
char *cmd_opts;
char cmd_descr[CVS_CMD_MAXDESCRLEN];
char *cmd_defargs;
- struct cvs_cmd_info *cmd_info;
};
struct cvs_file;
@@ -318,23 +317,24 @@ extern CVSFILE *cvs_files;
/* client command handlers */
+extern struct cvs_cmd_info cvs_add;
+extern struct cvs_cmd_info cvs_admin;
+extern struct cvs_cmd_info cvs_annotate;
+extern struct cvs_cmd_info cvs_checkout;
+extern struct cvs_cmd_info cvs_commit;
+extern struct cvs_cmd_info cvs_diff;
+extern struct cvs_cmd_info cvs_getlog;
+extern struct cvs_cmd_info cvs_history;
+extern struct cvs_cmd_info cvs_import;
+extern struct cvs_cmd_info cvs_init;
+extern struct cvs_cmd_info cvs_remove;
+extern struct cvs_cmd_info cvs_status;
+extern struct cvs_cmd_info cvs_tag;
+extern struct cvs_cmd_info cvs_update;
+extern struct cvs_cmd_info cvs_version;
+
int cvs_startcmd (struct cvs_cmd *, int, char **);
-int cvs_add (int, char **);
-int cvs_admin (int, char **);
-int cvs_annotate (int, char **);
-int cvs_checkout (int, char **);
-int cvs_commit (int, char **);
-int cvs_diff (int, char **);
-int cvs_getlog (int, char **);
-int cvs_history (int, char **);
-int cvs_import (int, char **);
-int cvs_init (int, char **);
-int cvs_remove (int, char **);
int cvs_server (int, char **);
-int cvs_status (int, char **);
-int cvs_tag (int, char **);
-int cvs_update (int, char **);
-int cvs_version (int, char **);
int cvs_var_set (const char *, const char *);
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index 2deefe08358..38fa4df1ff2 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.22 2005/02/27 00:22:08 jfb Exp $ */
+/* $OpenBSD: diff.c,v 1.23 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -213,9 +213,12 @@ struct excludes {
char *splice(char *, char *);
+int cvs_diff_options(char *, int, char **, int *);
int cvs_diffreg(const char *, const char *);
int cvs_diff_file(struct cvs_file *, void *);
-int cvs_diff_sendflags(struct cvsroot *, struct diff_arg *);
+int cvs_diff_sendflags(struct cvsroot *);
+int cvs_diff_cleanup(void);
+
static void output(const char *, FILE *, const char *, FILE *);
static void check(FILE *, FILE *);
static void range(int, int, char *);
@@ -337,40 +340,43 @@ u_char cup2low[256] = {
0xfd, 0xfe, 0xff
};
+struct cvs_cmd_info cvs_diff = {
+ cvs_diff_options,
+ cvs_diff_sendflags,
+ cvs_diff_file,
+ cvs_diff_cleanup,
+ NULL,
+ CF_RECURSE | CF_IGNORE | CF_SORT | CF_KNOWN,
+ CVS_REQ_DIFF,
+ CVS_CMD_SENDDIR
+};
+
+static struct diff_arg *dap = NULL;
+static int recurse;
-/*
- * cvs_diff()
- *
- * Handler for the `cvs diff' command.
- *
- * SYNOPSIS: cvs [args] diff [-clipu] [-D date] [-r rev]
- */
int
-cvs_diff(int argc, char **argv)
+cvs_diff_options(char *opt, int argc, char **argv, int *arg)
{
- int ch, recurse, flags;
- struct diff_arg darg;
- struct cvsroot *root;
-
- context = CVS_DIFF_DEFCTX;
- flags = CF_RECURSE|CF_IGNORE|CF_SORT|CF_KNOWN;
- recurse = 1;
+ int ch;
- memset(&darg, 0, sizeof(darg));
+ dap = (struct diff_arg *)malloc(sizeof(*dap));
+ if (dap == NULL)
+ return (EX_DATAERR);
+ dap->date1 = dap->date2 = dap->rev1 = dap->rev2 = NULL;
strlcpy(diffargs, argv[0], sizeof(diffargs));
- while ((ch = getopt(argc, argv, "cD:liNpr:u")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'c':
strlcat(diffargs, " -c", sizeof(diffargs));
format = D_CONTEXT;
break;
case 'D':
- if (darg.date1 == NULL && darg.rev1 == NULL)
- darg.date1 = optarg;
- else if (darg.date2 == NULL && darg.rev2 == NULL)
- darg.date2 = optarg;
- else {
+ if (dap->date1 == NULL && dap->rev1 == NULL) {
+ dap->date1 = optarg;
+ } else if (dap->date2 == NULL && dap->rev2 == NULL) {
+ dap->date2 = optarg;
+ } else {
cvs_log(LP_ERR,
"no more than two revisions/dates can "
"be specified");
@@ -379,7 +385,7 @@ cvs_diff(int argc, char **argv)
case 'l':
strlcat(diffargs, " -l", sizeof(diffargs));
recurse = 0;
- flags &= ~CF_RECURSE;
+ cvs_diff.file_flags &= ~CF_RECURSE;
break;
case 'i':
strlcat(diffargs, " -i", sizeof(diffargs));
@@ -394,11 +400,12 @@ cvs_diff(int argc, char **argv)
pflag = 1;
break;
case 'r':
- if ((darg.rev1 == NULL) && (darg.date1 == NULL))
- darg.rev1 = optarg;
- else if ((darg.rev2 == NULL) && (darg.date2 == NULL))
- darg.rev2 = optarg;
- else {
+ if ((dap->rev1 == NULL) && (dap->date1 == NULL)) {
+ dap->rev1 = optarg;
+ } else if ((dap->rev2 == NULL) &&
+ (dap->date2 == NULL)) {
+ dap->rev2 = optarg;
+ } else {
cvs_log(LP_ERR,
"no more than two revisions/dates can "
"be specified");
@@ -414,34 +421,24 @@ cvs_diff(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- cvs_files = cvs_file_get(".", flags);
- } else
- cvs_files = cvs_file_getspec(argv, argc, 0);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- cvs_file_examine(cvs_files, cvs_diff_file, &darg);
-
- root = cvs_files->cf_ddat->cd_root;
- if (root->cr_method != CVS_METHOD_LOCAL) {
- cvs_senddir(root, cvs_files);
- cvs_sendreq(root, CVS_REQ_DIFF, NULL);
- }
-
+ *arg = optind;
return (0);
}
+int
+cvs_diff_cleanup(void)
+{
+ if (dap != NULL)
+ free(dap);
+ return (0);
+}
/*
* cvs_diff_sendflags()
*
*/
int
-cvs_diff_sendflags(struct cvsroot *root, struct diff_arg *dap)
+cvs_diff_sendflags(struct cvsroot *root)
{
/* send the flags */
if (Nflag && (cvs_sendarg(root, "-N", 0) < 0))
@@ -487,12 +484,9 @@ cvs_diff_file(struct cvs_file *cfp, void *arg)
BUF *b1, *b2;
RCSNUM *r1, *r2;
RCSFILE *rf;
- struct diff_arg *dap;
struct cvs_ent *entp;
struct cvsroot *root;
- dap = (struct diff_arg *)arg;
-
if (cfp->cf_type == DT_DIR) {
if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
root = cfp->cf_parent->cf_ddat->cd_root;
@@ -500,11 +494,13 @@ cvs_diff_file(struct cvs_file *cfp, void *arg)
CVS_FILE_NAME(cfp));
} else {
root = cfp->cf_ddat->cd_root;
+#if 0
if ((cfp->cf_parent == NULL) ||
(root != cfp->cf_parent->cf_ddat->cd_root)) {
cvs_connect(root);
- cvs_diff_sendflags(root, dap);
+ cvs_diff_sendflags(root);
}
+#endif
cvs_senddir(root, cfp);
}
diff --git a/usr.bin/cvs/getlog.c b/usr.bin/cvs/getlog.c
index 7242718b2a3..166cbc8abd2 100644
--- a/usr.bin/cvs/getlog.c
+++ b/usr.bin/cvs/getlog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getlog.c,v 1.15 2005/03/26 08:09:54 tedu Exp $ */
+/* $OpenBSD: getlog.c,v 1.16 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -53,32 +53,35 @@ static void cvs_getlog_print (const char *, RCSFILE *, u_int);
#endif
static int cvs_getlog_file (CVSFILE *, void *);
+int cvs_getlog_options(char *, int, char **, int *);
+struct cvs_cmd_info cvs_getlog = {
+ cvs_getlog_options,
+ NULL,
+ cvs_getlog_file,
+ NULL, NULL,
+ CF_RECURSE,
+ CVS_REQ_LOG,
+ CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
+};
+
+static int rfonly = 0;
+static int honly = 0;
-/*
- * cvs_getlog()
- *
- * Implement the `cvs log' command.
- */
int
-cvs_getlog(int argc, char **argv)
+cvs_getlog_options(char *opt, int argc, char **argv, int *arg)
{
- int i, rfonly, honly, flags;
- struct cvsroot *root;
-
- flags = CF_RECURSE;
- rfonly = 0;
- honly = 0;
+ int ch;
- while ((i = getopt(argc, argv, "d:hlRr:")) != -1) {
- switch (i) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
+ switch (ch) {
case 'd':
break;
case 'h':
honly = 1;
break;
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_getlog.file_flags &= ~CF_RECURSE;
break;
case 'R':
rfonly = 1;
@@ -90,39 +93,7 @@ cvs_getlog(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
-
- if (argc == 0)
- cvs_files = cvs_file_get(".", flags);
- else
- cvs_files = cvs_file_getspec(argv, argc, flags);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
-
- if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
- return (EX_PROTOCOL);
-
- cvs_file_examine(cvs_files, cvs_getlog_file, NULL);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- cvs_senddir(root, cvs_files);
- if (argc > 0) {
- for (i = 0; i < argc; i++)
- cvs_sendarg(root, argv[i], 0);
- }
- cvs_sendreq(root, CVS_REQ_LOG, NULL);
- }
-
+ *arg = optind;
return (0);
}
diff --git a/usr.bin/cvs/history.c b/usr.bin/cvs/history.c
index cdd47a4d874..309dd2711a4 100644
--- a/usr.bin/cvs/history.c
+++ b/usr.bin/cvs/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.8 2005/02/28 20:45:07 joris Exp $ */
+/* $OpenBSD: history.c,v 1.9 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -55,35 +55,36 @@
#define CVS_HF_EXCL (CVS_HF_C|CVS_HF_E|CVS_HF_M|CVS_HF_O|CVS_HF_T|CVS_HF_X)
static void cvs_history_print (struct cvs_hent *);
-
+int cvs_history_options(char *, int, char **, int *);
+int cvs_history_sendflags(struct cvsroot *);
extern char *__progname;
+struct cvs_cmd_info cvs_history = {
+ cvs_history_options,
+ cvs_history_sendflags,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ CVS_REQ_HISTORY,
+ CVS_CMD_SENDDIR
+};
+
+static int flags = 0;
+static char *user = NULL;
+static char *zone = "+0000";
+static char *tag = NULL;
+static u_int nbmod = 0;
+static u_int rep = 0;
+static char *modules[CVS_HISTORY_MAXMOD];
-/*
- * cvs_history()
- *
- * Handle the `cvs history' command.
- */
int
-cvs_history(int argc, char **argv)
+cvs_history_options(char *opt, int argc, char **argv, int *arg)
{
- int ch, flags;
- u_int nbmod, rep;
- char *user, *zone, *tag, *cp;
- char *modules[CVS_HISTORY_MAXMOD], histpath[MAXPATHLEN];
- struct cvsroot *root;
- struct cvs_hent *hent;
- CVSHIST *hp;
-
- tag = NULL;
- user = NULL;
- zone = "+0000";
- nbmod = 0;
- flags = 0;
- rep = 0;
-
- while ((ch = getopt(argc, argv, "acelm:oTt:u:wx:z:")) != -1) {
+ int ch;
+
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'a':
flags |= CVS_HF_A;
@@ -127,8 +128,6 @@ cvs_history(int argc, char **argv)
break;
case 'x':
rep++;
- for (cp = optarg; *cp != '\0'; cp++) {
- }
break;
case 'z':
zone = optarg;
@@ -145,55 +144,36 @@ cvs_history(int argc, char **argv)
} else if (rep == 0)
flags |= CVS_HF_O; /* use -o as default */
- root = cvsroot_get(".");
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
- if (root->cr_method == CVS_METHOD_LOCAL) {
- snprintf(histpath, sizeof(histpath), "%s/%s", root->cr_dir,
- CVS_PATH_HISTORY);
- hp = cvs_hist_open(histpath);
- if (hp == NULL) {
- return (EX_UNAVAILABLE);
- }
-
- while ((hent = cvs_hist_getnext(hp)) != NULL) {
- cvs_history_print(hent);
- }
- cvs_hist_close(hp);
- } else {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
+ *arg = optind;
+ return (0);
+}
- if ((flags & CVS_HF_C) && (cvs_sendarg(root, "-c", 0) < 0))
- return (EX_PROTOCOL);
+int
+cvs_history_sendflags(struct cvsroot *root)
+{
- if ((flags & CVS_HF_O) && (cvs_sendarg(root, "-o", 0) < 0))
- return (EX_PROTOCOL);
+ if ((flags & CVS_HF_C) && (cvs_sendarg(root, "-c", 0) < 0))
+ return (EX_PROTOCOL);
- if (tag != NULL) {
- if ((cvs_sendarg(root, "-t", 0) < 0) ||
- (cvs_sendarg(root, tag, 0) < 0))
- return (EX_PROTOCOL);
- }
- if (user != NULL) {
- if ((cvs_sendarg(root, "-u", 0) < 0) ||
- (cvs_sendarg(root, user, 0) < 0))
- return (EX_PROTOCOL);
- }
+ if ((flags & CVS_HF_O) && (cvs_sendarg(root, "-o", 0) < 0))
+ return (EX_PROTOCOL);
- if ((cvs_sendarg(root, "-z", 0) < 0) ||
- (cvs_sendarg(root, zone, 0) < 0))
+ if (tag != NULL) {
+ if ((cvs_sendarg(root, "-t", 0) < 0) ||
+ (cvs_sendarg(root, tag, 0) < 0))
return (EX_PROTOCOL);
+ }
- if (cvs_sendreq(root, CVS_REQ_HISTORY, NULL) < 0)
+ if (user != NULL) {
+ if ((cvs_sendarg(root, "-u", 0) < 0) ||
+ (cvs_sendarg(root, user, 0) < 0))
return (EX_PROTOCOL);
}
+ if ((cvs_sendarg(root, "-z", 0) < 0) ||
+ (cvs_sendarg(root, zone, 0) < 0))
+ return (EX_PROTOCOL);
+
return (0);
}
diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c
index fa38f13e020..6a074943601 100644
--- a/usr.bin/cvs/import.c
+++ b/usr.bin/cvs/import.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: import.c,v 1.6 2005/03/05 18:43:55 joris Exp $ */
+/* $OpenBSD: import.c,v 1.7 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -44,28 +44,29 @@
#define CVS_IMPORT_DEFBRANCH "1.1.1"
+int cvs_import_options(char *, int, char **, int *);
+int cvs_import_sendflags(struct cvsroot *);
+int cvs_import_file(CVSFILE *, void *);
+static RCSNUM *bnum;
+static char *branch, *module, *vendor, *release;
-int cvs_import_file(CVSFILE *, void *);
-char repo[MAXPATHLEN];
+struct cvs_cmd_info cvs_import = {
+ cvs_import_options,
+ cvs_import_sendflags,
+ cvs_import_file,
+ NULL, NULL,
+ CF_RECURSE | CF_IGNORE | CF_NOSYMS,
+ CVS_REQ_IMPORT,
+ CVS_CMD_SENDDIR
+};
-/*
- * cvs_import()
- *
- * Handler for the `cvs import' command.
- */
int
-cvs_import(int argc, char **argv)
+cvs_import_options(char *opt, int argc, char **argv, int *arg)
{
- int ch, flags;
- char *branch;
- struct cvsroot *root;
- RCSNUM *bnum;
-
- branch = CVS_IMPORT_DEFBRANCH;
- flags = CF_RECURSE | CF_IGNORE | CF_NOSYMS;
+ int ch;
- while ((ch = getopt(argc, argv, "b:dI:k:m:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'b':
branch = optarg;
@@ -101,45 +102,33 @@ cvs_import(int argc, char **argv)
argc -= optind;
argv += optind;
+ *arg = optind;
+
if (argc > 4)
return (EX_USAGE);
- cvs_files = cvs_file_get(".", flags);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
+ module = argv[0];
+ vendor = argv[1];
+ release = argv[2];
if ((cvs_msg == NULL) &&
(cvs_msg = cvs_logmsg_get(NULL, NULL, NULL, NULL)) == NULL)
return (-1);
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if ((cvs_connect(root) < 0) ||
- (cvs_sendarg(root, "-b", 0) < 0) ||
- (cvs_sendarg(root, branch, 0) < 0) ||
- (cvs_logmsg_send(root, cvs_msg) < 0) ||
- (cvs_sendarg(root, argv[0], 0) < 0) ||
- (cvs_sendarg(root, argv[1], 0) < 0) ||
- (cvs_sendarg(root, argv[2], 0) < 0))
- return (EX_PROTOCOL);
- }
-
- snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, argv[0]);
- cvs_file_examine(cvs_files, cvs_import_file, NULL);
+ return (0);
+}
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0 ||
- cvs_sendreq(root, CVS_REQ_IMPORT, NULL) < 0)
- return (EX_PROTOCOL);
- }
+int
+cvs_import_sendflags(struct cvsroot *root)
+{
+ if ((cvs_connect(root) < 0) ||
+ (cvs_sendarg(root, "-b", 0) < 0) ||
+ (cvs_sendarg(root, branch, 0) < 0) ||
+ (cvs_logmsg_send(root, cvs_msg) < 0) ||
+ (cvs_sendarg(root, module, 0) < 0) ||
+ (cvs_sendarg(root, vendor, 0) < 0) ||
+ (cvs_sendarg(root, release, 0) < 0))
+ return (EX_PROTOCOL);
return (0);
}
@@ -155,8 +144,10 @@ cvs_import_file(CVSFILE *cfp, void *arg)
int ret;
struct cvsroot *root;
char fpath[MAXPATHLEN], repodir[MAXPATHLEN];
+ char repo[MAXPATHLEN];
root = CVS_DIR_ROOT(cfp);
+ snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, module);
cvs_file_getpath(cfp, fpath, sizeof(fpath));
printf("Importing %s\n", fpath);
diff --git a/usr.bin/cvs/init.c b/usr.bin/cvs/init.c
index a9b39868007..453cebf765f 100644
--- a/usr.bin/cvs/init.c
+++ b/usr.bin/cvs/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.11 2005/03/01 21:14:21 jfb Exp $ */
+/* $OpenBSD: init.c,v 1.12 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -66,45 +66,29 @@ struct cvsroot_file {
{ CVS_PATH_VERIFYMSG, CFT_FILE, (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) },
};
+int cvs_init_local(struct cvsroot *);
+
+struct cvs_cmd_info cvs_init = {
+ NULL,
+ NULL, NULL, NULL, NULL,
+ 0,
+ CVS_REQ_INIT,
+ 0
+};
/*
- * cvs_init()
+ * cvs_init_local()
*
- * Handler for the `cvs init' command which is used to initialize a CVS
- * repository.
+ * Local handler for the "cvs init" command.
* Returns 0 on success, or the appropriate exit status on failure.
*/
int
-cvs_init(int argc, char **argv)
+cvs_init_local(struct cvsroot *root)
{
int fd;
u_int i;
char path[MAXPATHLEN];
RCSFILE *rfp;
- struct cvsroot *root;
-
- if (argc != 1)
- return (EX_USAGE);
-
- root = cvsroot_get(".");
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_DATAERR);
-
- if (cvs_sendreq(root, CVS_REQ_INIT, root->cr_dir) < 0)
- return (EX_DATAERR);
-
- cvs_disconnect(root);
- return (0);
- }
for (i = 0; i < sizeof(cvsroot_files)/sizeof(cvsroot_files[i]); i++) {
snprintf(path, sizeof(path), "%s/%s", root->cr_dir,
diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c
index f155f69dc7f..bb0ae6b904e 100644
--- a/usr.bin/cvs/proto.c
+++ b/usr.bin/cvs/proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.c,v 1.44 2005/03/26 08:09:54 tedu Exp $ */
+/* $OpenBSD: proto.c,v 1.45 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -961,7 +961,7 @@ cvs_senddir(struct cvsroot *root, CVSFILE *dir)
char lbuf[MAXPATHLEN], rbuf[MAXPATHLEN];
cvs_file_getpath(dir, lbuf, sizeof(lbuf));
- if (strcmp(lbuf, cvs_lastdir) == 0)
+ if (strcmp(lbuf, cvs_lastdir) == 0 && cvs_cmdop != CVS_OP_CHECKOUT)
return (0);
if (dir->cf_ddat->cd_repo == NULL)
diff --git a/usr.bin/cvs/remove.c b/usr.bin/cvs/remove.c
index b3871f3d2a1..904183defe2 100644
--- a/usr.bin/cvs/remove.c
+++ b/usr.bin/cvs/remove.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: remove.c,v 1.3 2005/03/09 15:24:36 xsa Exp $ */
+/* $OpenBSD: remove.c,v 1.4 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2004 Xavier Santolaria <xsa@openbsd.org>
@@ -44,23 +44,27 @@
extern char *__progname;
-int cvs_remove_file (CVSFILE *, void *);
+int cvs_remove_file(CVSFILE *, void *);
+int cvs_remove_options(char *, int, char **, int *);
-int force_remove = 0; /* -f option */
+static int force_remove = 0; /* -f option */
+
+struct cvs_cmd_info cvs_remove = {
+ cvs_remove_options,
+ NULL,
+ cvs_remove_file,
+ NULL, NULL,
+ 0,
+ CVS_REQ_REMOVE,
+ CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2 | CVS_CMD_ALLOWSPEC
+};
-/*
- * cvs_remove()
- *
- * Handler for the `cvs remove' command.
- * Returns 0 on success, or one of the known system exit codes on failure.
- */
int
-cvs_remove(int argc, char **argv)
+cvs_remove_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch;
- struct cvsroot *root;
+ int ch;
- while ((ch = getopt(argc, argv, "flR")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'f':
force_remove = 1;
@@ -80,36 +84,7 @@ cvs_remove(int argc, char **argv)
if (argc == 0)
return (EX_USAGE);
- cvs_files = cvs_file_getspec(argv, argc, 0);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
-
- if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
- return (EX_PROTOCOL);
-
- cvs_file_examine(cvs_files, cvs_remove_file, NULL);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
-
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
-
- if (cvs_sendreq(root, CVS_REQ_REMOVE, NULL) < 0)
- return (EX_PROTOCOL);
- }
-
+ *arg = optind;
return (0);
}
diff --git a/usr.bin/cvs/status.c b/usr.bin/cvs/status.c
index edb0e62bfba..ac6192362ea 100644
--- a/usr.bin/cvs/status.c
+++ b/usr.bin/cvs/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.9 2005/03/26 08:09:54 tedu Exp $ */
+/* $OpenBSD: status.c,v 1.10 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -51,31 +51,34 @@ const char *cvs_statstr[] = {
};
-int cvs_status_file (CVSFILE *, void *);
+int cvs_status_file(CVSFILE *, void *);
+int cvs_status_options(char *, int, char **, int *);
+int cvs_status_sendflags(struct cvsroot *);
+struct cvs_cmd_info cvs_status = {
+ cvs_status_options,
+ cvs_status_sendflags,
+ cvs_status_file,
+ NULL, NULL,
+ CF_SORT | CF_IGNORE | CF_RECURSE,
+ CVS_REQ_STATUS,
+ CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
+};
+
+static int verbose = 0;
-/*
- * cvs_status()
- *
- * Handler for the `cvs status' command.
- * Returns 0 on success, or one of the known exit codes on error.
- */
int
-cvs_status(int argc, char **argv)
+cvs_status_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, flags, verbose;
- struct cvsroot *root;
+ int ch;
- verbose = 0;
- flags = CF_SORT|CF_IGNORE|CF_RECURSE;
-
- while ((ch = getopt(argc, argv, "lRv")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_status.file_flags &= ~CF_RECURSE;
break;
case 'R':
- flags |= CF_RECURSE;
+ cvs_status.file_flags |= CF_RECURSE;
break;
case 'v':
verbose = 1;
@@ -85,48 +88,17 @@ cvs_status(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- cvs_files = cvs_file_get(".", flags);
- } else {
- cvs_files = cvs_file_getspec(argv, argc, 0);
- }
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
- if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
- return (EX_PROTOCOL);
- }
-
- cvs_file_examine(cvs_files, cvs_status_file, NULL);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_STATUS, NULL) < 0)
- return (EX_PROTOCOL);
- }
-
+ *arg = optind;
return (0);
}
+int
+cvs_status_sendflags(struct cvsroot *root)
+{
+ if (verbose && (cvs_sendarg(root, "-v", 0) < 0))
+ return (EX_PROTOCOL);
+ return (0);
+}
/*
* cvs_status_file()
diff --git a/usr.bin/cvs/tag.c b/usr.bin/cvs/tag.c
index 967ecf9f04e..d7d44adeab9 100644
--- a/usr.bin/cvs/tag.c
+++ b/usr.bin/cvs/tag.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tag.c,v 1.6 2005/03/26 08:09:54 tedu Exp $ */
+/* $OpenBSD: tag.c,v 1.7 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2004 Joris Vink <joris@openbsd.org>
@@ -41,28 +41,32 @@
#include "proto.h"
-int cvs_tag_file (CVSFILE *, void *);
+int cvs_tag_file(CVSFILE *, void *);
+int cvs_tag_options(char *, int, char **, int *);
+int cvs_tag_sendflags(struct cvsroot *);
+static char *tag, *old_tag, *date;
+static int branch, delete;
+
+struct cvs_cmd_info cvs_tag = {
+ cvs_tag_options,
+ cvs_tag_sendflags,
+ cvs_tag_file,
+ NULL, NULL,
+ CF_SORT | CF_IGNORE | CF_RECURSE,
+ CVS_REQ_TAG,
+ CVS_CMD_ALLOWSPEC
+};
-/*
- * cvs_tag()
- *
- * Handler for the `cvs tag' command.
- * Returns 0 on success, or one of the known exit codes on error.
- */
int
-cvs_tag(int argc, char **argv)
+cvs_tag_options(char *opt, int argc, char **argv, int *arg)
{
- int ch, flags;
- struct cvsroot *root;
- char *tag, *old_tag, *date;
- int branch, delete;
+ int ch;
date = old_tag = NULL;
branch = delete = 0;
- flags = CF_SORT|CF_IGNORE|CF_RECURSE;
- while ((ch = getopt(argc, argv, "bdD:lr:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'b':
branch = 1;
@@ -74,7 +78,7 @@ cvs_tag(int argc, char **argv)
date = optarg;
break;
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_tag.file_flags &= ~CF_RECURSE;
break;
case 'r':
old_tag = optarg;
@@ -84,6 +88,7 @@ cvs_tag(int argc, char **argv)
}
}
+ *arg = optind;
argc -= optind;
argv += optind;
@@ -93,6 +98,7 @@ cvs_tag(int argc, char **argv)
tag = argv[0];
argc--;
argv++;
+ *arg += 1;
}
if (branch && delete) {
@@ -111,52 +117,33 @@ cvs_tag(int argc, char **argv)
return (-1);
}
- if (argc == 0)
- cvs_files = cvs_file_get(".", flags);
- else
- cvs_files = cvs_file_getspec(argv, argc, 0);
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
+ return (0);
+}
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_connect(root) < 0)
- return (EX_PROTOCOL);
- if (branch && (cvs_sendarg(root, "-b", 0) < 0))
- return (EX_PROTOCOL);
- if (delete && (cvs_sendarg(root, "-d", 0) < 0))
- return (EX_PROTOCOL);
- if (old_tag) {
- if ((cvs_sendarg(root, "-r", 0) < 0) ||
- (cvs_sendarg(root, old_tag, 0) < 0))
- return (EX_PROTOCOL);
- }
- if (date) {
- if ((cvs_sendarg(root, "-D", 0) < 0) ||
- (cvs_sendarg(root, date, 0) < 0))
- return (EX_PROTOCOL);
- }
- if (cvs_sendarg(root, tag, 0) < 0)
- return (EX_PROTOCOL);
- }
+int
+cvs_tag_sendflags(struct cvsroot *root)
+{
+ if (branch && (cvs_sendarg(root, "-b", 0) < 0))
+ return (EX_PROTOCOL);
- cvs_file_examine(cvs_files, cvs_tag_file, NULL);
+ if (delete && (cvs_sendarg(root, "-d", 0) < 0))
+ return (EX_PROTOCOL);
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
+ if (old_tag) {
+ if ((cvs_sendarg(root, "-r", 0) < 0) ||
+ (cvs_sendarg(root, old_tag, 0) < 0))
return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_TAG, NULL) < 0)
+ }
+
+ if (date) {
+ if ((cvs_sendarg(root, "-D", 0) < 0) ||
+ (cvs_sendarg(root, date, 0) < 0))
return (EX_PROTOCOL);
}
+ if (cvs_sendarg(root, tag, 0) < 0)
+ return (EX_PROTOCOL);
+
return (0);
}
diff --git a/usr.bin/cvs/update.c b/usr.bin/cvs/update.c
index 236b8a55bca..51cdaee24cf 100644
--- a/usr.bin/cvs/update.c
+++ b/usr.bin/cvs/update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: update.c,v 1.17 2005/02/27 00:22:08 jfb Exp $ */
+/* $OpenBSD: update.c,v 1.18 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -41,25 +41,26 @@
#include "proto.h"
-int cvs_update_file (CVSFILE *, void *);
-int cvs_update_prune (CVSFILE *, void *);
+int cvs_update_file(CVSFILE *, void *);
+int cvs_update_prune(CVSFILE *, void *);
+int cvs_update_options(char *, int, char **, int *);
+struct cvs_cmd_info cvs_update = {
+ cvs_update_options,
+ NULL,
+ cvs_update_file,
+ NULL, NULL,
+ CF_SORT | CF_RECURSE | CF_IGNORE | CF_KNOWN | CF_NOSYMS,
+ CVS_REQ_UPDATE,
+ CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2 | CVS_CMD_SENDDIR
+};
-/*
- * cvs_update()
- *
- * Handle the `cvs update' command.
- * Returns 0 on success, or the appropriate exit code on error.
- */
int
-cvs_update(int argc, char **argv)
+cvs_update_options(char *opt, int argc, char **argv, int *arg)
{
- int i, ch, flags;
- struct cvsroot *root;
+ int ch;
- flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_KNOWN|CF_NOSYMS;
-
- while ((ch = getopt(argc, argv, "ACD:dflPpQqRr:")) != -1) {
+ while ((ch = getopt(argc, argv, opt)) != -1) {
switch (ch) {
case 'A':
case 'C':
@@ -68,7 +69,7 @@ cvs_update(int argc, char **argv)
case 'f':
break;
case 'l':
- flags &= ~CF_RECURSE;
+ cvs_update.file_flags &= ~CF_RECURSE;
break;
case 'P':
case 'p':
@@ -76,7 +77,7 @@ cvs_update(int argc, char **argv)
case 'q':
break;
case 'R':
- flags |= CF_RECURSE;
+ cvs_update.file_flags |= CF_RECURSE;
break;
case 'r':
break;
@@ -85,43 +86,7 @@ cvs_update(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
-
- if (argc == 0)
- cvs_files = cvs_file_get(".", flags);
- else {
- /* don't perform ignore on explicitly listed files */
- flags &= ~(CF_IGNORE | CF_RECURSE | CF_SORT);
- cvs_files = cvs_file_getspec(argv, argc, flags);
- }
- if (cvs_files == NULL)
- return (EX_DATAERR);
-
- root = CVS_DIR_ROOT(cvs_files);
- if (root == NULL) {
- cvs_log(LP_ERR,
- "No CVSROOT specified! Please use the `-d' option");
- cvs_log(LP_ERR,
- "or set the CVSROOT environment variable.");
- return (EX_USAGE);
- }
- if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
- return (EX_PROTOCOL);
-
- cvs_file_examine(cvs_files, cvs_update_file, NULL);
-
- if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_senddir(root, cvs_files) < 0)
- return (EX_PROTOCOL);
-
- for (i = 0; i < argc; i++)
- if (cvs_sendarg(root, argv[i], 0) < 0)
- return (EX_PROTOCOL);
- if (cvs_sendreq(root, CVS_REQ_UPDATE, NULL) < 0)
- return (EX_PROTOCOL);
- }
-
+ *arg = optind;
return (0);
}
diff --git a/usr.bin/cvs/version.c b/usr.bin/cvs/version.c
index eede8d1cc1c..b612f30bd2f 100644
--- a/usr.bin/cvs/version.c
+++ b/usr.bin/cvs/version.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: version.c,v 1.7 2004/12/07 17:10:56 tedu Exp $ */
+/* $OpenBSD: version.c,v 1.8 2005/03/30 17:43:04 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -36,31 +36,25 @@
#include "cvs.h"
#include "proto.h"
+int cvs_version_sendflags(struct cvsroot *);
+struct cvs_cmd_info cvs_version = {
+ NULL,
+ cvs_version_sendflags,
+ NULL, NULL, NULL, 0, 0, 0
+};
int
-cvs_version(int argc, char **argv)
+cvs_version_sendflags(struct cvsroot *root)
{
- struct cvsroot *root;
-
- if (argc > 1)
- return (EX_USAGE);
-
- root = cvsroot_get(".");
if ((root != NULL) && (root->cr_method != CVS_METHOD_LOCAL))
printf("Client: ");
printf("%s\n", CVS_VERSION);
if ((root != NULL) && (root->cr_method != CVS_METHOD_LOCAL)) {
- if (cvs_connect(root) < 0)
- return (1);
-
printf("Server: %s\n", root->cr_version == NULL ?
"(unknown)" : root->cr_version);
- cvs_disconnect(root);
}
- cvsroot_free(root);
-
return (0);
}