diff options
author | peter <peter@FreeBSD.org> | 1997-05-15 22:46:24 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-05-15 22:46:24 +0000 |
commit | 4f40fe8334ad5f056e1d9105f23fe7ac859c39ba (patch) | |
tree | 3b2f0092fa216d9f61059ba94b7f10b5bacf9496 /contrib/cvs/src/repos.c | |
parent | 8982e501c77217c860f79bba431f46a62b607a21 (diff) | |
download | FreeBSD-src-4f40fe8334ad5f056e1d9105f23fe7ac859c39ba.zip FreeBSD-src-4f40fe8334ad5f056e1d9105f23fe7ac859c39ba.tar.gz |
Import of cvs-1.9.9-970515 onto vendor branch.
Obtained from: cyclic.com
Diffstat (limited to 'contrib/cvs/src/repos.c')
-rw-r--r-- | contrib/cvs/src/repos.c | 117 |
1 files changed, 62 insertions, 55 deletions
diff --git a/contrib/cvs/src/repos.c b/contrib/cvs/src/repos.c index 7beaaba..2590df5 100644 --- a/contrib/cvs/src/repos.c +++ b/contrib/cvs/src/repos.c @@ -7,6 +7,7 @@ */ #include "cvs.h" +#include "getline.h" /* Determine the name of the RCS repository for directory DIR in the current working directory, or for the current working directory @@ -23,11 +24,10 @@ Name_Repository (dir, update_dir) char *update_dir; { FILE *fpin; - char *ret, *xupdate_dir; - char repos[PATH_MAX]; - char path[PATH_MAX]; - char tmp[PATH_MAX]; - char cvsadm[PATH_MAX]; + char *xupdate_dir; + char *repos = NULL; + size_t repos_allocated = 0; + char *tmp; char *cp; if (update_dir && *update_dir) @@ -36,48 +36,61 @@ Name_Repository (dir, update_dir) xupdate_dir = "."; if (dir != NULL) - (void) sprintf (cvsadm, "%s/%s", dir, CVSADM); - else - (void) strcpy (cvsadm, CVSADM); - - /* sanity checks */ - if (!isdir (cvsadm)) - { - error (0, 0, "in directory %s:", xupdate_dir); - error (1, 0, "there is no version here; do '%s checkout' first", - program_name); - } - - if (dir != NULL) - (void) sprintf (tmp, "%s/%s", dir, CVSADM_ENT); - else - (void) strcpy (tmp, CVSADM_ENT); - - if (!isreadable (tmp)) { - error (0, 0, "in directory %s:", xupdate_dir); - error (1, 0, "*PANIC* administration files missing"); - } - - if (dir != NULL) + tmp = xmalloc (strlen (dir) + sizeof (CVSADM_REP) + 10); (void) sprintf (tmp, "%s/%s", dir, CVSADM_REP); - else - (void) strcpy (tmp, CVSADM_REP); - - if (!isreadable (tmp)) - { - error (0, 0, "in directory %s:", xupdate_dir); - error (1, 0, "*PANIC* administration files missing"); } + else + tmp = xstrdup (CVSADM_REP); /* * The assumption here is that the repository is always contained in the * first line of the "Repository" file. */ - fpin = open_file (tmp, "r"); + fpin = CVS_FOPEN (tmp, "r"); - if (fgets (repos, PATH_MAX, fpin) == NULL) + if (fpin == NULL) { + int save_errno = errno; + char *cvsadm; + + if (dir != NULL) + { + cvsadm = xmalloc (strlen (dir) + sizeof (CVSADM) + 10); + (void) sprintf (cvsadm, "%s/%s", dir, CVSADM); + } + else + cvsadm = xstrdup (CVSADM); + + if (!isdir (cvsadm)) + { + error (0, 0, "in directory %s:", xupdate_dir); + error (1, 0, "there is no version here; do '%s checkout' first", + program_name); + } + free (cvsadm); + + if (existence_error (save_errno)) + { + /* FIXME: This is a very poorly worded error message. It + occurs at least in the case where the user manually + creates a directory named CVS, so the error message + should be more along the lines of "CVS directory found + without administrative files; use CVS to create the CVS + directory, or rename it to something else if the + intention is to store something besides CVS + administrative files". */ + error (0, 0, "in directory %s:", xupdate_dir); + error (1, 0, "*PANIC* administration files missing"); + } + + error (1, save_errno, "cannot open %s", tmp); + } + free (tmp); + + if (getline (&repos, &repos_allocated, fpin) < 0) + { + /* FIXME: should be checking for end of file separately. */ error (0, 0, "in directory %s:", xupdate_dir); error (1, errno, "cannot read %s", CVSADM_REP); } @@ -98,30 +111,23 @@ Name_Repository (dir, update_dir) } if (! isabsolute(repos)) { - if (CVSroot == NULL) + char *newrepos; + + if (CVSroot_original == NULL) { error (0, 0, "in directory %s:", xupdate_dir); error (0, 0, "must set the CVSROOT environment variable\n"); error (0, 0, "or specify the '-d' option to %s.", program_name); error (1, 0, "illegal repository setting"); } - (void) strcpy (path, repos); - (void) sprintf (repos, "%s/%s", CVSroot, path); - } -#ifdef CLIENT_SUPPORT - if (!client_active && !isdir (repos)) -#else - if (!isdir (repos)) -#endif - { - error (0, 0, "in directory %s:", xupdate_dir); - error (1, 0, "there is no repository %s", repos); + newrepos = xmalloc (strlen (CVSroot_directory) + strlen (repos) + 10); + (void) sprintf (newrepos, "%s/%s", CVSroot_directory, repos); + free (repos); + repos = newrepos; } - /* allocate space to return and fill it in */ - strip_path (repos); - ret = xstrdup (repos); - return (ret); + strip_trailing_slashes (repos); + return repos; } /* @@ -137,9 +143,10 @@ Short_Repository (repository) /* If repository matches CVSroot at the beginning, strip off CVSroot */ /* And skip leading '/' in rep, in case CVSroot ended with '/'. */ - if (strncmp (CVSroot, repository, strlen (CVSroot)) == 0) + if (strncmp (CVSroot_directory, repository, + strlen (CVSroot_directory)) == 0) { - char *rep = repository + strlen (CVSroot); + char *rep = repository + strlen (CVSroot_directory); return (*rep == '/') ? rep+1 : rep; } else |