summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-12-14 22:30:49 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-12-14 22:30:49 +0000
commit90a8e93a12f4ab775543cbbef1c08e0e6afc630e (patch)
tree963b64ec3b9e41647954d6bc00b848f0a564243f
parentd1f3d7faf427e4408bb4c6247fe88062b808474f (diff)
First attempt at syncing the command code and doing a lot more error
checking on all the protocol calls
-rw-r--r--usr.bin/cvs/annotate.c97
-rw-r--r--usr.bin/cvs/commit.c31
-rw-r--r--usr.bin/cvs/getlog.c115
-rw-r--r--usr.bin/cvs/status.c119
-rw-r--r--usr.bin/cvs/tag.c24
-rw-r--r--usr.bin/cvs/update.c133
6 files changed, 273 insertions, 246 deletions
diff --git a/usr.bin/cvs/annotate.c b/usr.bin/cvs/annotate.c
index ed15aa83ab5..68923aa07ad 100644
--- a/usr.bin/cvs/annotate.c
+++ b/usr.bin/cvs/annotate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: annotate.c,v 1.1 2004/12/09 20:03:26 jfb Exp $ */
+/* $OpenBSD: annotate.c,v 1.2 2004/12/14 22:30:47 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -94,15 +94,26 @@ cvs_annotate(int argc, char **argv)
return (EX_DATAERR);
root = CVS_DIR_ROOT(cvs_files);
- if (root->cr_method != NULL) {
- cvs_connect(root);
+ 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 (rev != NULL) {
- cvs_sendarg(root, "-r", 0);
- cvs_sendarg(root, rev, 0);
+ if ((cvs_sendarg(root, "-r", 0) < 0) ||
+ (cvs_sendarg(root, rev, 0) < 0))
+ return (EX_PROTOCOL);
}
if (date != NULL) {
- cvs_sendarg(root, "-D", 0);
- cvs_sendarg(root, date, 0);
+ if ((cvs_sendarg(root, "-D", 0) < 0) ||
+ (cvs_sendarg(root, date, 0) < 0))
+ return (EX_PROTOCOL);
}
}
@@ -110,10 +121,13 @@ cvs_annotate(int argc, char **argv)
if (root->cr_method != CVS_METHOD_LOCAL) {
- cvs_senddir(root, cvs_files);
+ if (cvs_senddir(root, cvs_files) < 0)
+ return (EX_PROTOCOL);
for (i = 0; i < argc; i++)
- cvs_sendarg(root, argv[i], 0);
- cvs_sendreq(root, CVS_REQ_ANNOTATE, NULL);
+ if (cvs_sendarg(root, argv[i], 0) < 0)
+ return (EX_PROTOCOL);
+ if (cvs_sendreq(root, CVS_REQ_ANNOTATE, NULL) < 0)
+ return (EX_PROTOCOL);
}
return (0);
@@ -128,64 +142,57 @@ cvs_annotate(int argc, char **argv)
int
cvs_annotate_file(CVSFILE *cf, void *arg)
{
+ int ret;
char fpath[MAXPATHLEN];
struct cvsroot *root;
struct cvs_ent *entp;
- cvs_file_getpath(cf, fpath, sizeof(fpath));
+ ret = 0;
+ root = CVS_DIR_ROOT(cf);
- if (cf->cf_type == DT_DIR) {
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- root = cf->cf_parent->cf_ddat->cd_root;
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ if ((root->cr_method != CVS_METHOD_LOCAL) && (cf->cf_type == DT_DIR)) {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN)
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
CVS_FILE_NAME(cf));
- } else {
- root = cf->cf_ddat->cd_root;
- if ((cf->cf_parent == NULL) ||
- (root != cf->cf_parent->cf_ddat->cd_root)) {
- cvs_connect(root);
- }
-
- cvs_senddir(root, cf);
- }
-
- return (0);
- } else
- root = cf->cf_parent->cf_ddat->cd_root;
-
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- if (root->cr_method == CVS_METHOD_LOCAL)
- cvs_printf("? %s\n", fpath);
else
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
- CVS_FILE_NAME(cf));
- return (0);
+ ret = cvs_senddir(root, cf);
+ return (ret);
}
+ cvs_file_getpath(cf, fpath, sizeof(fpath));
entp = cvs_ent_getent(fpath);
- if ((entp != NULL) && (root->cr_method != CVS_METHOD_LOCAL) &&
- (cvs_sendentry(root, entp) < 0)) {
- cvs_ent_free(entp);
- return (-1);
- }
if (root->cr_method != CVS_METHOD_LOCAL) {
+ if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
+ cvs_ent_free(entp);
+ return (-1);
+ }
+
switch (cf->cf_cvstat) {
+ case CVS_FST_UNKNOWN:
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ CVS_FILE_NAME(cf));
+ break;
case CVS_FST_UPTODATE:
- cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
+ ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
+ CVS_FILE_NAME(cf));
break;
case CVS_FST_ADDED:
case CVS_FST_MODIFIED:
- cvs_sendreq(root, CVS_REQ_ISMODIFIED,
+ ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
CVS_FILE_NAME(cf));
break;
default:
- return (-1);
+ break;
+ }
+ } else {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
+ cvs_printf("? %s\n", fpath);
+ return (0);
}
-
}
if (entp != NULL)
cvs_ent_free(entp);
- return (0);
+ return (ret);
}
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index 5c29806de5c..b41243c0aac 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.11 2004/12/13 23:08:45 jfb Exp $ */
+/* $OpenBSD: commit.c,v 1.12 2004/12/14 22:30:48 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -119,18 +119,27 @@ cvs_commit(int argc, char **argv)
}
root = CVS_DIR_ROOT(cvs_files);
- cvs_connect(root);
- cvs_logmsg_send(root, msg);
+ 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, msg) < 0)))
+ return (EX_PROTOCOL);
cvs_file_examine(cvs_files, cvs_commit_file, &cl);
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_CI, NULL);
+ 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);
@@ -176,10 +185,10 @@ cvs_commit_file(CVSFILE *cf, void *arg)
rf = NULL;
repo = NULL;
+ root = CVS_DIR_ROOT(cf);
if (cf->cf_type == DT_DIR) {
if (cf->cf_cvstat != CVS_FST_UNKNOWN) {
- root = CVS_DIR_ROOT(cf);
if ((cf->cf_parent != NULL) &&
(root != cf->cf_parent->cf_ddat->cd_root)) {
cvs_connect(root);
@@ -191,8 +200,6 @@ cvs_commit_file(CVSFILE *cf, void *arg)
return (0);
}
-
- root = CVS_DIR_ROOT(cf);
cvs_file_getpath(cf, fpath, sizeof(fpath));
if (cf->cf_parent != NULL)
diff --git a/usr.bin/cvs/getlog.c b/usr.bin/cvs/getlog.c
index 7e15c54347c..6e62cf2914c 100644
--- a/usr.bin/cvs/getlog.c
+++ b/usr.bin/cvs/getlog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getlog.c,v 1.11 2004/12/14 20:19:37 xsa Exp $ */
+/* $OpenBSD: getlog.c,v 1.12 2004/12/14 22:30:48 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -93,17 +93,27 @@ cvs_getlog(int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc == 0) {
+ if (argc == 0)
cvs_files = cvs_file_get(".", flags);
- } else {
+ 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);
- root = cvs_files->cf_ddat->cd_root;
if (root->cr_method != CVS_METHOD_LOCAL) {
cvs_senddir(root, cvs_files);
if (argc > 0) {
@@ -125,88 +135,73 @@ cvs_getlog(int argc, char **argv)
static int
cvs_getlog_file(CVSFILE *cf, void *arg)
{
+ int ret;
char *repo, fpath[MAXPATHLEN];
RCSFILE *rf;
struct cvsroot *root;
struct cvs_ent *entp;
- cvs_file_getpath(cf, fpath, sizeof(fpath));
-
- if (cf->cf_type == DT_DIR) {
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- root = cf->cf_parent->cf_ddat->cd_root;
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
- CVS_FILE_NAME(cf));
- } else {
- root = cf->cf_ddat->cd_root;
- if ((cf->cf_parent == NULL) ||
- (root != cf->cf_parent->cf_ddat->cd_root)) {
- cvs_connect(root);
- }
-
- cvs_senddir(root, cf);
- }
-
- return (0);
- } else
- root = cf->cf_parent->cf_ddat->cd_root;
-
+ ret = 0;
rf = NULL;
- if (cf->cf_parent != NULL) {
- repo = cf->cf_parent->cf_ddat->cd_repo;
- } else {
- repo = NULL;
- }
+ root = CVS_DIR_ROOT(cf);
+ repo = CVS_DIR_REPO(cf);
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- if (root->cr_method == CVS_METHOD_LOCAL)
- cvs_printf("? %s\n", fpath);
- else
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ if ((root->cr_method != CVS_METHOD_LOCAL) && (cf->cf_type == DT_DIR)) {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN)
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
CVS_FILE_NAME(cf));
- return (0);
+ else
+ ret = cvs_senddir(root, cf);
+ return (ret);
}
+ cvs_file_getpath(cf, fpath, sizeof(fpath));
entp = cvs_ent_getent(fpath);
- if (entp == NULL)
- return (-1);
-
- if ((root->cr_method != CVS_METHOD_LOCAL) &&
- (cvs_sendentry(root, entp) < 0)) {
- cvs_ent_free(entp);
- return (-1);
- }
if (root->cr_method != CVS_METHOD_LOCAL) {
+ if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
+ cvs_ent_free(entp);
+ return (-1);
+ }
+
switch (cf->cf_cvstat) {
+ case CVS_FST_UNKNOWN:
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ CVS_FILE_NAME(cf));
+ break;
case CVS_FST_UPTODATE:
- cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
+ ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
+ CVS_FILE_NAME(cf));
break;
case CVS_FST_ADDED:
case CVS_FST_MODIFIED:
- cvs_sendreq(root, CVS_REQ_ISMODIFIED,
+ ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
CVS_FILE_NAME(cf));
break;
default:
- return (-1);
+ break;
+ }
+ } else {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
+ cvs_printf("? %s\n", fpath);
+ return (0);
}
- cvs_ent_free(entp);
- return (0);
- }
+ snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
+ root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
- snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
- root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
+ rf = rcs_open(fpath, RCS_MODE_READ);
+ if (rf == NULL) {
+ cvs_ent_free(entp);
+ return (-1);
+ }
- rf = rcs_open(fpath, RCS_MODE_READ);
- if (rf == NULL) {
- cvs_ent_free(entp);
- return (-1);
+ rcs_close(rf);
}
- rcs_close(rf);
- cvs_ent_free(entp);
- return (0);
+ if (entp != NULL)
+ cvs_ent_free(entp);
+ return (ret);
}
#ifdef notyet
diff --git a/usr.bin/cvs/status.c b/usr.bin/cvs/status.c
index f36cf73c675..c517d73443b 100644
--- a/usr.bin/cvs/status.c
+++ b/usr.bin/cvs/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.4 2004/12/07 17:10:56 tedu Exp $ */
+/* $OpenBSD: status.c,v 1.5 2004/12/14 22:30:48 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -64,9 +64,8 @@ int
cvs_status(int argc, char **argv)
{
int i, ch, flags;
- struct cvs_file *cf;
+ struct cvsroot *root;
- cf = NULL;
flags = CF_SORT|CF_IGNORE|CF_RECURSE;
while ((ch = getopt(argc, argv, "F:flm:Rr:")) != -1) {
@@ -80,16 +79,35 @@ cvs_status(int argc, char **argv)
argv += optind;
if (argc == 0) {
- cf = cvs_file_get(".", flags);
- if (cf == NULL) {
- return (EX_DATAERR);
- }
-
- cvs_file_examine(cf, cvs_status_file, NULL);
+ cvs_files = cvs_file_get(".", flags);
} else {
- for (i = 0; i < argc; i++) {
- cf = cvs_file_get(argv[i], flags);
- }
+ 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_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);
}
return (0);
@@ -104,65 +122,52 @@ cvs_status(int argc, char **argv)
int
cvs_status_file(CVSFILE *cfp, void *arg)
{
+ int ret;
char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
RCSFILE *rf;
struct cvs_ent *entp;
struct cvsroot *root;
- cvs_file_getpath(cfp, fpath, sizeof(fpath));
- cvs_log(LP_DEBUG, "%s: getting status for %s", __func__, fpath);
-
- if (cfp->cf_type == DT_DIR) {
- root = cfp->cf_ddat->cd_root;
- if ((cfp->cf_parent == NULL) ||
- (root != cfp->cf_parent->cf_ddat->cd_root)) {
- cvs_connect(root);
- }
-
- cvs_senddir(root, cfp);
- return (0);
- } else
- root = cfp->cf_parent->cf_ddat->cd_root;
-
+ ret = 0;
rf = NULL;
- if (cfp->cf_parent != NULL)
- repo = cfp->cf_parent->cf_ddat->cd_repo;
- else
- repo = NULL;
+ root = CVS_DIR_ROOT(cfp);
+ repo = CVS_DIR_REPO(cfp);
- if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
- if (root->cr_method == CVS_METHOD_LOCAL)
- cvs_log(LP_WARN, "I know nothing about %s", fpath);
- else
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
- CVS_FILE_NAME(cfp));
- return (0);
- }
+ if ((root->cr_method != CVS_METHOD_LOCAL) && (cfp->cf_type == DT_DIR))
+ return (cvs_senddir(root, cfp));
+ cvs_file_getpath(cfp, fpath, sizeof(fpath));
entp = cvs_ent_getent(fpath);
- if (entp == NULL)
- return (-1);
if (root->cr_method != CVS_METHOD_LOCAL) {
- if (cvs_sendentry(root, entp) < 0) {
+ if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
cvs_ent_free(entp);
return (-1);
}
- }
- if (cfp->cf_cvstat == CVS_FST_UPTODATE) {
- if (root->cr_method != CVS_METHOD_LOCAL)
- cvs_sendreq(root, CVS_REQ_UNCHANGED,
+ switch (cfp->cf_cvstat) {
+ case CVS_FST_UNKNOWN:
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
CVS_FILE_NAME(cfp));
- cvs_ent_free(entp);
- return (0);
- }
-
- /* at this point, the file is modified */
- if (root->cr_method != CVS_METHOD_LOCAL) {
- cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cfp));
- cvs_sendfile(root, fpath);
+ 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_MODIFIED,
+ CVS_FILE_NAME(cfp));
+ if (ret == 0)
+ ret = cvs_sendfile(root, fpath);
+ default:
+ break;
+ }
} else {
+ if (cfp->cf_cvstat == CVS_FST_UNKNOWN) {
+ cvs_log(LP_WARN, "I know nothing about %s", fpath);
+ return (0);
+ }
+
snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
root->cr_dir, repo, CVS_FILE_NAME(cfp), RCS_FILE_EXT);
@@ -174,6 +179,8 @@ cvs_status_file(CVSFILE *cfp, void *arg)
rcs_close(rf);
}
- cvs_ent_free(entp);
- return (0);
+
+ if (entp != NULL)
+ cvs_ent_free(entp);
+ return (ret);
}
diff --git a/usr.bin/cvs/tag.c b/usr.bin/cvs/tag.c
index 7c5705cc824..19d3bfe102b 100644
--- a/usr.bin/cvs/tag.c
+++ b/usr.bin/cvs/tag.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tag.c,v 1.1 2004/12/14 19:11:54 jfb Exp $ */
+/* $OpenBSD: tag.c,v 1.2 2004/12/14 22:30:48 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2004 Joris Vink <amni@pandora.be>
@@ -116,26 +116,28 @@ cvs_tag(int argc, char **argv)
return (EX_USAGE);
}
- if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
- return (EX_OSERR);
-
if (root->cr_method != CVS_METHOD_LOCAL) {
- if (branch)
- cvs_sendarg(root, "-b", 0);
- if (delete)
- cvs_sendarg(root, "-d", 0);
+ 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) {
cvs_sendarg(root, "-r", 0);
cvs_sendarg(root, old_tag, 0);
}
- cvs_sendarg(root, tag, 0);
+ if (cvs_sendarg(root, tag, 0) < 0)
+ return (EX_PROTOCOL);
}
cvs_file_examine(cvs_files, cvs_tag_file, NULL);
if (root->cr_method != CVS_METHOD_LOCAL) {
- cvs_senddir(root, cvs_files);
- cvs_sendreq(root, CVS_REQ_TAG, NULL);
+ if (cvs_senddir(root, cvs_files) < 0)
+ return (EX_PROTOCOL);
+ if (cvs_sendreq(root, CVS_REQ_TAG, NULL) < 0)
+ return (EX_PROTOCOL);
}
return (0);
diff --git a/usr.bin/cvs/update.c b/usr.bin/cvs/update.c
index 76420c3d2d5..503b507c7ad 100644
--- a/usr.bin/cvs/update.c
+++ b/usr.bin/cvs/update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: update.c,v 1.11 2004/12/07 17:10:56 tedu Exp $ */
+/* $OpenBSD: update.c,v 1.12 2004/12/14 22:30:48 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -54,7 +54,8 @@ int cvs_update_prune (CVSFILE *, void *);
int
cvs_update(int argc, char **argv)
{
- int ch, flags;
+ int i, ch, flags;
+ struct cvsroot *root;
flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_KNOWN|CF_NOSYMS;
@@ -87,9 +88,9 @@ cvs_update(int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc == 0) {
+ if (argc == 0)
cvs_files = cvs_file_get(".", flags);
- } else {
+ else {
/* don't perform ignore on explicitly listed files */
flags &= ~(CF_IGNORE | CF_RECURSE | CF_SORT);
cvs_files = cvs_file_getspec(argv, argc, flags);
@@ -97,10 +98,29 @@ cvs_update(int argc, char **argv)
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);
- cvs_senddir(cvs_files->cf_ddat->cd_root, cvs_files);
- cvs_sendreq(cvs_files->cf_ddat->cd_root, CVS_REQ_UPDATE, 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);
+ }
return (0);
}
@@ -109,92 +129,81 @@ cvs_update(int argc, char **argv)
/*
* cvs_update_file()
*
- * Diff a single file.
+ * Update a single file. In the case where we act as client, send any
+ * pertinent information about that file to the server.
*/
int
cvs_update_file(CVSFILE *cf, void *arg)
{
+ int ret;
char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
RCSFILE *rf;
struct cvsroot *root;
struct cvs_ent *entp;
- cvs_file_getpath(cf, fpath, sizeof(fpath));
-
- if (cf->cf_type == DT_DIR) {
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- root = cf->cf_parent->cf_ddat->cd_root;
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
- CVS_FILE_NAME(cf));
- } else {
- root = cf->cf_ddat->cd_root;
- if ((cf->cf_parent == NULL) ||
- (root != cf->cf_parent->cf_ddat->cd_root)) {
- cvs_connect(root);
- }
-
- cvs_senddir(root, cf);
- }
-
- return (0);
- } else
- root = cf->cf_parent->cf_ddat->cd_root;
-
+ ret = 0;
rf = NULL;
- if (cf->cf_parent != NULL) {
- repo = cf->cf_parent->cf_ddat->cd_repo;
- } else {
- repo = NULL;
- }
+ root = CVS_DIR_ROOT(cf);
+ repo = CVS_DIR_REPO(cf);
- if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
- if (root->cr_method == CVS_METHOD_LOCAL)
- cvs_printf("? %s\n", fpath);
+ if ((root->cr_method != CVS_METHOD_LOCAL) && (cf->cf_type == DT_DIR)) {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN)
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ CVS_FILE_NAME(cf));
else
- cvs_sendreq(root, CVS_REQ_QUESTIONABLE, CVS_FILE_NAME(cf));
- return (0);
+ ret = cvs_senddir(root, cf);
+ return (ret);
}
+ cvs_file_getpath(cf, fpath, sizeof(fpath));
entp = cvs_ent_getent(fpath);
- if (entp == NULL)
- return (-1);
-
- if ((root->cr_method != CVS_METHOD_LOCAL) &&
- (cvs_sendentry(root, entp) < 0)) {
- cvs_ent_free(entp);
- return (-1);
- }
if (root->cr_method != CVS_METHOD_LOCAL) {
+ if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
+ cvs_ent_free(entp);
+ return (-1);
+ }
+
switch (cf->cf_cvstat) {
+ case CVS_FST_UNKNOWN:
+ ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
+ CVS_FILE_NAME(cf));
+ break;
case CVS_FST_UPTODATE:
- cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
+ ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
+ CVS_FILE_NAME(cf));
break;
case CVS_FST_ADDED:
case CVS_FST_MODIFIED:
- cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cf));
- cvs_sendfile(root, fpath);
+ ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
+ CVS_FILE_NAME(cf));
+ if (ret == 0)
+ ret = cvs_sendfile(root, fpath);
break;
default:
- return (-1);
+ break;
+ }
+ } else {
+ if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
+ cvs_printf("? %s\n", fpath);
+ return (0);
}
- cvs_ent_free(entp);
- return (0);
- }
+ snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
+ root->cr_dir, repo, fpath, RCS_FILE_EXT);
- snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
- root->cr_dir, repo, fpath, RCS_FILE_EXT);
+ rf = rcs_open(rcspath, RCS_MODE_READ);
+ if (rf == NULL) {
+ cvs_ent_free(entp);
+ return (-1);
+ }
- rf = rcs_open(rcspath, RCS_MODE_READ);
- if (rf == NULL) {
- cvs_ent_free(entp);
- return (-1);
+ rcs_close(rf);
}
- rcs_close(rf);
- cvs_ent_free(entp);
- return (0);
+ if (entp != NULL)
+ cvs_ent_free(entp);
+ return (ret);
}