summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/annotate.c
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/cvs/annotate.c
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/cvs/annotate.c')
-rw-r--r--usr.bin/cvs/annotate.c96
1 files changed, 35 insertions, 61 deletions
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()
*