diff --git a/contrib/csup/TODO b/contrib/csup/TODO index 66988e1780b0..41b2408766f2 100644 --- a/contrib/csup/TODO +++ b/contrib/csup/TODO @@ -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?). diff --git a/contrib/csup/config.c b/contrib/csup/config.c index 393a3db58293..55aaf5ce63d8 100644 --- a/contrib/csup/config.c +++ b/contrib/csup/config.c @@ -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) { diff --git a/contrib/csup/detailer.c b/contrib/csup/detailer.c index b07a4aeb0e90..20436c6a2129 100644 --- a/contrib/csup/detailer.c +++ b/contrib/csup/detailer.c @@ -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 coll *coll, struct status *st) { 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 *d, char *name, char *path) 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, struct coll *coll, char *name, 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, struct coll *coll, char *name, 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 diff --git a/contrib/csup/diff.c b/contrib/csup/diff.c index f4d73faa5740..9a0f5fe924fb 100644 --- a/contrib/csup/diff.c +++ b/contrib/csup/diff.c @@ -31,9 +31,9 @@ #include #include #include +#include #include #include -#include #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 *, lineno_t); 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 stream *orig, struct stream *dest, { 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 stream *orig, struct stream *dest, 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, struct editcmd *ec) } /* 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, struct editcmd *ec) 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 stream *orig, struct stream *dest, 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 stream *orig, struct stream *dest, /* 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 stream *orig, struct stream *dest, 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 stream *orig, struct stream *dest, 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 stream *orig, struct stream *dest, 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 *line) 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 to) 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_t to) 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; diff --git a/contrib/csup/fattr.c b/contrib/csup/fattr.c index 53df588f4bf3..c8409b6ef86e 100644 --- a/contrib/csup/fattr.c +++ b/contrib/csup/fattr.c @@ -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, const char *path) 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 char *topath, const char *frompath) error = rmdir(topath); else error = unlink(topath); - if (error) { + if (error) goto bad; - } } } @@ -859,9 +859,8 @@ fattr_install(struct fattr *fa, const char *topath, const char *frompath) 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; diff --git a/contrib/csup/misc.h b/contrib/csup/misc.h index 1f6d8b245ec6..a7ca3a625ac0 100644 --- a/contrib/csup/misc.h +++ b/contrib/csup/misc.h @@ -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 *); diff --git a/contrib/csup/rcsfile.c b/contrib/csup/rcsfile.c index 9a715d6a33c5..5e192055bbd0 100644 --- a/contrib/csup/rcsfile.c +++ b/contrib/csup/rcsfile.c @@ -27,19 +27,22 @@ */ #include +#include +#include #include #include #include -#include -#include + #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 rcsfile *, 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, char *cvsroot, char *colltag) 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, struct stream *wr) 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 *dest) 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 *rf, struct stream *dest) { 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 *rf, struct stream *dest) * 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 *rf, struct stream *dest) 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 *rf, struct stream *dest) } 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, struct stream *dest, struct delta *d, 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, struct stream *dest, struct delta *d, 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, struct stream *dest, struct delta *d, 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, struct delta *d, struct buf **buf_dest) 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, struct delta *d, struct buf **buf_dest) * 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 *revnum, char *revdate, char *author, 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, char *revnum, char *revdate, char *autho /* 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, char *revnum) { 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, char *revnum) 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, struct delta *d, int trunk) */ 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, char *textline, size_t size) } 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 *state) } /* Truncate the deltalog with a certain offset. */ -/* XXX: error values for these. */ void rcsdelta_truncatelog(struct delta *d, off_t offset) { diff --git a/contrib/csup/rcsparse.c b/contrib/csup/rcsparse.c index 88a376291a49..ab9786685a41 100644 --- a/contrib/csup/rcsparse.c +++ b/contrib/csup/rcsparse.c @@ -24,16 +24,17 @@ * SUCH DAMAGE. * * $FreeBSD$ - * */ -#include #include -#include "rcstokenizer.h" -#include "rcsparse.h" -#include "rcsfile.h" +#include +#include + #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 *infp) 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 *sp) 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 *sp) 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_t *sp, int token) 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, yyscan_t *sp, int token) 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, yyscan_t *sp, int token) 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. */ diff --git a/contrib/csup/rcsparse.h b/contrib/csup/rcsparse.h index 9eacbc89f0a5..21051e585c21 100644 --- a/contrib/csup/rcsparse.h +++ b/contrib/csup/rcsparse.h @@ -24,19 +24,18 @@ * SUCH DAMAGE. * * $FreeBSD$ - * */ #ifndef _RCSPARSE_H_ #define _RCSPARSE_H_ -#define ID 0 -#define NUM 1 -#define KEYWORD 2 -#define KEYWORD_TWO 3 -#define STRING 4 -#define SEMIC 5 -#define COLON 6 +#define ID 0 +#define NUM 1 +#define KEYWORD 2 +#define KEYWORD_TWO 3 +#define STRING 4 +#define SEMIC 5 +#define COLON 6 struct rcsfile; int rcsparse_run(struct rcsfile *, FILE *); -#endif +#endif /* !_RCSPARSE_H_ */ diff --git a/contrib/csup/rcstokenizer.l b/contrib/csup/rcstokenizer.l index 583bcbe1c81f..63d2ef51d704 100644 --- a/contrib/csup/rcstokenizer.l +++ b/contrib/csup/rcstokenizer.l @@ -24,7 +24,6 @@ * SUCH DAMAGE. * * $FreeBSD$ - * */ /* @@ -32,6 +31,7 @@ */ %{ #include + #include "misc.h" #include "rcsparse.h" diff --git a/contrib/csup/rsyncfile.c b/contrib/csup/rsyncfile.c index 474c5366b5ec..30ccc30665f1 100644 --- a/contrib/csup/rsyncfile.c +++ b/contrib/csup/rsyncfile.c @@ -66,8 +66,8 @@ struct rsyncfile { uint32_t rsum; }; -static size_t rsync_chooseblocksize(size_t); -static uint32_t rsync_rollsum(char *, size_t); +static size_t rsync_chooseblocksize(size_t); +static uint32_t rsync_rollsum(char *, size_t); /* Open a file and initialize variable for rsync operation. */ struct rsyncfile * diff --git a/contrib/csup/rsyncfile.h b/contrib/csup/rsyncfile.h index bfe1ad18e9ba..8609ed56d939 100644 --- a/contrib/csup/rsyncfile.h +++ b/contrib/csup/rsyncfile.h @@ -30,13 +30,12 @@ #define _RSYNCFILE_H_ struct rsyncfile; - -struct rsyncfile *rsync_open(char *, size_t, int); -int rsync_nextblock(struct rsyncfile *); -char *rsync_rsum(struct rsyncfile *); -char *rsync_blockmd5(struct rsyncfile *); -int rsync_close(struct rsyncfile *); -size_t rsync_blocksize(struct rsyncfile *); -size_t rsync_filesize(struct rsyncfile *); +struct rsyncfile *rsync_open(char *, size_t, int); +int rsync_nextblock(struct rsyncfile *); +char *rsync_rsum(struct rsyncfile *); +char *rsync_blockmd5(struct rsyncfile *); +int rsync_close(struct rsyncfile *); +size_t rsync_blocksize(struct rsyncfile *); +size_t rsync_filesize(struct rsyncfile *); #endif /* !_RSYNCFILE_H_ */ diff --git a/contrib/csup/status.c b/contrib/csup/status.c index 9e1a2c00517d..3482e8ee7be1 100644 --- a/contrib/csup/status.c +++ b/contrib/csup/status.c @@ -170,7 +170,6 @@ status_rd(struct status *st) error = statusrec_cook(sr, line); if (error) { st->error = STATUS_ERR_PARSE; - printf("ERROR HERE\n"); return (NULL); } return (sr); diff --git a/contrib/csup/stream.c b/contrib/csup/stream.c index 7ea651515f7f..aa229b497164 100644 --- a/contrib/csup/stream.c +++ b/contrib/csup/stream.c @@ -1209,8 +1209,8 @@ md5rcsfilter_flush(struct stream *stream, struct buf *buf, stream_flush_t how) int error; mf = stream->fdata; - space[1] = '\0'; space[0] = ' '; + space[1] = '\0'; ptr = buf->buf + buf->off; end = buf->buf + buf->off + buf->in; diff --git a/contrib/csup/updater.c b/contrib/csup/updater.c index ede4af59169c..ef2aba345dee 100644 --- a/contrib/csup/updater.c +++ b/contrib/csup/updater.c @@ -58,7 +58,7 @@ #define UPDATER_ERR_READ (-3) /* Error reading from server. */ #define UPDATER_ERR_DELETELIM (-4) /* File deletion limit exceeded. */ -#define BUFSIZE 1024 +#define BUFSIZE 4096 /* Everything needed to update a file. */ struct file_update { @@ -347,13 +347,13 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) struct coll *coll; struct statusrec srbuf, *sr; struct fattr *rcsattr, *tmp; - char *cmd, *blocksize, *line, *msg, *attr; + char *attr, *cmd, *blocksize, *line, *msg; char *name, *tag, *date, *revdate; char *expand, *wantmd5, *revnum; char *optstr, *rcsopt, *pos; time_t t; off_t position; - int error, needfixupmsg; + int attic, error, needfixupmsg; error = 0; rd = up->rd; @@ -410,7 +410,7 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) return (UPDATER_ERR_PROTO); /* Theoritically, the file does not exist on the client. Just to make sure, we'll delete it here, if it - exists. */ + exists. */ if (access(fup->destpath, F_OK) == 0) { error = updater_delete(up, fup); if (error) @@ -560,45 +560,29 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) return (UPDATER_ERR_MSG); } break; - case 'a': - name = proto_get_ascii(&line); - attr = proto_get_ascii(&line); - if (name == NULL || attr == NULL || line != NULL) - return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 1); - if (error) - return (UPDATER_ERR_PROTO); - fup->temppath = tempname(fup->destpath); - sr = &fup->srbuf; - sr->sr_type = SR_FILEDEAD; - sr->sr_file = xstrdup(name); - sr->sr_serverattr = fattr_decode(attr); - if (sr->sr_serverattr == NULL) - return (UPDATER_ERR_PROTO); - lprintf(1, " Create %s -> Attic\n", name); - error = updater_addfile(up, fup, attr, 0); - if (error) - return (error); - break; - case 'A': - case 'R': // XXX + case 'a': + case 'R': name = proto_get_ascii(&line); attr = proto_get_ascii(&line); if (name == NULL || attr == NULL || line != NULL) return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 0); + attic = (cmd[0] == 'a'); + error = fup_prepare(fup, name, attic); if (error) return (UPDATER_ERR_PROTO); fup->temppath = tempname(fup->destpath); sr = &fup->srbuf; - sr->sr_type = SR_FILELIVE; + sr->sr_type = attic ? SR_FILEDEAD : SR_FILELIVE; sr->sr_file = xstrdup(name); sr->sr_serverattr = fattr_decode(attr); if (sr->sr_serverattr == NULL) return (UPDATER_ERR_PROTO); - lprintf(1, " Create %s\n", name); + if (attic) + lprintf(1, " Create %s -> Attic\n", name); + else + lprintf(1, " Create %s\n", name); error = updater_addfile(up, fup, attr, 0); if (error) return (error); @@ -628,7 +612,6 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) if (error) return (error); break; - case 'I': /* * Create directory and add DirDown entry in status @@ -714,13 +697,7 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) return (UPDATER_ERR_MSG); } break; -#if 0 - case 'h': - /* XXX: SR_LINKFILEDEAD. */ - case 'H': - lprintf(1, "Got 'H'\n"); - break; -#endif + case 'L': case 'l': name = proto_get_ascii(&line); if (name == NULL) @@ -728,9 +705,9 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) attr = proto_get_ascii(&line); if (attr == NULL || line != NULL) return (UPDATER_ERR_PROTO); - + attic = (cmd[0] == 'l'); sr = &fup->srbuf; - sr->sr_type = SR_FILEDEAD; + sr->sr_type = attic ? SR_FILEDEAD : SR_FILELIVE; sr->sr_file = xstrdup(name); sr->sr_serverattr = fattr_decode(attr); sr->sr_clientattr = fattr_decode(attr); @@ -750,62 +727,18 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) return (UPDATER_ERR_MSG); } break; - case 'L': - name = proto_get_ascii(&line); - if (name == NULL) - return (UPDATER_ERR_PROTO); - attr = proto_get_ascii(&line); - if (attr == NULL || line != NULL) - return (UPDATER_ERR_PROTO); - - sr = &fup->srbuf; - sr->sr_type = SR_FILELIVE; - sr->sr_file = xstrdup(name); - sr->sr_serverattr = fattr_decode(attr); - sr->sr_clientattr = fattr_decode(attr); - if (sr->sr_serverattr == NULL || - sr->sr_clientattr == NULL) - return (UPDATER_ERR_PROTO); - /* Save space. Described in detail in updatefile. */ - if (!(fattr_getmask(sr->sr_clientattr) & FA_LINKCOUNT) - || fattr_getlinkcount(sr->sr_clientattr) <= 1) - fattr_maskout(sr->sr_clientattr, - FA_DEV | FA_INODE); - fattr_maskout(sr->sr_clientattr, FA_FLAGS); - error = status_put(fup->st, sr); - if (error) { - up->errmsg = status_errmsg(fup->st); - return (UPDATER_ERR_MSG); - } - break; + case 'N': case 'n': name = proto_get_ascii(&line); attr = proto_get_ascii(&line); if (name == NULL || attr == NULL || line != NULL) return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 1); + attic = (cmd[0] == 'n'); + error = fup_prepare(fup, name, attic); if (error) return (UPDATER_ERR_PROTO); sr = &fup->srbuf; - sr->sr_type = SR_FILEDEAD; - sr->sr_file = xstrdup(name); - sr->sr_serverattr = fattr_decode(attr); - sr->sr_clientattr = fattr_new(FT_SYMLINK, -1); - fattr_mergedefault(sr->sr_clientattr); - error = updater_updatenode(up, coll, fup, name, attr); - if (error) - return (error); - break; - case 'N': - name = proto_get_ascii(&line); - attr = proto_get_ascii(&line); - if (name == NULL || attr == NULL || line != NULL) - return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 0); - if (error) - return (UPDATER_ERR_PROTO); - sr = &fup->srbuf; - sr->sr_type = SR_FILELIVE; + sr->sr_type = (attic ? SR_FILEDEAD : SR_FILELIVE); sr->sr_file = xstrdup(name); sr->sr_serverattr = fattr_decode(attr); sr->sr_clientattr = fattr_new(FT_SYMLINK, -1); @@ -815,93 +748,52 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) if (error) return (error); break; + case 'V': case 'v': name = proto_get_ascii(&line); attr = proto_get_ascii(&line); optstr = proto_get_ascii(&line); wantmd5 = proto_get_ascii(&line); - rcsopt = NULL; /*rcs_decode(optstr);*/ + rcsopt = NULL; /* XXX: Not supported. */ if (attr == NULL || line != NULL || wantmd5 == NULL) return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 1); + attic = (cmd[0] == 'v'); + error = fup_prepare(fup, name, attic); if (error) return (UPDATER_ERR_PROTO); fup->temppath = tempname(fup->destpath); fup->wantmd5 = xstrdup(wantmd5); sr = &fup->srbuf; - sr->sr_type = SR_FILEDEAD; + sr->sr_type = attic ? SR_FILEDEAD : SR_FILELIVE; sr->sr_file = xstrdup(name); sr->sr_serverattr = fattr_decode(attr); if (sr->sr_serverattr == NULL) return (UPDATER_ERR_PROTO); error = 0; - error = updater_rcsedit(up, fup, name, rcsopt); - if (error) - return (error); - break; - case 'V': - name = proto_get_ascii(&line); - attr = proto_get_ascii(&line); - optstr = proto_get_ascii(&line); - wantmd5 = proto_get_ascii(&line); - rcsopt = NULL; /*rcs_decode(optstr);*/ - if (attr == NULL || line != NULL || wantmd5 == NULL) - return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 0); - if (error) - return (UPDATER_ERR_PROTO); - fup->temppath = tempname(fup->destpath); - fup->wantmd5 = xstrdup(wantmd5); - sr = &fup->srbuf; - sr->sr_type = SR_FILELIVE; - sr->sr_file = xstrdup(name); - sr->sr_serverattr = fattr_decode(attr); - if (sr->sr_serverattr == NULL) - return (UPDATER_ERR_PROTO); - error = updater_rcsedit(up, fup, name, rcsopt); if (error) return (error); break; case 'X': - name = proto_get_ascii(&line); - attr = proto_get_ascii(&line); - if (name == NULL || attr == NULL || line != NULL) - return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 0); - if (error) - return (UPDATER_ERR_PROTO); - - fup->temppath = tempname(fup->destpath); - sr = &fup->srbuf; - sr->sr_type = SR_FILELIVE; - sr->sr_file = xstrdup(name); - sr->sr_serverattr = fattr_decode(attr); - if (sr->sr_serverattr == NULL) - return (UPDATER_ERR_PROTO); - lprintf(1, " Fixup %s\n", name); - error = updater_addfile(up, fup, attr, 1); - if (error) - return (error); - break; case 'x': name = proto_get_ascii(&line); attr = proto_get_ascii(&line); if (name == NULL || attr == NULL || line != NULL) return (UPDATER_ERR_PROTO); - error = fup_prepare(fup, name, 1); + attic = (cmd[0] == 'x'); + error = fup_prepare(fup, name, attic); if (error) return (UPDATER_ERR_PROTO); fup->temppath = tempname(fup->destpath); sr = &fup->srbuf; - sr->sr_type = SR_FILEDEAD; + sr->sr_type = attic ? SR_FILEDEAD : SR_FILELIVE; sr->sr_file = xstrdup(name); sr->sr_serverattr = fattr_decode(attr); if (sr->sr_serverattr == NULL) return (UPDATER_ERR_PROTO); - lprintf(1, " Fixup %s -> Attic\n", name); + lprintf(1, " Fixup %s\n", name); error = updater_addfile(up, fup, attr, 1); if (error) return (error); @@ -933,7 +825,6 @@ updater_docoll(struct updater *up, struct file_update *fup, int isfixups) lprintf(-1, "Server warning: %s\n", msg); break; default: - lprintf(-1, "Unknown command: %s\n", cmd); return (UPDATER_ERR_PROTO); } fup_cleanup(fup); @@ -1123,8 +1014,6 @@ updater_updatefile(struct updater *up, struct file_update *fup, if (coll->co_options & CO_CHECKOUTMODE) fattr_maskout(sr->sr_clientattr, FA_COIGNORE); - /* XXX: Mask out chflags for now. Cvsup doesn't record them. */ - /*fattr_maskout(sr->sr_clientattr, FA_FLAGS);*/ error = status_put(st, sr); if (error) { up->errmsg = status_errmsg(st); @@ -1408,7 +1297,10 @@ updater_updatenode(struct updater *up, struct coll *coll, struct file_update *fu "\"%s\": %s", fup->destpath, strerror(errno)); return (UPDATER_ERR_MSG); } - /* XXX Executes */ + /* + * XXX: Executes not implemented. Have not encountered much use for it + * yet. + */ /* * We weren't necessarily able to set all the file attributes to the * desired values, and any executes may have altered the attributes. @@ -1462,21 +1354,19 @@ static int updater_addfile(struct updater *up, struct file_update *fup, char *attr, int isfixup) { - char md5[MD5_DIGEST_SIZE]; struct coll *coll; struct stream *to; struct statusrec *sr; struct fattr *fa; - char *path, *line, *cmd; - int error; - off_t fsize; char buf[BUFSIZE]; + char md5[MD5_DIGEST_SIZE]; ssize_t nread; - off_t remains; + off_t fsize, remains; + char *cmd, *line, *path; + int error; coll = fup->coll; path = fup->destpath; - nread = 0; sr = &fup->srbuf; fa = fattr_decode(attr); fsize = fattr_filesize(fa); @@ -1484,7 +1374,6 @@ updater_addfile(struct updater *up, struct file_update *fup, char *attr, error = mkdirhier(path, coll->co_umask); if (error) return (UPDATER_ERR_PROTO); - to = stream_open_file(fup->temppath, O_WRONLY | O_CREAT | O_TRUNC, 0755); if (to == NULL) { xasprintf(&up->errmsg, "%s: Cannot create: %s", @@ -1515,7 +1404,6 @@ updater_addfile(struct updater *up, struct file_update *fup, char *attr, if (fup->wantmd5 == NULL || line != NULL || strcmp(cmd, "5") != 0) return (UPDATER_ERR_PROTO); - /* UPDATE FILE. */ sr->sr_clientattr = fattr_frompath(fup->temppath, FATTR_NOFOLLOW); if (sr->sr_clientattr == NULL) return (UPDATER_ERR_PROTO); @@ -1523,7 +1411,6 @@ updater_addfile(struct updater *up, struct file_update *fup, char *attr, FA_MODTIME | FA_MASK); error = updater_updatefile(up, fup, md5, isfixup); fup->wantmd5 = NULL; /* So that it doesn't get freed. */ - /* UPDATE IT. */ if (error) return (error); return (0); @@ -1536,9 +1423,9 @@ updater_checkout(struct updater *up, struct file_update *fup, int isfixup) struct statusrec *sr; struct coll *coll; struct stream *to; - char *cmd, *path, *line; - size_t size; ssize_t nbytes; + size_t size; + char *cmd, *path, *line; int error, first; coll = fup->coll; @@ -1558,7 +1445,7 @@ updater_checkout(struct updater *up, struct file_update *fup, int isfixup) } to = stream_open_file(fup->temppath, - O_WRONLY | O_CREAT | O_TRUNC, 0600); /*XXX: Change to correct perm*/ + O_WRONLY | O_CREAT | O_TRUNC, 0600); if (to == NULL) { xasprintf(&up->errmsg, "%s: Cannot create: %s", fup->temppath, strerror(errno)); @@ -1650,15 +1537,13 @@ updater_rcsedit(struct updater *up, struct file_update *fup, char *name, struct fattr *oldfattr; char md5[MD5_DIGEST_SIZE]; char *branch, *cmd, *expand, *line, *path, *revnum, *tag, *temppath; - int error, changed; + int error; - rcsopt = NULL; /* XXX: just for now. */ coll = fup->coll; sr = &fup->srbuf; st = fup->st; temppath = fup->temppath; path = fup->origpath != NULL ? fup->origpath : fup->destpath; - changed = 0; error = 0; /* If the path is new, we must create the Attic dir if needed. */ @@ -1674,11 +1559,6 @@ updater_rcsedit(struct updater *up, struct file_update *fup, char *name, * XXX: we could avoid parsing overhead if we're reading ahead before we * parse the file. */ - rf = rcsfile_frompath(path, name, coll->co_cvsroot, coll->co_tag); - if (rf == NULL) { - xasprintf(&up->errmsg, "Error reading rcsfile %s\n", name); - return (UPDATER_ERR_MSG); - } oldfattr = fattr_frompath(path, FATTR_NOFOLLOW); if (oldfattr == NULL) { xasprintf(&up->errmsg, "%s: Cannot get attributes: %s", path, @@ -1686,83 +1566,91 @@ updater_rcsedit(struct updater *up, struct file_update *fup, char *name, return (UPDATER_ERR_MSG); } fattr_merge(sr->sr_serverattr, oldfattr); + rf = NULL; + + /* Macro for making touching an RCS file faster. */ +#define UPDATER_OPENRCS(rf, up, path, name, cvsroot, tag) do { \ + if ((rf) == NULL) { \ + (rf) = rcsfile_frompath((path), (name), (cvsroot), \ + (tag)); \ + if ((rf) == NULL) { \ + xasprintf(&(up)->errmsg, \ + "Error reading rcsfile %s\n", (name)); \ + return (UPDATER_ERR_MSG); \ + } \ + } \ +} while (0) while ((line = stream_getln(up->rd, NULL)) != NULL) { if (strcmp(line, ".") == 0) break; cmd = proto_get_ascii(&line); if (cmd == NULL) { - fprintf(stderr, "Error when adding delta\n"); + lprintf(-1, "Error editing %s\n", name); return (UPDATER_ERR_PROTO); } switch(cmd[0]) { case 'B': branch = proto_get_ascii(&line); - if (branch == NULL || line != NULL) { - fprintf(stderr, "problems with branch\n"); + if (branch == NULL || line != NULL) return (UPDATER_ERR_PROTO); - } - rcsfile_setval(rf, RCSFILE_BRANCH, branch); - changed = 1; + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); break; case 'b': + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); rcsfile_setval(rf, RCSFILE_BRANCH, NULL); - changed = 1; break; case 'D': + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); error = updater_addelta(rf, up->rd, line); - changed = 1; if (error) return (error); break; case 'd': revnum = proto_get_ascii(&line); - if (revnum == NULL || line != NULL) { - fprintf(stderr, "Problems with delta\n"); + if (revnum == NULL || line != NULL) return (UPDATER_ERR_PROTO); - } + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); rcsfile_deleterev(rf, revnum); - changed = 1; break; case 'E': expand = proto_get_ascii(&line); - if (expand == NULL || line != NULL) { - fprintf(stderr, "Expand\n"); + if (expand == NULL || line != NULL) return (UPDATER_ERR_PROTO); - } + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); rcsfile_setval(rf, RCSFILE_EXPAND, expand); - changed = 1; break; case 'T': tag = proto_get_ascii(&line); revnum = proto_get_ascii(&line); if (tag == NULL || revnum == NULL || - line != NULL) { - fprintf(stderr, "Add tag\n"); + line != NULL) return (UPDATER_ERR_PROTO); - } + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); rcsfile_addtag(rf, tag, revnum); - changed = 1; break; case 't': tag = proto_get_ascii(&line); revnum = proto_get_ascii(&line); if (tag == NULL || revnum == NULL || - line != NULL) { - fprintf(stderr, "Delete tag\n"); + line != NULL) return (UPDATER_ERR_PROTO); - } + UPDATER_OPENRCS(rf, up, path, name, + coll->co_cvsroot, coll->co_tag); rcsfile_deletetag(rf, tag, revnum); - changed = 1; break; default: - fprintf(stderr, "Unknown %s\n", line); return (UPDATER_ERR_PROTO); - break; } } - if (!changed) { + if (rf == NULL) { fattr_maskout(oldfattr, ~FA_MODTIME); if (fattr_equal(oldfattr, sr->sr_serverattr) == 0) lprintf(1, " SetAttrs %s", fup->coname); @@ -1803,7 +1691,7 @@ updater_rcsedit(struct updater *up, struct file_update *fup, char *name, } fattr_override(sr->sr_clientattr, sr->sr_serverattr, FA_MODTIME | FA_MASK); - if (changed) { + if (rf != NULL) { error = updater_updatefile(up, fup, md5, 0); fup->wantmd5 = NULL; /* So that it doesn't get freed. */ if (error) @@ -1825,13 +1713,8 @@ updater_rcsedit(struct updater *up, struct file_update *fup, char *name, * this is a problem, since if a file is moved, it should be edited to * show if it's dead or not. */ - if (fup->origpath != NULL) { - /* - * XXX: Should we track delete count or is this a "silent" - * delete? - */ + if (fup->origpath != NULL) updater_deletefile(fup->origpath); - } return (0); } @@ -1842,13 +1725,13 @@ int updater_addelta(struct rcsfile *rf, struct stream *rd, char *cmdline) { struct delta *d; - char *author, *cmd, *diffbase, *line, *logline, *revdate, *revnum, *state, - *textline; size_t size; int stop; + char *author, *cmd, *diffbase, *line, *logline; + char *revdate, *revnum, *state, *textline; revnum = proto_get_ascii(&cmdline); - diffbase = proto_get_ascii(&cmdline); /* XXX: diffBase. */ + diffbase = proto_get_ascii(&cmdline); revdate = proto_get_ascii(&cmdline); author = proto_get_ascii(&cmdline); size = 0; @@ -1889,7 +1772,7 @@ updater_addelta(struct rcsfile *rf, struct stream *rd, char *cmdline) break; case 'N': case 'n': - /* XXX: Not implemented. */ + /* XXX: Not supported. */ break; case 'S': state = proto_get_ascii(&line); @@ -1932,11 +1815,11 @@ updater_append_file(struct updater *up, struct file_update *fup, off_t pos) struct fattr *fa; struct stream *to; struct statusrec *sr; - char buf[BUFSIZE], *line, *cmd; - char md5[MD5_DIGEST_SIZE]; - int error, fd; - off_t bytes; ssize_t nread; + off_t bytes; + char buf[BUFSIZE], md5[MD5_DIGEST_SIZE]; + char *line, *cmd; + int error, fd; sr = &fup->srbuf; fa = sr->sr_serverattr; @@ -1963,7 +1846,8 @@ updater_append_file(struct updater *up, struct file_update *fup, off_t pos) bytes = fattr_filesize(fa) - pos; /* Append the new data. */ do { - nread = stream_read(up->rd, buf, (BUFSIZE > bytes) ? bytes : BUFSIZE); + nread = stream_read(up->rd, buf, + (BUFSIZE > bytes) ? bytes : BUFSIZE); bytes -= nread; stream_write(to, buf, nread); } while (bytes > 0); @@ -1984,7 +1868,6 @@ updater_append_file(struct updater *up, struct file_update *fup, off_t pos) if (fup->wantmd5 == NULL || line != NULL || strcmp(cmd, "5") != 0) return (UPDATER_ERR_PROTO); - /* UPDATE FILE. */ sr->sr_clientattr = fattr_frompath(fup->destpath, FATTR_NOFOLLOW); if (sr->sr_clientattr == NULL) return (UPDATER_ERR_PROTO); @@ -1992,7 +1875,6 @@ updater_append_file(struct updater *up, struct file_update *fup, off_t pos) FA_MODTIME | FA_MASK); error = updater_updatefile(up, fup, md5, 0); fup->wantmd5 = NULL; /* So that it doesn't get freed. */ - /* UPDATE IT. */ if (error) return (error); return (0); @@ -2005,9 +1887,9 @@ updater_append_file(struct updater *up, struct file_update *fup, off_t pos) static int updater_read_checkout(struct stream *src, struct stream *dest) { - char *line; - size_t size; ssize_t nbytes; + size_t size; + char *line; int first; first = 1; @@ -2050,10 +1932,10 @@ updater_rsync(struct updater *up, struct file_update *fup, size_t blocksize) struct statusrec *sr; struct stream *to; char md5[MD5_DIGEST_SIZE]; + ssize_t nbytes; + size_t blocknum, blockstart, blockcount; char *buf, *line; int error, orig; - size_t blocknum, blockstart, blockcount; - ssize_t nbytes; sr = &fup->srbuf;