summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2006-05-31 01:26:23 +0000
committerJoris Vink <joris@cvs.openbsd.org>2006-05-31 01:26:23 +0000
commita17d9ae674be35096bc95ea0be4d7699cffeef27 (patch)
tree510c7808f8ca51c285f496784a4191cfe18e75b8 /usr.bin/cvs
parentb7e06e0faad4c8501344e9a3df2dc87691753266 (diff)
allow commit to ressurect added files that exist in Attic/
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/commit.c58
-rw-r--r--usr.bin/cvs/file.c12
2 files changed, 51 insertions, 19 deletions
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index 26a57c708bf..d2d9dae7c6a 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.65 2006/05/30 21:32:52 joris Exp $ */
+/* $OpenBSD: commit.c,v 1.66 2006/05/31 01:26:21 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -150,10 +150,10 @@ void
cvs_commit_local(struct cvs_file *cf)
{
BUF *b;
- int l, isadded;
+ int l, openflags, rcsflags;
char *d, *f, rbuf[24];
CVSENTRIES *entlist;
- char *attic, *repo;
+ char *attic, *repo, *rcsfile;
cvs_log(LP_TRACE, "cvs_commit_local(%s)", cf->file_path);
cvs_file_classify(cf, NULL, 0);
@@ -162,19 +162,53 @@ cvs_commit_local(struct cvs_file *cf)
fatal("cvs_commit_local: '%s' is not a file", cf->file_path);
if (cf->file_status == FILE_MODIFIED ||
- cf->file_status == FILE_REMOVED)
+ cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED
+ && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1))
rcsnum_tostr(cf->file_rcs->rf_head, rbuf, sizeof(rbuf));
else
strlcpy(rbuf, "Non-existent", sizeof(rbuf));
- isadded = (cf->file_status == FILE_ADDED && cf->file_rcs == NULL);
- if (isadded) {
- cf->repo_fd = open(cf->file_rpath, O_CREAT|O_TRUNC|O_WRONLY);
+ if (cf->file_status == FILE_ADDED) {
+ rcsflags = RCS_CREATE;
+ openflags = O_CREAT | O_TRUNC | O_WRONLY;
+ if (cf->file_rcs != NULL) {
+ if (cf->file_rcs->rf_inattic == 0)
+ cvs_log(LP_ERR, "warning: expected %s "
+ "to be in the Attic", cf->file_path);
+
+ if (cf->file_rcs->rf_dead == 0)
+ cvs_log(LP_ERR, "warning: expected %s "
+ "to be dead", cf->file_path);
+
+ rcsfile = xmalloc(MAXPATHLEN);
+ repo = xmalloc(MAXPATHLEN);
+ cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
+ l = snprintf(rcsfile, MAXPATHLEN, "%s/%s%s",
+ repo, cf->file_name, RCS_FILE_EXT);
+ if (l == -1 || l >= MAXPATHLEN)
+ fatal("cvs_commit_local: overflow");
+
+ if (rename(cf->file_rpath, rcsfile) == -1)
+ fatal("cvs_commit_local: failed to move %s "
+ "outside the Attic: %s", cf->file_path,
+ strerror(errno));
+
+ xfree(cf->file_rpath);
+ cf->file_rpath = xstrdup(rcsfile);
+ xfree(rcsfile);
+ xfree(repo);
+
+ rcsflags = RCS_READ | RCS_PARSE_FULLY;
+ openflags = O_RDONLY;
+ rcs_close(cf->file_rcs);
+ }
+
+ cf->repo_fd = open(cf->file_rpath, openflags);
if (cf->repo_fd < 0)
fatal("cvs_commit_local: %s", strerror(errno));
cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd,
- RCS_CREATE, 0600);
+ rcsflags, 0600);
if (cf->file_rcs == NULL)
fatal("cvs_commit_local: failed to create RCS file "
"for %s", cf->file_path);
@@ -184,7 +218,7 @@ cvs_commit_local(struct cvs_file *cf)
cvs_printf("%s <- %s\n", cf->file_rpath, cf->file_path);
cvs_printf("old revision: %s; ", rbuf);
- if (isadded == 0)
+ if (cf->file_status != FILE_ADDED)
d = commit_diff_file(cf);
if (cf->file_status == FILE_REMOVED) {
@@ -199,7 +233,7 @@ cvs_commit_local(struct cvs_file *cf)
cvs_buf_putc(b, '\0');
f = cvs_buf_release(b);
- if (isadded == 0) {
+ if (cf->file_status != FILE_ADDED) {
if (rcs_deltatext_set(cf->file_rcs,
cf->file_rcs->rf_head, d) == -1)
fatal("cvs_commit_local: failed to set delta");
@@ -213,7 +247,7 @@ cvs_commit_local(struct cvs_file *cf)
xfree(f);
- if (isadded == 0)
+ if (cf->file_status != FILE_ADDED)
xfree(d);
if (cf->file_status == FILE_REMOVED) {
@@ -227,7 +261,7 @@ cvs_commit_local(struct cvs_file *cf)
if (cf->file_status == FILE_REMOVED) {
strlcpy(rbuf, "Removed", sizeof(rbuf));
} else if (cf->file_status == FILE_ADDED) {
- if (cf->file_rcs->rf_dead == 0)
+ if (cf->file_rcs->rf_dead == 1)
strlcpy(rbuf, "Initial Revision", sizeof(rbuf));
else
rcsnum_tostr(cf->file_rcs->rf_head,
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index ecb5f5546d9..0c2e90a9450 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.154 2006/05/30 22:06:13 joris Exp $ */
+/* $OpenBSD: file.c,v 1.155 2006/05/31 01:26:22 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
@@ -618,18 +618,16 @@ cvs_file_classify(struct cvs_file *cf, const char *tag, int loud)
if (cf->file_rcs == NULL)
fatal("cvs_file_classify: failed to parse RCS");
cf->file_rcs->rf_inattic = 0;
- } else if (cvs_cmdop != CVS_OP_UPDATE && cvs_cmdop != CVS_OP_CHECKOUT
- && cvs_cmdop != CVS_OP_COMMIT) {
- xfree(cf->file_rpath);
+ } else if (cvs_cmdop != CVS_OP_CHECKOUT) {
l = snprintf(rcsfile, MAXPATHLEN, "%s/%s/%s%s",
repo, CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT);
if (l == -1 || l >= MAXPATHLEN)
fatal("cvs_file_classify: overflow");
- cf->file_rpath = xstrdup(rcsfile);
-
- cf->repo_fd = open(cf->file_rpath, O_RDONLY);
+ cf->repo_fd = open(rcsfile, O_RDONLY);
if (cf->repo_fd != -1) {
+ xfree(cf->file_rpath);
+ cf->file_rpath = xstrdup(rcsfile);
cf->file_rcs = rcs_open(cf->file_rpath,
cf->repo_fd, rflags);
if (cf->file_rcs == NULL)