1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

A few bugfixes:

- Instead of including protocol info in diffs, strip them before adding
  deltatext and take this into account when applying the diff later.
- Don't use strlen when the string in the RCS file may contain garbage. This got
  caught in the checksumming before, but was not fixed until now. Instead of
  using strlen, pass the token length when adding log and text entries to a
  delta. Add an extra length parameter to duptext() to record the token length.
- When adding new branches to a file, add them in at the tail instead of the
  head of the list to get correct ordering when writing out.
- Input stream when diffing was opened twice.
- Don't expand keywords in diffs between deltas.
This commit is contained in:
Ulf Lilleengen 2008-12-03 22:47:33 +00:00
parent bc1d339146
commit 9178dc306f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/csup_cvsmode/; revision=185592
5 changed files with 49 additions and 47 deletions

View File

@ -140,10 +140,10 @@ diff_apply(struct stream *rd, struct stream *orig, struct stream *dest,
}
line = stream_getln(rd, NULL);
}
if (line == NULL)
if (comode && line == NULL)
return (-1);
/* If we got ".+", there's no ending newline. */
if (strcmp(line, ".+") == 0 && !empty)
if (comode && strcmp(line, ".+") == 0 && !empty)
noeol = 1;
ec.where = 0;
while ((line = stream_getln(orig, &size)) != NULL)

View File

@ -204,7 +204,7 @@ rcsfile_frompath(char *path, char *name, char *cvsroot, char *colltag)
rf->branch = NULL;
rf->strictlock = 0;
rf->comment = NULL;
rf->expand = -1;
rf->expand = EXPAND_DEFAULT;
rf->desc = NULL;
infp = fopen(path, "r");
@ -263,7 +263,7 @@ rcsfile_send_details(struct rcsfile *rf, struct stream *wr)
if (error)
return(error);
/* Write expand. */
if (rf->expand >= 0) {
if (rf->expand != EXPAND_DEFAULT) {
error = proto_printf(wr, "E %s\n",
keyword_encode_expand(rf->expand));
if (error)
@ -561,7 +561,6 @@ rcsfile_puttext(struct rcsfile *rf, struct stream *dest, struct delta *d,
error = -1;
goto cleanup;
}
rd = stream_open_buf(diffbase->text);
di->di_rcsfile = rf->name;
di->di_cvsroot = rf->cvsroot;
di->di_revnum = d->revnum;
@ -569,9 +568,9 @@ rcsfile_puttext(struct rcsfile *rf, struct stream *dest, struct delta *d,
di->di_author = d->author;
di->di_tag = rf->colltag;
di->di_state = d->state;
di->di_expand = rf->expand;
di->di_expand = EXPAND_OLD;
k = keyword_new();
rd = stream_open_buf(diffbase->text);
error = diff_reverse(rd, orig, dest, k, di);
if (error) {
@ -634,7 +633,7 @@ rcsfile_getdeltatext(struct rcsfile *rf, struct delta *d, struct buf **buf_dest)
di->di_author = d->author;
di->di_tag = rf->colltag;
di->di_state = d->state;
di->di_expand = rf->expand;
di->di_expand = EXPAND_OLD;
rd = stream_open_buf(d->text);
k = keyword_new();
error = diff_apply(rd, orig, dest, k, di, 0);
@ -1010,7 +1009,7 @@ rcsfile_addelta(struct rcsfile *rf, char *revnum, char *revdate, char *author,
b = xmalloc(sizeof(struct branch));
b->revnum = brev;
LIST_INIT(&b->deltalist);
STAILQ_INSERT_HEAD(&d_bp->branchlist, b, branch_next);
STAILQ_INSERT_TAIL(&d_bp->branchlist, b, branch_next);
}
/* Insert both into the tree, and into the lookup list. */
@ -1222,32 +1221,35 @@ rcsfile_insertdelta(struct branch *b, struct delta *d, int trunk)
/* Add logtext to a delta. Assume the delta already exists. */
int
rcsdelta_addlog(struct delta *d, char *log)
rcsdelta_addlog(struct delta *d, char *log, int len)
{
struct stream *dest;
assert(d != NULL);
/* Strip away '@' at beginning and end. */
log++;
log[strlen(log) - 1] = '\0';
len--;
log[len - 1] = '\0';
dest = stream_open_buf(d->log);
stream_write(dest, log, strlen(log));
stream_write(dest, log, len - 1);
stream_close(dest);
return (0);
}
/* Add deltatext to a delta. Assume the delta already exists. */
int
rcsdelta_addtext(struct delta *d, char *text)
rcsdelta_addtext(struct delta *d, char *text, int len)
{
struct stream *dest;
assert(d != NULL);
/* Strip away '@' at beginning and end. */
text++;
text[strlen(text) - 1] = '\0';
len--;
text[len - 1] = '\0';
dest = stream_open_buf(d->text);
stream_write(dest, text, strlen(text));
stream_write(dest, text, len - 1);
stream_close(dest);
return (0);
}

View File

@ -63,8 +63,8 @@ struct delta *rcsfile_addelta(struct rcsfile *, char *, char *, char *,
void rcsfile_importdelta(struct rcsfile *, char *, char *, char *,
char *, char *);
int rcsdelta_addlog(struct delta *, char *);
int rcsdelta_addtext(struct delta *, char *);
int rcsdelta_addlog(struct delta *, char *, int);
int rcsdelta_addtext(struct delta *, char *, int);
void rcsdelta_appendlog(struct delta *, char *, size_t);
void rcsdelta_appendtext(struct delta *, char *, size_t);
void rcsdelta_setstate(struct delta *, char *);

View File

@ -45,7 +45,7 @@ static void asserttoken(yyscan_t *, int);
static int parse_admin(struct rcsfile *, yyscan_t *);
static int parse_deltas(struct rcsfile *, yyscan_t *, int);
static int parse_deltatexts(struct rcsfile *, yyscan_t *, int);
static char *duptext(yyscan_t *);
static char *duptext(yyscan_t *, int *);
struct string {
char *str;
@ -63,15 +63,18 @@ asserttoken(yyscan_t *sp, int token)
}
static char *
duptext(yyscan_t *sp)
duptext(yyscan_t *sp, int *arglen)
{
char *tmp, *val;
int len;
tmp = rcsget_text(*sp);
len = rcsget_leng(*sp);
val = xmalloc(len + 2);
strlcpy(val, tmp, len + 1);
val = xmalloc(len + 1);
memcpy(val, tmp, len);
val[len] = '\0';
if (arglen != NULL)
*arglen = len;
return (val);
}
@ -92,7 +95,7 @@ rcsparse_run(struct rcsfile *rf, FILE *infp)
tok = parse_deltas(rf, &scanner, tok);
assert(tok == KEYWORD);
asserttoken(&scanner, STRING);
desc = duptext(&scanner);
desc = duptext(&scanner, NULL);
rcsfile_setval(rf, RCSFILE_DESC, desc);
free(desc);
tok = rcslex(scanner);
@ -118,7 +121,7 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
/* head {num}; */
asserttoken(sp, KEYWORD);
asserttoken(sp, NUM);
head = duptext(sp);
head = duptext(sp, NULL);
rcsfile_setval(rf, RCSFILE_HEAD, head);
free(head);
asserttoken(sp, SEMIC);
@ -127,7 +130,7 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
token = rcslex(*sp);
if (token == KEYWORD_TWO) {
asserttoken(sp, NUM);
branch = duptext(sp);
branch = duptext(sp, NULL);
rcsfile_setval(rf, RCSFILE_BRANCH, branch);
free(branch);
asserttoken(sp, SEMIC);
@ -138,7 +141,7 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
assert(token == KEYWORD);
token = rcslex(*sp);
while (token == ID) {
id = duptext(sp);
id = duptext(sp, NULL);
rcsfile_addaccess(rf, id);
free(id);
token = rcslex(*sp);
@ -149,10 +152,10 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
asserttoken(sp, KEYWORD);
token = rcslex(*sp);
while (token == ID) {
tag = duptext(sp);
tag = duptext(sp, NULL);
asserttoken(sp, COLON);
asserttoken(sp, NUM);
revnum = duptext(sp);
revnum = duptext(sp, NULL);
rcsfile_importtag(rf, tag, revnum);
free(tag);
free(revnum);
@ -182,7 +185,7 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
} else if (!strcmp(tmp, "comment")) {
token = rcslex(*sp);
if (token == STRING) {
comment = duptext(sp);
comment = duptext(sp, NULL);
rcsfile_setval(rf, RCSFILE_COMMENT, comment);
free(comment);
}
@ -191,7 +194,7 @@ parse_admin(struct rcsfile *rf, yyscan_t *sp)
} else if (!strcmp(tmp, "expand")) {
token = rcslex(*sp);
if (token == STRING) {
expand = duptext(sp);
expand = duptext(sp, NULL);
rcsfile_setval(rf, RCSFILE_EXPAND, expand);
free(expand);
}
@ -231,22 +234,22 @@ parse_deltas(struct rcsfile *rf, yyscan_t *sp, int token)
/* num */
assert(token == NUM);
revnum = duptext(sp);
revnum = duptext(sp, NULL);
/* date num; */
asserttoken(sp, KEYWORD);
asserttoken(sp, NUM);
revdate = duptext(sp);
revdate = duptext(sp, NULL);
asserttoken(sp, SEMIC);
/* author id; */
asserttoken(sp, KEYWORD);
asserttoken(sp, ID);
author = duptext(sp);
author = duptext(sp, NULL);
asserttoken(sp, SEMIC);
/* state {id}; */
asserttoken(sp, KEYWORD);
token = rcslex(*sp);
if (token == ID) {
state = duptext(sp);
state = duptext(sp, NULL);
token = rcslex(*sp);
}
assert(token == SEMIC);
@ -261,7 +264,7 @@ parse_deltas(struct rcsfile *rf, yyscan_t *sp, int token)
asserttoken(sp, KEYWORD);
token = rcslex(*sp);
if (token == NUM) {
next = duptext(sp);
next = duptext(sp, NULL);
token = rcslex(*sp);
}
assert(token == SEMIC);
@ -298,7 +301,7 @@ parse_deltatexts(struct rcsfile *rf, yyscan_t *sp, int token)
{
struct delta *d;
char *log, *revnum, *text;
int error;
int error, len;
error = 0;
/* In case we don't have deltatexts. */
@ -307,7 +310,7 @@ parse_deltatexts(struct rcsfile *rf, yyscan_t *sp, int token)
do {
/* num */
assert(token == NUM);
revnum = duptext(sp);
revnum = duptext(sp, NULL);
/* Get delta we're adding text to. */
d = rcsfile_getdelta(rf, revnum);
free(revnum);
@ -315,8 +318,8 @@ parse_deltatexts(struct rcsfile *rf, yyscan_t *sp, int token)
/* log string */
asserttoken(sp, KEYWORD);
asserttoken(sp, STRING);
log = duptext(sp);
error = rcsdelta_addlog(d, log);
log = duptext(sp, &len);
error = rcsdelta_addlog(d, log, len);
free(log);
if (error)
return (-1);
@ -335,8 +338,8 @@ parse_deltatexts(struct rcsfile *rf, yyscan_t *sp, int token)
/* text string */
assert(token == KEYWORD);
asserttoken(sp, STRING);
text = duptext(sp);
error = rcsdelta_addtext(d, text);
text = duptext(sp, &len);
error = rcsdelta_addtext(d, text, len);
/*
* If this happens, something is wrong with the RCS file, and it
* should be resent.

View File

@ -1724,7 +1724,6 @@ updater_addelta(struct rcsfile *rf, struct stream *rd, char *cmdline)
{
struct delta *d;
size_t size;
int stop;
char *author, *cmd, *diffbase, *line, *logline;
char *revdate, *revnum, *state, *textline;
@ -1780,15 +1779,15 @@ updater_addelta(struct rcsfile *rf, struct stream *rd, char *cmdline)
break;
case 'T':
/* Do the same as in 'C' command. */
stop = 0;
textline = stream_getln(rd, &size);
while (textline != NULL) {
if (size == 2 && *textline == '.')
stop = 1;
break;
if (size == 3 &&
memcmp(textline, ".+", 2) == 0) {
/* Truncate newline. */
stop = 1;
rcsdelta_truncatetext(d, -1);
break;
}
if (size >= 3 &&
memcmp(textline, "..", 2) == 0) {
@ -1796,8 +1795,6 @@ updater_addelta(struct rcsfile *rf, struct stream *rd, char *cmdline)
textline++;
}
rcsdelta_appendtext(d, textline, size);
if (stop)
break;
textline = stream_getln(rd, &size);
}
break;