svn commit: r185134 - projects/csup_cvsmode/contrib/csup

Ulf Lilleengen lulf at FreeBSD.org
Thu Nov 20 11:51:07 PST 2008


Author: lulf
Date: Thu Nov 20 19:51:06 2008
New Revision: 185134
URL: http://svn.freebsd.org/changeset/base/185134

Log:
  - Refactor some parts of the code and increase code reuse.
  - Fix a lot of style issues remaining and old debugging output.
  - Update comments where needed.

Modified:
  projects/csup_cvsmode/contrib/csup/TODO
  projects/csup_cvsmode/contrib/csup/config.c
  projects/csup_cvsmode/contrib/csup/detailer.c
  projects/csup_cvsmode/contrib/csup/diff.c
  projects/csup_cvsmode/contrib/csup/fattr.c
  projects/csup_cvsmode/contrib/csup/misc.h
  projects/csup_cvsmode/contrib/csup/rcsfile.c
  projects/csup_cvsmode/contrib/csup/rcsparse.c
  projects/csup_cvsmode/contrib/csup/rcsparse.h
  projects/csup_cvsmode/contrib/csup/rcstokenizer.l
  projects/csup_cvsmode/contrib/csup/rsyncfile.c
  projects/csup_cvsmode/contrib/csup/rsyncfile.h
  projects/csup_cvsmode/contrib/csup/status.c
  projects/csup_cvsmode/contrib/csup/stream.c
  projects/csup_cvsmode/contrib/csup/updater.c

Modified: projects/csup_cvsmode/contrib/csup/TODO
==============================================================================
--- projects/csup_cvsmode/contrib/csup/TODO	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/TODO	Thu Nov 20 19:51:06 2008	(r185134)
@@ -28,4 +28,3 @@ MISSING FEATURES:
   checkout files (files in CVS/ subdirectores), a command line override
   to only update a specific collection and a third verbosity level to
   display commit log messages.
-- Add support for CVS mode (maybe?).

Modified: projects/csup_cvsmode/contrib/csup/config.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/config.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/config.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -442,10 +442,6 @@ coll_add(char *name)
 		    "\"%s\"\n", cur_coll->co_name);
 		exit(1);
 	}
-/*	if (!(cur_coll->co_options & CO_CHECKOUTMODE)) {
-		lprintf(-1, "Client only supports checkout mode\n");
-		exit(1);
-	}*/
 	if (!STAILQ_EMPTY(&colls)) {
 		coll = STAILQ_LAST(&colls, coll, co_next);
 		if (strcmp(coll->co_host, cur_coll->co_host) != 0) {

Modified: projects/csup_cvsmode/contrib/csup/detailer.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/detailer.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/detailer.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -147,9 +147,8 @@ detailer_batch(struct detailer *d)
 		error = proto_get_time(&line, &coll->co_scantime);
 		if (error || line != NULL || strcmp(cmd, "COLL") != 0 ||
 		    strcmp(collname, coll->co_name) != 0 ||
-		    strcmp(release, coll->co_release) != 0){ 
+		    strcmp(release, coll->co_release) != 0)
 			return (DETAILER_ERR_PROTO);
-		}
 		error = proto_printf(wr, "COLL %s %s\n", coll->co_name,
 		    coll->co_release);
 		if (error)
@@ -164,9 +163,8 @@ detailer_batch(struct detailer *d)
 			return (DETAILER_ERR_MSG);
 		error = detailer_coll(d, coll, st);
 		status_close(st, NULL);
-		if (error) {
+		if (error)
 			return (error);
-		}
 		if (coll->co_options & CO_COMPRESS) {
 			stream_filter_stop(rd);
 			stream_filter_stop(wr);
@@ -174,12 +172,10 @@ detailer_batch(struct detailer *d)
 		stream_flush(wr);
 	}
 	line = stream_getln(rd, NULL);
-	if (line == NULL) {
+	if (line == NULL)
 		return (DETAILER_ERR_READ);
-	}
-	if (strcmp(line, ".") != 0) {
+	if (strcmp(line, ".") != 0)
 		return (DETAILER_ERR_PROTO);
-	}
 	error = proto_printf(wr, ".\n");
 	if (error)
 		return (DETAILER_ERR_WRITE);
@@ -235,28 +231,25 @@ detailer_coll(struct detailer *d, struct
 {
 	struct fattr *rcsattr;
 	struct stream *rd, *wr;
-	char *attr, *cmd, *file, *line, *msg, *target, *path;
+	char *attr, *cmd, *file, *line, *msg, *path, *target;
 	int error, attic;
 
 	rd = d->rd;
 	wr = d->wr;
 	attic = 0;
 	line = stream_getln(rd, NULL);
-	if (line == NULL) {
+	if (line == NULL)
 		return (DETAILER_ERR_READ);
-	}
 	while (strcmp(line, ".") != 0) {
 		cmd = proto_get_ascii(&line);
-		if (cmd == NULL || strlen(cmd) != 1) {
+		if (cmd == NULL || strlen(cmd) != 1)
 			return (DETAILER_ERR_PROTO);
-		}
 		switch (cmd[0]) {
 		case 'D':
 			/* Delete file. */
 			file = proto_get_ascii(&line);
-			if (file == NULL || line != NULL) {
+			if (file == NULL || line != NULL)
 				return (DETAILER_ERR_PROTO); 
-			}
 			error = proto_printf(wr, "D %s\n", file);
 			if (error)
 				return (DETAILER_ERR_WRITE);
@@ -370,7 +363,6 @@ detailer_dofile_regular(struct detailer 
 	int error;
 	
 	wr = d->wr;
-
 	error = stat(path, &st);
 	/* If we don't have it or it's unaccessible, we want it again. */
 	if (error) {
@@ -429,7 +421,6 @@ detailer_dofile_rcs(struct detailer *d, 
 	int error;
 
 	wr = d->wr;
-
 	path = atticpath(coll->co_prefix, name);
 	fa = fattr_frompath(path, FATTR_NOFOLLOW);
 	if (fa == NULL) {
@@ -444,7 +435,6 @@ detailer_dofile_rcs(struct detailer *d, 
 	rf = rcsfile_frompath(path, name, coll->co_cvsroot, coll->co_tag);
 	free(path);
 	if (rf == NULL) {
-		lprintf(-1, "Error parsing, resend file.\n");
 		error = proto_printf(wr, "A %s\n", name);
 		if (error)
 			return (DETAILER_ERR_WRITE);
@@ -461,18 +451,17 @@ static int
 detailer_dofile_co(struct detailer *d, struct coll *coll, struct status *st,
     char *file)
 {
-	char md5[MD5_DIGEST_SIZE];
 	struct stream *wr;
 	struct fattr *fa;
 	struct statusrec *sr;
+	char md5[MD5_DIGEST_SIZE];
 	char *path;
 	int error, ret;
 
 	wr = d->wr;
 	path = checkoutpath(coll->co_prefix, file);
-	if (path == NULL) {
+	if (path == NULL)
 		return (DETAILER_ERR_PROTO);
-	}
 	fa = fattr_frompath(path, FATTR_NOFOLLOW);
 	if (fa == NULL) {
 		/* We don't have the file, so the only option at this

Modified: projects/csup_cvsmode/contrib/csup/diff.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/diff.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/diff.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -31,9 +31,9 @@
 #include <assert.h>
 #include <err.h>
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
 
 #include "diff.h"
 #include "keyword.h"
@@ -45,7 +45,7 @@ typedef long lineno_t;
 
 #define	EC_ADD	0
 #define	EC_DEL	1
-#define MAXKEY LONG_MAX
+#define	MAXKEY	LONG_MAX
 
 /* Editing command and state. */
 struct editcmd {
@@ -75,7 +75,7 @@ static int	diff_copyln(struct editcmd *,
 static int	diff_ignoreln(struct editcmd *, lineno_t);
 static void	diff_write(struct editcmd *, void *, size_t);
 static int	diff_insert_edit(struct diffstart *, struct editcmd *);
-static int	diff_free(struct diffstart *);
+static void	diff_free(struct diffstart *);
 
 int
 diff_apply(struct stream *rd, struct stream *orig, struct stream *dest,
@@ -83,8 +83,8 @@ diff_apply(struct stream *rd, struct str
 {
 	struct editcmd ec;
 	lineno_t i;
-	char *line;
 	size_t size;
+	char *line;
 	int empty, error, noeol;
 
 	memset(&ec, 0, sizeof(ec));
@@ -159,13 +159,16 @@ diff_apply(struct stream *rd, struct str
 	return (0);
 }
 
+/*
+ * Reverse a diff using the same algorithm as in cvsup.
+ */
 static int
 diff_write_reverse(struct stream *dest, struct diffstart *ds)
 {
-	long firstoutputlinedeleted, endline, startline, editline, num_deleted,
-	    num_added;
-	int num;
 	struct editcmd *ec, *nextec;
+	long editline, endline, firstoutputlinedeleted;
+	long num_added, num_deleted, startline;
+	int num;
 
 	nextec = LIST_FIRST(&ds->dhead);
 	editline = 0;
@@ -220,7 +223,6 @@ diff_insert_edit(struct diffstart *ds, s
 	}
 
 	/* Insertion sort based on key. */
-	/* XXX: check if this gets too slow. */
 	LIST_FOREACH(curec, &ds->dhead, next) {
 		if (ec->key < curec->key) {
 			LIST_INSERT_BEFORE(curec, ec, next);
@@ -234,19 +236,16 @@ diff_insert_edit(struct diffstart *ds, s
 	return (0);
 }
 
-static int
+static void 
 diff_free(struct diffstart *ds)
 {
 	struct editcmd *ec;
-	int freecount = 0;
 
 	while(!LIST_EMPTY(&ds->dhead)) {
 		ec = LIST_FIRST(&ds->dhead);
 		LIST_REMOVE(ec, next);
 		free(ec);
-		freecount++;
 	}
-	return freecount;
 }
 
 /*
@@ -262,7 +261,6 @@ diff_reverse(struct stream *rd, struct s
 	lineno_t i;
 	char *line;
 	int error, offset;
-	int malloccount = 0, freecount = 0;
 
 	memset(&ec, 0, sizeof(ec));
 	ec.orig = orig;
@@ -280,32 +278,28 @@ diff_reverse(struct stream *rd, struct s
 	/* First we build up the list of diffs from input. */
 	while (line != NULL) {
 		error = diff_geteditcmd(&ec, line);
-		/*fprintf(stderr, "Diff line '%s'\n", line);*/
 		if (error)
 			break;
 		if (ec.cmd == EC_ADD) {
 			addec = xmalloc(sizeof(struct editcmd));
-			malloccount++;
 			*addec = ec;
 			addec->havetext = 1;
 			/* Ignore the lines we was supposed to add. */
 			for (i = 0; i < ec.count; i++) {
 				line = stream_getln(rd, NULL);
-				/*fprintf(stderr, "Diff line '%s'\n", line);*/
 				if (line == NULL)
 					return (-1);
 			}
 
 			/* Get the next diff command if we have one. */
 			addec->key = addec->where + addec->count - offset;
-			if (delec != NULL && delec->key == addec->key - addec->count) {
+			if (delec != NULL &&
+			    delec->key == addec->key - addec->count) {
 				delec->key = addec->key;
 				delec->havetext = addec->havetext;
 				delec->count = addec->count;
-
 				diff_insert_edit(&ds, delec);
 				free(addec);
-				freecount++;
 				delec = NULL;
 				addec = NULL;
 			} else {
@@ -325,7 +319,6 @@ diff_reverse(struct stream *rd, struct s
 				delec = NULL;
 			}
 			delec = xmalloc(sizeof(struct editcmd));
-			malloccount++;
 			*delec = ec;
 			delec->key = delec->where - 1 - offset;
 			delec->offset = offset;
@@ -337,18 +330,14 @@ diff_reverse(struct stream *rd, struct s
 		line = stream_getln(rd, NULL);
 	}
 
-	while (line != NULL) {
-		/*fprintf(stderr, "Diff line '%s'\n", line);*/
+	while (line != NULL)
 		line = stream_getln(rd, NULL);
-	}
-	/*fprintf(stderr, "Done with diff\n");*/
 	if (delec != NULL) {
 		diff_insert_edit(&ds, delec);
 		delec = NULL;
 	}
 
 	addec = xmalloc(sizeof(struct editcmd));
-	malloccount++;
 	/* Should be filesize, but we set it to max value. */
 	addec->key = MAXKEY;
 	addec->offset = offset;
@@ -356,12 +345,8 @@ diff_reverse(struct stream *rd, struct s
 	addec->count = 0;
 	diff_insert_edit(&ds, addec);
 	addec = NULL;
-
-	/*fprintf(stderr, "Done with last diff\n");*/
 	diff_write_reverse(dest, &ds);
-	freecount += diff_free(&ds);
-	/*fprintf(stderr, "Diff did a total of %d mallocs\n", malloccount);
-	fprintf(stderr, "Diff did a total of %d frees\n", freecount);*/
+	diff_free(&ds);
 	stream_flush(dest);
 	return (0);
 }
@@ -404,8 +389,8 @@ diff_geteditcmd(struct editcmd *ec, char
 static int
 diff_copyln(struct editcmd *ec, lineno_t to)
 {
-	char *line;
 	size_t size;
+	char *line;
 
 	while (ec->editline < to) {
 		line = stream_getln(ec->orig, &size);
@@ -421,8 +406,8 @@ diff_copyln(struct editcmd *ec, lineno_t
 static int
 diff_ignoreln(struct editcmd *ec, lineno_t to)
 {
-	char *line;
 	size_t size;
+	char *line;
 
 	while (ec->editline < to) {
 		line = stream_getln(ec->orig, &size);
@@ -437,8 +422,8 @@ diff_ignoreln(struct editcmd *ec, lineno
 static void
 diff_write(struct editcmd *ec, void *buf, size_t size)
 {
-	char *line, *newline;
 	size_t newsize;
+	char *line, *newline;
 	int ret;
 
 	line = buf;

Modified: projects/csup_cvsmode/contrib/csup/fattr.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/fattr.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/fattr.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -44,7 +44,7 @@
 /*
  * Include the appropriate definition for the file attributes we support.
  * There are two different files: fattr_bsd.h for BSD-like systems that
- * support the extended file flags ? la chflags() and fattr_posix.h for
+ * support the extended file flags a la chflags() and fattr_posix.h for
  * bare POSIX systems that don't.
  */
 #ifdef HAVE_FFLAGS
@@ -764,7 +764,8 @@ fattr_makenode(const struct fattr *fa, c
 	return (error);
 }
 
-int fattr_delete(const char *path)
+int
+fattr_delete(const char *path)
 {
 	struct fattr *fa;
 	int error;
@@ -846,9 +847,8 @@ fattr_install(struct fattr *fa, const ch
 				error = rmdir(topath);
 			else
 				error = unlink(topath);
-			if (error) {
+			if (error)
 				goto bad;
-			}
 		}
 	}
 
@@ -859,9 +859,8 @@ fattr_install(struct fattr *fa, const ch
 		tv[1].tv_sec = fa->modtime;	/* Modification time. */
 		tv[1].tv_usec = 0;
 		error = utimes(frompath, tv);
-		if (error) {
+		if (error)
 			goto bad;
-		}
 	}
 	if (mask & FA_OWNER || mask & FA_GROUP) {
 		uid = -1;

Modified: projects/csup_cvsmode/contrib/csup/misc.h
==============================================================================
--- projects/csup_cvsmode/contrib/csup/misc.h	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/misc.h	Thu Nov 20 19:51:06 2008	(r185134)
@@ -99,30 +99,30 @@ struct backoff_timer;
 struct pattlist;
 struct tm;
 
-int	 asciitoint(const char *, int *, int);
-int	 lprintf(int, const char *, ...) __printflike(2, 3);
-int	 MD5_File(char *, char *);
-void	 MD5_End(char *, MD5_CTX *);
-int	 rcsdatetotm(const char *, struct tm *);
-time_t	 rcsdatetotime(const char *);
-int	 pathcmp(const char *, const char *);
-size_t	 commonpathlength(const char *, size_t, const char *, size_t);
-const char *pathlast(const char *); /*XXX*/
-int	isrcs(const char *, size_t *);
-char	*checkoutpath(const char *, const char *);
-char	*cvspath(const char *, const char *, int);
-char	*atticpath(const char *, const char *);
-char	*path_prefix(char *);
-char	*path_first(char *);
-int	 mkdirhier(char *, mode_t);
-char	*tempname(const char *);
-void	*xmalloc(size_t);
-void	*xrealloc(void *, size_t);
-char	*xstrdup(const char *);
-int	 xasprintf(char **, const char *, ...) __printflike(2, 3);
-int	 rcsnum_cmp(char *, char *);
-int	 rcsrev_istrunk(char *);
-char	*rcsrev_prefix(char *);
+int		 asciitoint(const char *, int *, int);
+int		 lprintf(int, const char *, ...) __printflike(2, 3);
+int		 MD5_File(char *, char *);
+void		 MD5_End(char *, MD5_CTX *);
+int		 rcsdatetotm(const char *, struct tm *);
+time_t		 rcsdatetotime(const char *);
+int		 pathcmp(const char *, const char *);
+size_t		 commonpathlength(const char *, size_t, const char *, size_t);
+const char	*pathlast(const char *);
+int		 isrcs(const char *, size_t *);
+char		*checkoutpath(const char *, const char *);
+char		*cvspath(const char *, const char *, int);
+char		*atticpath(const char *, const char *);
+char		*path_prefix(char *);
+char		*path_first(char *);
+int		 mkdirhier(char *, mode_t);
+char		*tempname(const char *);
+void		*xmalloc(size_t);
+void		*xrealloc(void *, size_t);
+char		*xstrdup(const char *);
+int		 xasprintf(char **, const char *, ...) __printflike(2, 3);
+int		 rcsnum_cmp(char *, char *);
+int		 rcsrev_istrunk(char *);
+char		*rcsrev_prefix(char *);
 
 struct pattlist		*pattlist_new(void);
 void			 pattlist_add(struct pattlist *, const char *);

Modified: projects/csup_cvsmode/contrib/csup/rcsfile.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/rcsfile.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/rcsfile.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -27,19 +27,22 @@
  */
 
 #include <assert.h>
+#include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <err.h>
-#include <errno.h>
+
 #include "diff.h"
-#include "misc.h"
 #include "keyword.h"
+#include "misc.h"
+#include "proto.h"
+#include "queue.h"
 #include "rcsfile.h"
 #include "rcsparse.h"
 #include "stream.h"
-#include "proto.h"
-#include "queue.h"
+
+#define BUF_SIZE_DEFAULT	128
 
 /*
  * RCS parser library. This is the part of the library that handles the
@@ -137,6 +140,7 @@ static void		 rcsfile_insertsorteddelta(
 			     struct delta *);
 static struct stream 	*rcsfile_getdeltatext(struct rcsfile *, struct delta *,
 			     struct buf **);
+static void		 rcsdelta_writestring(char *, size_t, struct stream *);
 
 
 /* Space formatting of RCS file. */
@@ -160,10 +164,10 @@ print_stream(struct stream *s)
 
 	line = stream_getln(s, NULL);
 	while (line != NULL) {
-		fprintf(stderr, "%s\n", line);
+		lprintf(-1, "%s\n", line);
 		line = stream_getln(s, NULL);
 	}
-	fprintf(stderr, "\n");
+	lprintf(-1, "\n");
 }
 
 /*
@@ -172,9 +176,8 @@ print_stream(struct stream *s)
 struct rcsfile *
 rcsfile_frompath(char *path, char *name, char *cvsroot, char *colltag)
 {
-	FILE *infp;
 	struct rcsfile *rf;
-	char one[10] = "1";
+	FILE *infp;
 	int error;
 
 	if (path == NULL || name == NULL || cvsroot == NULL || colltag == NULL)
@@ -184,11 +187,10 @@ rcsfile_frompath(char *path, char *name,
 	rf->name = xstrdup(name);
 	rf->cvsroot = xstrdup(cvsroot);
 	rf->colltag = xstrdup(colltag);
-	/*fprintf(stderr, "Doing file %s\n", rf->name);*/
 
 	/* Initialize head branch. */
 	rf->trunk = xmalloc(sizeof(struct branch));
-	rf->trunk->revnum = xstrdup(one);
+	rf->trunk->revnum = xstrdup("1");
 	LIST_INIT(&rf->trunk->deltalist);
 	/* Initialize delta list. */
 	LIST_INIT(&rf->deltatable);
@@ -262,7 +264,8 @@ rcsfile_send_details(struct rcsfile *rf,
 		return(error);
 	/* Write expand. */
 	if (rf->expand >= 0) {
-		error = proto_printf(wr, "E %s\n", keyword_encode_expand(rf->expand));
+		error = proto_printf(wr, "E %s\n",
+		    keyword_encode_expand(rf->expand));
 		if (error)
 			return(error);
 	}
@@ -339,7 +342,7 @@ rcsfile_write(struct rcsfile *rf, struct
 
 	stream_printf(dest, "\n\n");
 
-	/* 
+	/*
 	 * Write out deltas. We use a stack where we push the appropriate deltas
 	 * that is to be written out during the loop.
 	 */
@@ -414,11 +417,11 @@ rcsfile_write_deltatext(struct rcsfile *
 {
 	STAILQ_HEAD(, delta) deltastack;
 	LIST_HEAD(, delta) branchlist_datesorted;
-	struct stream *in;
 	struct delta *d, *d_tmp, *d_next, *d_tmp2, *d_tmp3;
+	struct stream *in;
 	struct branch *b;
-	char *line;
 	size_t size;
+	char *line;
 	int error;
 
 	error = 0;
@@ -457,7 +460,8 @@ rcsfile_write_deltatext(struct rcsfile *
 			 * it like a child.
 			 */
 			if (rcsrev_istrunk(d_next->revnum))
-				STAILQ_INSERT_HEAD(&deltastack, d_next, stack_next);
+				STAILQ_INSERT_HEAD(&deltastack, d_next,
+				    stack_next);
 			else
 				LIST_INSERT_HEAD(&branchlist_datesorted, d_next,
 				    branch_next_date);
@@ -477,7 +481,8 @@ rcsfile_write_deltatext(struct rcsfile *
 
 			d_tmp2 = LIST_FIRST(&branchlist_datesorted);
 			if (rcsnum_cmp(d_tmp->revdate, d_tmp2->revdate) < 0) {
-				LIST_INSERT_BEFORE(d_tmp2, d_tmp, branch_next_date);
+				LIST_INSERT_BEFORE(d_tmp2, d_tmp,
+				    branch_next_date);
 				continue;
 			}
 			while ((d_tmp3 = LIST_NEXT(d_tmp2, branch_next_date))
@@ -489,7 +494,7 @@ rcsfile_write_deltatext(struct rcsfile *
 			}
 			LIST_INSERT_AFTER(d_tmp2, d_tmp, branch_next_date);
 		}
-		/* 
+		/*
 		 * Invert the deltalist of a branch, since we're writing them
 		 * the opposite way. 
 		 */
@@ -512,9 +517,9 @@ rcsfile_puttext(struct rcsfile *rf, stru
 	struct keyword *k;
 	struct diffinfo dibuf, *di;
 	struct buf *b;
+	size_t size;
 	char *line;
 	int error;
-	size_t size;
 
 	di = &dibuf;
 	b = NULL;
@@ -545,7 +550,7 @@ rcsfile_puttext(struct rcsfile *rf, stru
 			line = stream_getln(orig, &size);
 		}
 		stream_close(orig);
-	/* 
+	/*
 	 * A new head was probably added, and now the previous HEAD must be
 	 * changed to include the diff instead.
 	 */
@@ -570,8 +575,7 @@ rcsfile_puttext(struct rcsfile *rf, stru
 		rd = stream_open_buf(diffbase->text);
 		error = diff_reverse(rd, orig, dest, k, di);
 		if (error) {
-			fprintf(stderr, "Error applying reverse diff: %d\n",
-			    error);
+			lprintf(-1, "Error applying reverse diff: %d\n", error);
 			goto cleanup;
 		}
 		keyword_free(k);
@@ -601,7 +605,10 @@ rcsfile_getdeltatext(struct rcsfile *rf,
 	buf_orig = NULL;
 	error = 0;
 
-	/* If diffbase is NULL or we are head (the old head), we have a normal complete deltatext. */
+	/*
+	 * If diffbase is NULL or we are head (the old head), we have a normal
+	 * complete deltatext.
+	 */
 	if (d->diffbase == NULL && !strcmp(rf->head, d->revnum)) {
 		orig = stream_open_buf(d->text);
 		return (orig);
@@ -617,7 +624,7 @@ rcsfile_getdeltatext(struct rcsfile *rf,
 	 * Now that we are sure we have a complete deltatext in ret, let's apply
 	 * our diff to it.
 	 */
-	*buf_dest = buf_new(128);
+	*buf_dest = buf_new(BUF_SIZE_DEFAULT);
 	dest = stream_open_buf(*buf_dest);
 
 	di->di_rcsfile = rf->name;
@@ -655,52 +662,51 @@ rcsfile_print(struct rcsfile *rf)
 	struct delta *d;
 	struct tag *t;
 	struct string *s;
-	char *line;
 	struct stream *in;
+	char *line;
 
-	printf("\n");
+	lprintf(1, "\n");
 	if (rf->name != NULL)
-		printf("name: '%s'\n", rf->name);
+		lprintf(1, "name: '%s'\n", rf->name);
 	if (rf->head != NULL)
-		printf("head: '%s'\n", rf->head);
+		lprintf(1, "head: '%s'\n", rf->head);
 	if (rf->branch != NULL)
-		printf("branch: '%s'\n", rf->branch);
-	printf("Access: ");
-	STAILQ_FOREACH(s, &rf->accesslist, string_next) {
-		printf("'%s' ", s->str);
-	}
-	printf("\n");
+		lprintf(1, "branch: '%s'\n", rf->branch);
+	lprintf(1, "Access: ");
+	STAILQ_FOREACH(s, &rf->accesslist, string_next)
+		lprintf(1, "'%s' ", s->str);
+	lprintf(1, "\n");
 
 	/* Print all tags. */
 	STAILQ_FOREACH(t, &rf->taglist, tag_next) {
-		printf("Tag: ");
+		lprintf(1, "Tag: ");
 		if (t->tag != NULL)
-			printf("name: %s ", t->tag);
+			lprintf(1, "name: %s ", t->tag);
 		if (t->revnum != NULL)
-			printf("rev: %s", t->revnum);
-		printf("\n");
+			lprintf(1, "rev: %s", t->revnum);
+		lprintf(1, "\n");
 	}
 
 	if (rf->strictlock)
-		printf("Strict!\n");
+		lprintf(1, "Strict!\n");
 	if (rf->comment != NULL)
-		printf("comment: '%s'\n", rf->comment);
+		lprintf(1, "comment: '%s'\n", rf->comment);
 	if (rf->expand >= 0)
-		printf("expand: '%s'\n", keyword_encode_expand(rf->expand));
+		lprintf(1, "expand: '%s'\n", keyword_encode_expand(rf->expand));
 	
 	/* Print all deltas. */
 	LIST_FOREACH(d, &rf->deltatable, table_next) {
-		printf("Delta: ");
+		lprintf(1, "Delta: ");
 		if (d->revdate != NULL)
-			printf("date: %s ", d->revdate);
+			lprintf(1, "date: %s ", d->revdate);
 		if (d->revnum != NULL)
-			printf("rev: %s", d->revnum);
+			lprintf(1, "rev: %s", d->revnum);
 		if (d->author != NULL)
-			printf("author: %s", d->author);
+			lprintf(1, "author: %s", d->author);
 		if (d->state != NULL)
-			printf("state: %s", d->state);
+			lprintf(1, "state: %s", d->state);
 
-		printf("Text:\n");
+		lprintf(1, "Text:\n");
 		in = stream_open_buf(d->text);
 		line = stream_getln(in, NULL);
 		while (line != NULL) {
@@ -708,11 +714,11 @@ rcsfile_print(struct rcsfile *rf)
 			line = stream_getln(in, NULL);
 		}
 		stream_close(in);
-		printf("\n");
+		lprintf(1, "\n");
 	}
 
 	if (rf->desc != NULL)
-		printf("desc: '%s'\n", rf->desc);
+		lprintf(1, "desc: '%s'\n", rf->desc);
 }
 
 /* Free all memory associated with a struct rcsfile. */
@@ -950,9 +956,8 @@ rcsfile_createdelta(char *revnum)
 	d->revdate = NULL;
 	d->state = NULL;
 	d->author = NULL;
-	/* XXX: default. */
-	d->log = buf_new(128);
-	d->text = buf_new(128);
+	d->log = buf_new(BUF_SIZE_DEFAULT);
+	d->text = buf_new(BUF_SIZE_DEFAULT);
 	d->diffbase = NULL;
 
 	STAILQ_INIT(&d->branchlist);
@@ -982,8 +987,8 @@ rcsfile_addelta(struct rcsfile *rf, char
 	d->diffbase = rcsfile_getdelta(rf, diffbase);
 
 	/* If it's trunk, insert it in the head branch list. */
-	b = rcsrev_istrunk(d->revnum) ? rf->trunk : rcsfile_getbranch(rf,
-	    d->revnum);
+	b = rcsrev_istrunk(d->revnum) ? rf->trunk :
+	    rcsfile_getbranch(rf, d->revnum);
 
 	/*
 	 * We didn't find a branch, check if we can find a branchpoint and
@@ -1086,7 +1091,6 @@ rcsfile_importdelta(struct rcsfile *rf, 
 
 	/* Insert if not a placeholder. */ 
 	if (!d->placeholder) {
-		/*fprintf(stderr, "Insert %s\n", d->revnum);*/
 		/* Insert both into the tree, and into the lookup list. */
 		if (rcsrev_istrunk(d->revnum))
 			rcsfile_insertdelta(b, d, 1);
@@ -1129,8 +1133,7 @@ rcsfile_getbranch(struct rcsfile *rf, ch
 {
 	struct branch *b;
 	struct delta *d;
-	char *branchrev;
-	char *bprev;
+	char *branchrev, *bprev;
 
 	branchrev = rcsrev_prefix(revnum);
 	bprev = rcsrev_prefix(branchrev);
@@ -1146,49 +1149,6 @@ rcsfile_getbranch(struct rcsfile *rf, ch
 	return (NULL);
 }
 
-#if 0
-/* Add a new branch to a delta. */
-void
-rcsfile_addbranch(struct rcsfile *rf, char *branch)
-{
-	struct delta *d;
-	struct branch *b;
-	char *branchrev, *deltarev;
-	int trunk;
-
-	/* 
-	 * Branchrev is our branches revision, the delta actual delta will be
-	 * taken care of later.
-	 */
-	branchrev = rcsrev_prefix(branch);
-	deltarev = rcsrev_prefix(branchrev);
-
-	/* XXX: Could we refer to a delta that is not added yet? If we're
-	 * refferring to branches without having been added before, this could
-	 * happen in the head branch.
-	 */
-	/*fprintf(stderr, "Add branch %s to delta %s\n", branchrev, deltarev);*/
-	d = rcsfile_getdelta(rf, deltarev);
-	if (d == NULL) {
-		/* We must create a placeholder for the delta holding the
-		 * branch. */
-		d = rcsfile_createdelta(deltarev);
-		d->placeholder = 1;
-		/* XXX: Can we assume this branch exists? */
-		trunk = rcsrev_istrunk(d->revnum);
-		b = trunk ? rf->trunk : rcsfile_getbranch(rf, d->revnum);
-		rcsfile_insertdelta(b, d, trunk);
-		rcsfile_insertsorteddelta(rf, d);
-	}
-	b = xmalloc(sizeof(struct branch));
-	b->revnum = branchrev;
-	LIST_INIT(&b->deltalist);
-	STAILQ_INSERT_HEAD(&d->branchlist, b, branch_next);
-	/* Free only deltarev, branchrev is used by branch. */
-	free(deltarev);
-}
-#endif
-
 /*
  * Insert a delta into the correct place in the table of the rcsfile. Sorted by
  * date.
@@ -1240,8 +1200,6 @@ rcsfile_insertdelta(struct branch *b, st
 	 */
 	LIST_FOREACH(d2, &b->deltalist, delta_next) {
 		if (trunk) {
-			/*fprintf(stderr, "Comparing %s and %s\n", d->revnum,
-			 * d2->revnum);*/
 			if (rcsnum_cmp(d->revnum, d2->revnum) >= 0) {
 				LIST_INSERT_BEFORE(d2, d, delta_next);
 				return;
@@ -1299,24 +1257,10 @@ void
 rcsdelta_appendlog(struct delta *d, char *logline, size_t size)
 {
 	struct stream *dest;
-	char buf[3];
-	size_t i;
-	int count;
 
 	assert(d != NULL);
 	dest = stream_open_buf(d->log);
-	for (i = 0; i < size; i++) {
-		buf[0] = logline[i];
-		buf[1] = '\0';
-		count = 1;
-		/* Expand @'s */
-		if (buf[0] == '@') {
-			buf[1] = '@';
-			buf[2] = '\0';
-			count = 2;
-		}
-		stream_write(dest, buf, count);
-	}
+	rcsdelta_writestring(logline, size, dest);
 	stream_close(dest);
 }
 
@@ -1325,13 +1269,20 @@ void
 rcsdelta_appendtext(struct delta *d, char *textline, size_t size)
 {
 	struct stream *dest;
+
+	assert(d != NULL);
+	dest = stream_open_buf(d->text);
+	rcsdelta_writestring(textline, size, dest);
+	stream_close(dest);
+}
+
+static void
+rcsdelta_writestring(char *textline, size_t size, struct stream *dest)
+{
 	char buf[3];
 	size_t i;
 	int count;
 
-	assert(d != NULL);
-	dest = stream_open_buf(d->text);
-	/* XXX: code reuse. */
 	for (i = 0; i < size; i++) {
 		buf[0] = textline[i];
 		buf[1] = '\0';
@@ -1344,11 +1295,8 @@ rcsdelta_appendtext(struct delta *d, cha
 		}
 		stream_write(dest, buf, count);
 	}
-
-	stream_close(dest);
 }
 
-
 /* Set delta state. */
 void
 rcsdelta_setstate(struct delta *d, char *state)
@@ -1364,7 +1312,6 @@ rcsdelta_setstate(struct delta *d, char 
 }
 
 /* Truncate the deltalog with a certain offset. */
-/* XXX: error values for these. */
 void
 rcsdelta_truncatelog(struct delta *d, off_t offset)
 {

Modified: projects/csup_cvsmode/contrib/csup/rcsparse.c
==============================================================================
--- projects/csup_cvsmode/contrib/csup/rcsparse.c	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/rcsparse.c	Thu Nov 20 19:51:06 2008	(r185134)
@@ -24,16 +24,17 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD$
- * 
  */
 
-#include <stdlib.h>
 #include <assert.h>
-#include "rcstokenizer.h"
-#include "rcsparse.h"
-#include "rcsfile.h"
+#include <stdio.h>
+#include <stdlib.h>
+
 #include "misc.h"
 #include "queue.h"
+#include "rcsfile.h"
+#include "rcsparse.h"
+#include "rcstokenizer.h"
 
 /*
  * This is an RCS-parser using lex for tokenizing and makes sure the RCS syntax
@@ -108,13 +109,7 @@ rcsparse_run(struct rcsfile *rf, FILE *i
 static int
 parse_admin(struct rcsfile *rf, yyscan_t *sp)
 {
-	char *head;
-	char *branch;
-	char *comment;
-	char *id;
-	char *expand;
-	char *tag, *revnum;
-	char *tmp;
+	char *branch, *comment, *expand, *head, *id, *revnum, *tag, *tmp;
 	int strict, token;
 
 	strict = 0;
@@ -169,7 +164,7 @@ parse_admin(struct rcsfile *rf, yyscan_t
 	asserttoken(sp, KEYWORD);
 	token = rcslex(*sp);
 	while (token == ID) {
-		/* XXX: skip locks */
+		/* XXX: locks field is skipped */
 		asserttoken(sp, COLON);
 		asserttoken(sp, NUM);
 		token = rcslex(*sp);
@@ -206,7 +201,7 @@ parse_admin(struct rcsfile *rf, yyscan_t
 		token = rcslex(*sp);
 		while (token == ID) {
 			token = rcslex(*sp);
-			/* XXX: ignore for now. */
+			/* XXX: newphrases ignored */
 			while (token == ID || token == NUM || token == STRING ||
 			    token == COLON) {
 				token = rcslex(*sp);
@@ -274,7 +269,7 @@ parse_deltas(struct rcsfile *rf, yyscan_
 		token = rcslex(*sp);
 		while (token == ID) {
 			token = rcslex(*sp);
-			/* XXX: ignore for now. */
+			/* XXX: newphrases ignored. */
 			while (token == ID || token == NUM || token == STRING ||
 			    token == COLON) {
 				token = rcslex(*sp);
@@ -302,15 +297,13 @@ static int
 parse_deltatexts(struct rcsfile *rf, yyscan_t *sp, int token)
 {
 	struct delta *d;
-	char *revnum, *log, *text;
+	char *log, *revnum, *text;
 	int error;
 
 	error = 0;
 	/* In case we don't have deltatexts. */
-	if (token != NUM) {
-		fprintf(stderr, "Tokens Was %d\n", token);
+	if (token != NUM)
 		return (token);
-	}
 	do {
 		/* num */
 		assert(token == NUM);
@@ -331,7 +324,7 @@ parse_deltatexts(struct rcsfile *rf, yys
 		token = rcslex(*sp);
 		while (token == ID) {
 			token = rcslex(*sp);
-			/* XXX: ignore for now. */
+			/* XXX: newphrases ignored. */
 			while (token == ID || token == NUM || token == STRING ||
 			    token == COLON) {
 				token = rcslex(*sp);
@@ -344,7 +337,7 @@ parse_deltatexts(struct rcsfile *rf, yys
 		asserttoken(sp, STRING);
 		text = duptext(sp);
 		error = rcsdelta_addtext(d, text);
-		/* 
+		/*
 		 * If this happens, something is wrong with the RCS file, and it
 		 * should be resent.
 		 */

Modified: projects/csup_cvsmode/contrib/csup/rcsparse.h
==============================================================================
--- projects/csup_cvsmode/contrib/csup/rcsparse.h	Thu Nov 20 18:44:09 2008	(r185133)
+++ projects/csup_cvsmode/contrib/csup/rcsparse.h	Thu Nov 20 19:51:06 2008	(r185134)
@@ -24,19 +24,18 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD$
- * 
  */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-projects mailing list