summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/util.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2008-01-31 16:44:47 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2008-01-31 16:44:47 +0000
commit9a5ffdb8ac39e8b01479323bb825bddb52eef6ac (patch)
tree7d9909cee6f9a48ad0aa021e1f171577f72748c3 /usr.bin/cvs/util.c
parent733fc74bc2023ea50e6e6879d17302025c57af96 (diff)
Rework of cvs_get_repository_name.
checkout is allowed to continue if CVS/Repository does not exist. export and import are not supposed to open CVS/Repository. All other commands -- if CVS_USE_WDIR is set -- must fatal if it does not exist. OK joris@
Diffstat (limited to 'usr.bin/cvs/util.c')
-rw-r--r--usr.bin/cvs/util.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index f0690b8052c..b17749ebc8b 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.126 2008/01/31 10:17:47 tobias Exp $ */
+/* $OpenBSD: util.c,v 1.127 2008/01/31 16:44:46 tobias Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org>
@@ -473,45 +473,41 @@ cvs_get_repository_name(const char *dir, char *dst, size_t len)
FILE *fp;
char fpath[MAXPATHLEN];
- /* During checkout -p, do not use any locally available files. */
- if (cvs_cmdop == CVS_OP_CHECKOUT && print_stdout) {
- dst[0] = '\0';
- if (strlcat(dst, dir, len) >= len)
+ dst[0] = '\0';
+
+ if (!(cmdp->cmd_flags & CVS_USE_WDIR)) {
+ if (strlcpy(dst, dir, len) >= len)
fatal("cvs_get_repository_name: truncation");
return;
}
- (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
- dir, CVS_PATH_REPOSITORY);
-
- if (cvs_cmdop != CVS_OP_IMPORT && (fp = fopen(fpath, "r")) != NULL) {
- if ((fgets(dst, len, fp)) == NULL)
- fatal("cvs_get_repository_name: bad repository file");
- dst[strcspn(dst, "\n")] = '\0';
- (void)fclose(fp);
- } else {
- dst[0] = '\0';
-
- if (cvs_cmdop == CVS_OP_IMPORT) {
- if (strlcpy(dst, import_repository, len) >= len)
- fatal("cvs_get_repository_name: truncation");
- if (strlcat(dst, "/", len) >= len)
+ switch (cvs_cmdop) {
+ case CVS_OP_EXPORT:
+ if (strcmp(dir, "."))
+ if (strlcpy(dst, dir, len) >= len)
fatal("cvs_get_repository_name: truncation");
+ break;
+ case CVS_OP_IMPORT:
+ if (strlcpy(dst, import_repository, len) >= len)
+ fatal("cvs_get_repository_name: truncation");
+ if (strlcat(dst, "/", len) >= len)
+ fatal("cvs_get_repository_name: truncation");
- if (strcmp(dir, ".")) {
- if (strlcat(dst, dir, len) >= len) {
- fatal("cvs_get_repository_name: "
- "truncation");
- }
- }
- } else {
- if ((cvs_cmdop == CVS_OP_EXPORT && strcmp(dir, ".")) ||
- cvs_cmdop != CVS_OP_CHECKOUT) {
- if (strlcat(dst, dir, len) >= len)
- fatal("cvs_get_repository_name: "
- "truncation");
- }
- }
+ if (strcmp(dir, "."))
+ if (strlcat(dst, dir, len) >= len)
+ fatal("cvs_get_repository_name: truncation");
+ break;
+ default:
+ (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
+ dir, CVS_PATH_REPOSITORY);
+ if ((fp = fopen(fpath, "r")) != NULL) {
+ if ((fgets(dst, len, fp)) == NULL)
+ fatal("%s: bad repository file", fpath);
+ dst[strcspn(dst, "\n")] = '\0';
+ (void)fclose(fp);
+ } else if (cvs_cmdop != CVS_OP_CHECKOUT)
+ fatal("%s is missing", fpath);
+ break;
}
}