diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-03-13 22:07:50 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-03-13 22:07:50 +0000 |
commit | d94ef2b74c348f009c17d631e2517b50c19d51c2 (patch) | |
tree | 1b4e9f195de43d5a67c58452f9a9ecdca85ab937 /usr.bin | |
parent | 5a95a46e64448648fbbd7489b46fe30548eaca3f (diff) |
support for the optional `branch' keyword, which is used to set the
default branch for an RCS file
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/rcs.c | 59 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.h | 44 |
2 files changed, 73 insertions, 30 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 900a09f9a6d..6eb82bf888e 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.34 2005/03/13 21:47:04 jfb Exp $ */ +/* $OpenBSD: rcs.c,v 1.35 2005/03/13 22:07:49 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -247,14 +247,8 @@ rcs_open(const char *path, int flags, ...) } memset(rfp, 0, sizeof(*rfp)); - if ((rfp->rf_branch = rcsnum_alloc()) == NULL) { - free(rfp); - return (NULL); - } - if ((rfp->rf_path = strdup(path)) == NULL) { cvs_log(LP_ERRNO, "failed to duplicate RCS file path"); - rcsnum_free(rfp->rf_branch); free(rfp); return (NULL); } @@ -366,6 +360,12 @@ rcs_write(RCSFILE *rfp) numbuf[0] = '\0'; fprintf(fp, "head\t%s;\n", numbuf); + + if (rfp->rf_branch != NULL) { + rcsnum_tostr(rfp->rf_branch, numbuf, sizeof(numbuf)); + fprintf(fp, "branch\t%s;\n", numbuf); + } + fputs("access", fp); TAILQ_FOREACH(ap, &(rfp->rf_access), ra_list) { fprintf(fp, "\n\t%s", ap->ra_name); @@ -436,6 +436,41 @@ rcs_write(RCSFILE *rfp) } /* + * rcs_branch_get() + * + * Retrieve the default branch number for the RCS file <file>. + * Returns the number on success. If NULL is returned, then there is no + * default branch for this file. + */ +const RCSNUM* +rcs_branch_get(RCSFILE *file) +{ + return (file->rf_branch); +} + +/* + * rcs_branch_set() + * + * Set the default branch for the RCS file <file> to <bnum>. + * Returns 0 on success, -1 on failure. + */ +int +rcs_branch_set(RCSFILE *file, const RCSNUM *bnum) +{ + if ((file->rf_branch == NULL) && + ((file->rf_branch = rcsnum_alloc()) == NULL)) + return (-1); + + if (rcsnum_cpy(bnum, file->rf_branch, 0) < 0) { + rcsnum_free(file->rf_branch); + file->rf_branch = NULL; + return (-1); + } + + return (0); +} + +/* * rcs_access_add() * * Add the login name <login> to the access list for the RCS file <file>. @@ -1279,8 +1314,14 @@ rcs_parse_admin(RCSFILE *rfp) rcsnum_aton(RCS_TOKSTR(rfp), NULL, rfp->rf_head); } else if (tok == RCS_TOK_BRANCH) { - rcsnum_aton(RCS_TOKSTR(rfp), NULL, - rfp->rf_branch); + if (rfp->rf_branch == NULL) { + rfp->rf_branch = rcsnum_alloc(); + if (rfp->rf_branch == NULL) + return (-1); + } + if (rcsnum_aton(RCS_TOKSTR(rfp), NULL, + rfp->rf_branch) < 0) + return (-1); } else if (tok == RCS_TOK_COMMENT) { rfp->rf_comment = strdup(RCS_TOKSTR(rfp)); if (rfp->rf_comment == NULL) { diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h index 6c623a8e719..e4fa8caf83c 100644 --- a/usr.bin/cvs/rcs.h +++ b/usr.bin/cvs/rcs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.h,v 1.15 2005/03/05 18:25:30 jfb Exp $ */ +/* $OpenBSD: rcs.h,v 1.16 2005/03/13 22:07:49 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -169,26 +169,28 @@ typedef struct rcs_file { extern int rcs_errno; -RCSFILE* rcs_open (const char *, int, ...); -void rcs_close (RCSFILE *); -int rcs_access_add (RCSFILE *, const char *); -int rcs_access_remove (RCSFILE *, const char *); -int rcs_access_check (RCSFILE *, const char *); -int rcs_sym_add (RCSFILE *, const char *, RCSNUM *); -int rcs_sym_remove (RCSFILE *, const char *); -RCSNUM* rcs_sym_getrev (RCSFILE *, const char *); -int rcs_lock_getmode (RCSFILE *); -int rcs_lock_setmode (RCSFILE *, int); -BUF* rcs_getrev (RCSFILE *, RCSNUM *); -BUF* rcs_gethead (RCSFILE *); -RCSNUM* rcs_getrevbydate (RCSFILE *, struct tm *); -const char* rcs_desc_get (RCSFILE *); -int rcs_desc_set (RCSFILE *, const char *); -const char* rcs_comment_get (RCSFILE *); -int rcs_comment_set (RCSFILE *, const char *); -int rcs_kwexp_set (RCSFILE *, int); -int rcs_kwexp_get (RCSFILE *); -const char* rcs_errstr (int); +RCSFILE* rcs_open (const char *, int, ...); +void rcs_close (RCSFILE *); +const RCSNUM* rcs_branch_get (RCSFILE *); +int rcs_branch_set (RCSFILE *, const RCSNUM *); +int rcs_access_add (RCSFILE *, const char *); +int rcs_access_remove (RCSFILE *, const char *); +int rcs_access_check (RCSFILE *, const char *); +int rcs_sym_add (RCSFILE *, const char *, RCSNUM *); +int rcs_sym_remove (RCSFILE *, const char *); +RCSNUM* rcs_sym_getrev (RCSFILE *, const char *); +int rcs_lock_getmode (RCSFILE *); +int rcs_lock_setmode (RCSFILE *, int); +BUF* rcs_getrev (RCSFILE *, RCSNUM *); +BUF* rcs_gethead (RCSFILE *); +RCSNUM* rcs_getrevbydate (RCSFILE *, struct tm *); +const char* rcs_desc_get (RCSFILE *); +int rcs_desc_set (RCSFILE *, const char *); +const char* rcs_comment_get (RCSFILE *); +int rcs_comment_set (RCSFILE *, const char *); +int rcs_kwexp_set (RCSFILE *, int); +int rcs_kwexp_get (RCSFILE *); +const char* rcs_errstr (int); int rcs_kflag_get (const char *); void rcs_kflag_usage (void); |