summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-03-24 01:03:42 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-03-24 01:03:42 +0000
commit5e8d2f93a2fc7686076b1662303e6d3ce4045879 (patch)
treef9530055c8e8294a42eb8eefa7cc81685d560826 /usr.bin
parent22b377e7221cbc861a8913105167ff5a8de55279 (diff)
add the first pieces of our new command framework.
ok jfb@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/cmd.c122
-rw-r--r--usr.bin/cvs/cvs.c71
-rw-r--r--usr.bin/cvs/cvs.h49
-rw-r--r--usr.bin/cvs/cvs/Makefile4
4 files changed, 203 insertions, 43 deletions
diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c
new file mode 100644
index 00000000000..3a6b17103d7
--- /dev/null
+++ b/usr.bin/cvs/cmd.c
@@ -0,0 +1,122 @@
+/* $OpenBSD: cmd.c,v 1.1 2005/03/24 01:03:41 joris Exp $ */
+/*
+ * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/time.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <sysexits.h>
+
+#include "cvs.h"
+#include "log.h"
+#include "rcs.h"
+#include "proto.h"
+
+/*
+ * start the execution of a command.
+ */
+int
+cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv)
+{
+ int i;
+ int ret;
+ struct cvsroot *root;
+ struct cvs_cmd_info *c = cmd->cmd_info;
+
+ if ((ret = c->cmd_options(cmd->cmd_opts, argc, argv, &i)) < 0)
+ return (ret);
+
+ argc += i;
+ argv += i;
+
+ if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0)
+ cvs_files = cvs_file_getspec(argv, argc, 0);
+ else
+ cvs_files = cvs_file_get(".", c->file_flags);
+
+ if (cvs_files == NULL)
+ return (EX_DATAERR);
+
+ 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) {
+ cvs_log(LP_ERR,
+ "No CVSROOT specified! Please use the `-d' option");
+ cvs_log(LP_ERR,
+ "or set the CVSROOT enviroment variable.");
+ return (EX_USAGE);
+ }
+
+ if (root->cr_method != CVS_METHOD_LOCAL) {
+ if (cvs_connect(root) < 0)
+ return (EX_PROTOCOL);
+
+ if (c->cmd_flags & CVS_CMD_SENDARGS1) {
+ for (i = 0; i < argc; i++) {
+ if (cvs_sendarg(root, argv[i], 0) < 0)
+ return (EX_PROTOCOL);
+ }
+ }
+
+ if (c->cmd_sendflags != NULL)
+ c->cmd_sendflags(root);
+
+ if (c->cmd_flags & CVS_CMD_NEEDLOG) {
+ if (cvs_logmsg_send(root, cvs_msg) < 0)
+ return (EX_PROTOCOL);
+ }
+ }
+
+ if (c->cmd_examine != NULL)
+ cvs_file_examine(cvs_files, c->cmd_examine, NULL);
+
+ if (root->cr_method != CVS_METHOD_LOCAL) {
+ if (c->cmd_flags & CVS_CMD_SENDDIR) {
+ if (cvs_senddir(root, cvs_files) < 0)
+ return (EX_PROTOCOL);
+ }
+
+ if (c->cmd_flags & CVS_CMD_SENDARGS2) {
+ for (i = 0; i < argc; i++) {
+ if (cvs_sendarg(root, argv[i], 0) < 0)
+ return (EX_PROTOCOL);
+ }
+ }
+
+ if (cvs_sendreq(root, c->cmd_req,
+ (cmd->cmd_op == CVS_OP_INIT) ? root->cr_dir : NULL) < 0)
+ return (EX_PROTOCOL);
+ }
+
+ return (0);
+}
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c
index f8e146ad40c..2c844099ed5 100644
--- a/usr.bin/cvs/cvs.c
+++ b/usr.bin/cvs/cvs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.c,v 1.42 2005/03/08 16:13:30 joris Exp $ */
+/* $OpenBSD: cvs.c,v 1.43 2005/03/24 01:03:41 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -84,36 +84,27 @@ static TAILQ_HEAD(, cvs_var) cvs_variables;
* returned is EX_USAGE, the command's usage string is printed to standard
* error before returning.
*/
-static 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 **);
- char *cmd_synopsis;
- char *cmd_opts;
- char cmd_descr[CVS_CMD_MAXDESCRLEN];
- char *cmd_defargs;
-} cvs_cdt[] = {
+struct cvs_cmd cvs_cdt[] = {
{
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,
"",
"",
"Administration front end for rcs",
- NULL,
+ NULL, NULL
},
{
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,
@@ -121,49 +112,49 @@ static struct cvs_cmd {
"[-t id] module ...",
"AcD:d:fj:k:lNnPRr:st:",
"Checkout sources for editing",
- NULL,
+ NULL, NULL
},
{
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,
"[-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,
"",
"",
"Show repository access history",
- NULL,
+ NULL, NULL
},
{
CVS_OP_IMPORT, "import", { "im", "imp" }, cvs_import,
@@ -171,14 +162,14 @@ static struct cvs_cmd {
"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,
"",
"",
"Create a CVS repository if it doesn't exist",
- NULL,
+ NULL, NULL
},
#if defined(HAVE_KERBEROS)
{
@@ -186,7 +177,7 @@ static struct cvs_cmd {
"",
"",
"Start a Kerberos authentication CVS server",
- NULL,
+ NULL, NULL
},
#endif
{
@@ -194,84 +185,84 @@ static struct cvs_cmd {
"[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
"",
"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,
"[-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,
"",
"",
"Server mode",
- NULL,
+ NULL, NULL
},
{
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,
"[-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,
@@ -279,27 +270,27 @@ static struct cvs_cmd {
"[-t id] ...",
"",
"Bring work tree in sync with repository",
- NULL,
+ NULL, NULL
},
{
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
},
};
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 0deeef8e632..8ca318c9a90 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.45 2005/03/06 21:09:00 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.46 2005/03/24 01:03:41 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -126,6 +126,52 @@
#define CVS_PATH_ROOTSPEC CVS_PATH_CVSDIR "/Root"
#define CVS_PATH_REPOSITORY CVS_PATH_CVSDIR "/Repository"
+struct cvs_cmd_info {
+ /* parses the options for the command */
+ int (*cmd_options)(char *, int, char **, int *);
+
+ /* send command specific flags (CVS_METHOD_REMOTE only) */
+ int (*cmd_sendflags)(struct cvsroot *);
+
+ /* callback to be used for cvs_file_examine() */
+ int (*cmd_examine)(CVSFILE *, void *);
+
+ /* called after everything is done */
+ int (*cmd_cleanup)(void);
+
+ /* helper function, gets called after cvs_file_get()
+ * to do command specific operations if needed.
+ */
+ int (*cmd_helper)(void);
+
+ /* flags for cvs_file_get() */
+ int file_flags;
+
+ /* number of request */
+ int cmd_req;
+
+ /* info on the command (see flags below) */
+ int cmd_flags;
+};
+
+/* flags for cmd_flags */
+#define CVS_CMD_ALLOWSPEC 0x01
+#define CVS_CMD_NEEDLOG 0x02
+#define CVS_CMD_SENDARGS1 0x04
+#define CVS_CMD_SENDARGS2 0x08
+#define CVS_CMD_SENDDIR 0x10
+
+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 **);
+ char *cmd_synopsis;
+ char *cmd_opts;
+ char cmd_descr[CVS_CMD_MAXDESCRLEN];
+ char *cmd_defargs;
+ struct cvs_cmd_info *cmd_info;
+};
struct cvs_file;
struct cvs_dir;
@@ -272,6 +318,7 @@ extern CVSFILE *cvs_files;
/* client command handlers */
+int cvs_startcmd (struct cvs_cmd *, int, char **);
int cvs_add (int, char **);
int cvs_admin (int, char **);
int cvs_annotate (int, char **);
diff --git a/usr.bin/cvs/cvs/Makefile b/usr.bin/cvs/cvs/Makefile
index 22baf66cfa7..688be163acd 100644
--- a/usr.bin/cvs/cvs/Makefile
+++ b/usr.bin/cvs/cvs/Makefile
@@ -1,11 +1,11 @@
-# $OpenBSD: Makefile,v 1.18 2005/03/09 15:15:15 jfb Exp $
+# $OpenBSD: Makefile,v 1.19 2005/03/24 01:03:41 joris Exp $
.PATH: ${.CURDIR}/..
PROG= cvs
MAN= cvs.1 cvsrc.5 cvsintro.7
-SRCS= cvs.c add.c admin.c annotate.c buf.c checkout.c commit.c diff.c \
+SRCS= cvs.c add.c admin.c annotate.c buf.c checkout.c cmd.c commit.c diff.c \
entries.c file.c getlog.c history.c hist.c import.c init.c log.c \
logmsg.c proto.c rcs.c rcsnum.c remove.c req.c resp.c root.c \
server.c sock.c status.c tag.c update.c util.c version.c