summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2006-05-28 10:15:36 +0000
committerJoris Vink <joris@cvs.openbsd.org>2006-05-28 10:15:36 +0000
commitfa55687b4e86f7a25b9d512a82714baae5978be5 (patch)
tree5caa042ef4b0e0e69f0d2a19f72223421e4fd2a5 /usr.bin
parent619566bfefb4014d70e71a968af2afff5684747f (diff)
enable basic add command, only works on files right now.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/Makefile6
-rw-r--r--usr.bin/cvs/add.c43
-rw-r--r--usr.bin/cvs/cmd.c4
-rw-r--r--usr.bin/cvs/commit.c26
4 files changed, 62 insertions, 17 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile
index c1dd20d8ca6..20f845c2afd 100644
--- a/usr.bin/cvs/Makefile
+++ b/usr.bin/cvs/Makefile
@@ -1,11 +1,11 @@
-# $OpenBSD: Makefile,v 1.23 2006/05/27 18:04:46 joris Exp $
+# $OpenBSD: Makefile,v 1.24 2006/05/28 10:15:35 joris Exp $
PROG= opencvs
MAN= cvs.1 cvsignore.5 cvsrc.5 cvswrappers.5 cvsintro.7
CPPFLAGS+=-I${.CURDIR}
-SRCS= cvs.c commit.c config.c checkout.c buf.c cmd.c date.y diff.c diff3.c \
- diff_internals.c entries.c fatal.c file.c log.c repository.c \
+SRCS= cvs.c add.c commit.c config.c checkout.c buf.c cmd.c date.y diff.c \
+ diff3.c diff_internals.c entries.c fatal.c file.c log.c repository.c \
rcs.c rcsnum.c rcstime.c root.c status.c worklist.c util.c \
update.c xmalloc.c
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c
index 9980b34e50b..1004085ee8c 100644
--- a/usr.bin/cvs/add.c
+++ b/usr.bin/cvs/add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: add.c,v 1.43 2006/05/28 07:56:44 joris Exp $ */
+/* $OpenBSD: add.c,v 1.44 2006/05/28 10:15:35 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -77,20 +77,57 @@ cvs_add(int argc, char **argv)
void
cvs_add_local(struct cvs_file *cf)
{
+ int stop, l;
+ char *entry, revbuf[16];
+ CVSENTRIES *entlist;
+
cvs_log(LP_TRACE, "cvs_add_local(%s)", cf->file_path);
cvs_file_classify(cf, 0);
+ if (cf->file_rcs != NULL)
+ rcsnum_tostr(cf->file_rcs->rf_head, revbuf, sizeof(revbuf));
+
+ stop = 0;
switch (cf->file_status) {
case FILE_ADDED:
cvs_log(LP_NOTICE, "%s has already been entered",
cf->file_path);
+ stop = 1;
+ break;
+ case FILE_UPTODATE:
+ if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 0) {
+ cvs_log(LP_NOTICE, "%s already exists, with version "
+ "number %s", cf->file_path, revbuf);
+ stop = 1;
+ }
break;
case FILE_UNKNOWN:
- cvs_log(LP_NOTICE, "%s is unknown to us so far",
- cf->file_path);
+ if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1) {
+ cvs_log(LP_NOTICE, "re-adding file %s "
+ "(instead of dead revision %s)",
+ cf->file_path, revbuf);
+ } else {
+ cvs_log(LP_NOTICE, "scheduling file '%s' for addition",
+ cf->file_path);
+ }
break;
default:
break;
}
+
+ if (stop == 1)
+ return;
+
+ entry = xmalloc(CVS_ENT_MAXLINELEN);
+ l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/0/Initial %s//",
+ cf->file_name, cf->file_name);
+
+ entlist = cvs_ent_open(cf->file_wd);
+ cvs_ent_add(entlist, entry);
+ cvs_ent_close(entlist, ENT_SYNC);
+
+ xfree(entry);
+
+ cvs_log(LP_NOTICE, "use commit to add this file permanently");
}
diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c
index 9d5df6ae04a..98dbad8eb3a 100644
--- a/usr.bin/cvs/cmd.c
+++ b/usr.bin/cvs/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.44 2006/05/27 03:30:30 joris Exp $ */
+/* $OpenBSD: cmd.c,v 1.45 2006/05/28 10:15:35 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -32,13 +32,13 @@
extern char *cvs_rootstr;
struct cvs_cmd *cvs_cdt[] = {
+ &cvs_cmd_add,
&cvs_cmd_commit,
&cvs_cmd_checkout,
&cvs_cmd_diff,
&cvs_cmd_update,
&cvs_cmd_status,
#if 0
- &cvs_cmd_add,
&cvs_cmd_admin,
&cvs_cmd_annotate,
&cvs_cmd_checkout,
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index b81e1f56cd3..4aeef771879 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.62 2006/05/28 07:56:44 joris Exp $ */
+/* $OpenBSD: commit.c,v 1.63 2006/05/28 10:15:35 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -126,7 +126,8 @@ cvs_commit_check_conflicts(struct cvs_file *cf)
cf->file_status == FILE_UNLINK)
conflicts_found++;
- if (update_has_conflict_markers(cf)) {
+ if (cf->file_status != FILE_REMOVED &&
+ update_has_conflict_markers(cf)) {
cvs_log(LP_ERR, "conflict: unresolved conflicts in %s from "
"merging, please fix these first", cf->file_path);
conflicts_found++;
@@ -149,6 +150,7 @@ void
cvs_commit_local(struct cvs_file *cf)
{
BUF *b;
+ int isadded;
char *d, *f, rbuf[24];
CVSENTRIES *entlist;
@@ -161,7 +163,8 @@ cvs_commit_local(struct cvs_file *cf)
else
strlcpy(rbuf, "Non-existent", sizeof(rbuf));
- if (cf->file_status == FILE_ADDED) {
+ 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->repo_fd < 0)
fatal("cvs_commit_local: %s", strerror(errno));
@@ -177,7 +180,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 (cf->file_status != FILE_ADDED)
+ if (isadded == 0)
d = commit_diff_file(cf);
if (cf->file_status == FILE_REMOVED) {
@@ -192,7 +195,7 @@ cvs_commit_local(struct cvs_file *cf)
cvs_buf_putc(b, '\0');
f = cvs_buf_release(b);
- if (cf->file_status != FILE_ADDED) {
+ if (isadded == 0) {
if (rcs_deltatext_set(cf->file_rcs,
cf->file_rcs->rf_head, d) == -1)
fatal("cvs_commit_local: failed to set delta");
@@ -206,7 +209,7 @@ cvs_commit_local(struct cvs_file *cf)
xfree(f);
- if (cf->file_status != FILE_ADDED)
+ if (isadded == 0)
xfree(d);
if (cf->file_status == FILE_REMOVED) {
@@ -220,7 +223,11 @@ 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) {
- strlcpy(rbuf, "Initial Revision", sizeof(rbuf));
+ if (cf->file_rcs->rf_dead == 0)
+ strlcpy(rbuf, "Initial Revision", sizeof(rbuf));
+ else
+ rcsnum_tostr(cf->file_rcs->rf_head,
+ rbuf, sizeof(rbuf));
} else if (cf->file_status == FILE_MODIFIED) {
rcsnum_tostr(cf->file_rcs->rf_head, rbuf, sizeof(rbuf));
}
@@ -253,11 +260,12 @@ commit_diff_file(struct cvs_file *cf)
char*delta, *p1, *p2;
BUF *b1, *b2, *b3;
- if (cf->file_status == FILE_MODIFIED) {
+ if (cf->file_status == FILE_MODIFIED ||
+ cf->file_status == FILE_ADDED) {
if ((b1 = cvs_buf_load(cf->file_path, BUF_AUTOEXT)) == NULL)
fatal("commit_diff_file: failed to load '%s'",
cf->file_path);
- } else if (cf->file_status == FILE_REMOVED) {
+ } else {
b1 = rcs_getrev(cf->file_rcs, cf->file_rcs->rf_head);
if (b1 == NULL)
fatal("commit_diff_file: failed to load HEAD");