diff options
-rw-r--r-- | usr.bin/cvs/tag.c | 185 |
1 files changed, 102 insertions, 83 deletions
diff --git a/usr.bin/cvs/tag.c b/usr.bin/cvs/tag.c index 8487fabd37f..276c0b58c92 100644 --- a/usr.bin/cvs/tag.c +++ b/usr.bin/cvs/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.13 2005/04/18 21:02:50 jfb Exp $ */ +/* $OpenBSD: tag.c,v 1.14 2005/04/19 18:51:30 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2004 Joris Vink <joris@openbsd.org> @@ -26,13 +26,10 @@ */ #include <sys/types.h> -#include <sys/stat.h> #include <errno.h> #include <stdio.h> -#include <fcntl.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> #include "cvs.h" @@ -40,47 +37,54 @@ #include "proto.h" -int cvs_tag_file(CVSFILE *, void *); -int cvs_tag_options(char *, int, char **, int *); -int cvs_tag_sendflags(struct cvsroot *); +static int cvs_tag_local (CVSFILE *, void *); +static int cvs_tag_remote (CVSFILE *, void *); +static int cvs_tag_options (char *, int, char **, int *); +static int cvs_tag_sendflags (struct cvsroot *); -static char *tag, *old_tag, *date; -static int branch, delete; +static char *tag_name = NULL; +static char *tag_date = NULL; +static char *tag_oldname = NULL; +static int tag_branch = 0; +static int tag_delete = 0; +static int tag_forcehead = 0; struct cvs_cmd_info cvs_tag = { cvs_tag_options, cvs_tag_sendflags, - cvs_tag_file, + cvs_tag_remote, NULL, NULL, CF_SORT | CF_IGNORE | CF_RECURSE, CVS_REQ_TAG, - CVS_CMD_ALLOWSPEC + CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR }; -int +static int cvs_tag_options(char *opt, int argc, char **argv, int *arg) { int ch; - date = old_tag = NULL; - branch = delete = 0; + tag_date = tag_oldname = NULL; while ((ch = getopt(argc, argv, opt)) != -1) { switch (ch) { case 'b': - branch = 1; + tag_branch = 1; break; case 'd': - delete = 1; + tag_delete = 1; + break; + case 'f': + tag_forcehead = 1; break; case 'D': - date = optarg; + tag_date = optarg; break; case 'l': cvs_tag.file_flags &= ~CF_RECURSE; break; case 'r': - old_tag = optarg; + tag_oldname = optarg; break; default: return (CVS_EX_USAGE); @@ -94,24 +98,24 @@ cvs_tag_options(char *opt, int argc, char **argv, int *arg) if (argc == 0) { return (CVS_EX_USAGE); } else { - tag = argv[0]; + tag_name = argv[0]; argc--; argv++; *arg += 1; } - if (branch && delete) { + if (tag_branch && tag_delete) { cvs_log(LP_WARN, "ignoring -b with -d options"); - branch = 0; + tag_branch = 0; } - if (delete && old_tag) - old_tag = NULL; + if (tag_delete && tag_oldname) + tag_oldname = NULL; - if (delete && date) - date = NULL; + if (tag_delete && tag_date) + tag_date = NULL; - if (old_tag != NULL && date != NULL) { + if (tag_oldname != NULL && tag_date != NULL) { cvs_log(LP_ERROR, "-r and -D options are mutually exclusive"); return (CVS_EX_USAGE); } @@ -119,28 +123,28 @@ cvs_tag_options(char *opt, int argc, char **argv, int *arg) return (0); } -int +static int cvs_tag_sendflags(struct cvsroot *root) { - if (branch && (cvs_sendarg(root, "-b", 0) < 0)) + if (tag_branch && (cvs_sendarg(root, "-b", 0) < 0)) return (CVS_EX_PROTO); - if (delete && (cvs_sendarg(root, "-d", 0) < 0)) + if (tag_delete && (cvs_sendarg(root, "-d", 0) < 0)) return (CVS_EX_PROTO); - if (old_tag) { + if (tag_oldname) { if ((cvs_sendarg(root, "-r", 0) < 0) || - (cvs_sendarg(root, old_tag, 0) < 0)) + (cvs_sendarg(root, tag_oldname, 0) < 0)) return (CVS_EX_PROTO); } - if (date) { + if (tag_date) { if ((cvs_sendarg(root, "-D", 0) < 0) || - (cvs_sendarg(root, date, 0) < 0)) + (cvs_sendarg(root, tag_date, 0) < 0)) return (CVS_EX_PROTO); } - if (cvs_sendarg(root, tag, 0) < 0) + if (cvs_sendarg(root, tag_name, 0) < 0) return (CVS_EX_PROTO); return (0); @@ -148,72 +152,87 @@ cvs_tag_sendflags(struct cvsroot *root) /* - * cvs_tag_file() + * cvs_tag_remote() * * Get the status of a single file. */ -int -cvs_tag_file(CVSFILE *cfp, void *arg) +static int +cvs_tag_remote(CVSFILE *cfp, void *arg) { - int ret, l; - char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN]; - RCSFILE *rf; + int ret; + char fpath[MAXPATHLEN]; struct cvsroot *root; ret = 0; - rf = NULL; root = CVS_DIR_ROOT(cfp); - if ((root->cr_method != CVS_METHOD_LOCAL) && (cfp->cf_type == DT_DIR)) { - if (cvs_senddir(root, cfp) < 0) - return (CVS_EX_PROTO); - return (0); + if (cfp->cf_type == DT_DIR) { + ret = cvs_senddir(root, cfp); + return (ret); + } + + if (cvs_sendentry(root, cfp) < 0) { + return (CVS_EX_PROTO); } cvs_file_getpath(cfp, fpath, sizeof(fpath)); - if (root->cr_method != CVS_METHOD_LOCAL) { - if (cvs_sendentry(root, cfp) < 0) { - return (CVS_EX_PROTO); - } + switch (cfp->cf_cvstat) { + case CVS_FST_UNKNOWN: + ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cfp->cf_name); + break; + case CVS_FST_UPTODATE: + ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cfp->cf_name); + break; + case CVS_FST_MODIFIED: + ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cfp->cf_name); + default: + break; + } - switch (cfp->cf_cvstat) { - case CVS_FST_UNKNOWN: - ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, - CVS_FILE_NAME(cfp)); - break; - case CVS_FST_UPTODATE: - ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, - CVS_FILE_NAME(cfp)); - break; - case CVS_FST_MODIFIED: - ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, - CVS_FILE_NAME(cfp)); - default: - break; - } - } else { - if (cfp->cf_cvstat == CVS_FST_UNKNOWN) { - cvs_log(LP_WARN, "I know nothing about %s", fpath); - return (0); - } + return (ret); +} - repo = CVS_DIR_REPO(cfp); - l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s", - root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT); - if (l == -1 || l >= (int)sizeof(rcspath)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", rcspath); - return (-1); - } - rf = rcs_open(rcspath, RCS_READ); - if (rf == NULL) { - return (CVS_EX_DATA); - } +static int +cvs_tag_local(CVSFILE *cf, void *arg) +{ + int len; + char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN]; + struct cvsroot *root; + RCSFILE *rf; + RCSNUM *tag_rev; + + cvs_file_getpath(cf, fpath, sizeof(fpath)); + + if (cf->cf_cvstat == CVS_FST_UNKNOWN) { + cvs_log(LP_WARN, "I know nothing about %s", fpath); + return (0); + } + + repo = CVS_DIR_REPO(cf); + root = CVS_DIR_ROOT(cf); - rcs_close(rf); + len = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s", + root->cr_dir, repo, cf->cf_name, RCS_FILE_EXT); + if (len == -1 || len >= (int)sizeof(rcspath)) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", rcspath); + return (-1); } - return (ret); + rf = rcs_open(rcspath, RCS_READ|RCS_WRITE); + if (rf == NULL) { + cvs_log(LP_ERR, "failed to open %s: %s", rcspath, + rcs_errstr(rcs_errno)); + return (-1); + } + + if (rcs_sym_add(rf, tag_name, tag_rev) < 0) { + cvs_log(LP_ERR, "failed to tag %s: %s", rcspath, + rcs_errstr(rcs_errno)); + } + + rcs_close(rf); + return (0); } |