From 90a8e93a12f4ab775543cbbef1c08e0e6afc630e Mon Sep 17 00:00:00 2001 From: Jean-Francois Brousseau Date: Tue, 14 Dec 2004 22:30:49 +0000 Subject: First attempt at syncing the command code and doing a lot more error checking on all the protocol calls --- usr.bin/cvs/getlog.c | 115 ++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 60 deletions(-) (limited to 'usr.bin/cvs/getlog.c') 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 * 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 -- cgit v1.2.3