From 1c00d757d321d2eeabe0a851638553057f95ac7f Mon Sep 17 00:00:00 2001 From: Jean-Francois Brousseau Date: Wed, 6 Apr 2005 19:12:09 +0000 Subject: * allow for creation and removal of RCS locks * add rcs_tag_resolve() to resolve a branch, tag or revision easily --- usr.bin/cvs/rcs.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) (limited to 'usr.bin/cvs/rcs.c') diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 84c49df9122..ea460332c1c 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.39 2005/04/06 18:51:29 joris Exp $ */ +/* $OpenBSD: rcs.c,v 1.40 2005/04/06 19:12:08 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -686,6 +686,78 @@ rcs_lock_setmode(RCSFILE *file, int mode) return (pmode); } +/* + * rcs_lock_add() + * + * Add an RCS lock for the user on revision . + * Returns 0 on success, or -1 on failure. + */ +int +rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev) +{ + struct rcs_lock *lkp; + + /* first look for duplication */ + TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list) { + if (strcmp(lkp->rl_name, user) == 0) { + rcs_errno = RCS_ERR_DUPENT; + return (-1); + } + } + + lkp = (struct rcs_lock *)malloc(sizeof(*lkp)); + if (lkp == NULL) { + cvs_log(LP_ERRNO, "failed to allocate RCS lock"); + return (-1); + } + + lkp->rl_name = cvs_strdup(user); + if (lkp->rl_name == NULL) { + cvs_log(LP_ERRNO, "failed to duplicate user name"); + free(lkp); + return (-1); + } + + TAILQ_INSERT_TAIL(&(file->rf_locks), lkp, rl_list); + + /* not synced anymore */ + file->rf_flags &= ~RCS_SYNCED; + return (0); + + +} + + +/* + * rcs_lock_remove() + * + * Remove the RCS lock on revision . + * Returns 0 on success, or -1 on failure. + */ +int +rcs_lock_remove(RCSFILE *file, const RCSNUM *rev) +{ + struct rcs_lock *lkp; + + TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list) + if (rcsnum_cmp(lkp->rl_num, rev, 0) == 0) + break; + + if (lkp == NULL) { + rcs_errno = RCS_ERR_NOENT; + return (-1); + } + + TAILQ_REMOVE(&(file->rf_locks), lkp, rl_list); + rcsnum_free(lkp->rl_num); + cvs_strfree(lkp->rl_name); + free(lkp); + + /* not synced anymore */ + file->rf_flags &= ~RCS_SYNCED; + return (0); +} + /* * rcs_desc_get() * @@ -752,6 +824,25 @@ rcs_comment_set(RCSFILE *file, const char *comment) return (0); } +/* + * rcs_tag_resolve() + * + * Retrieve the revision number corresponding to the tag for the RCS + * file . + */ +RCSNUM* +rcs_tag_resolve(RCSFILE *file, const char *tag) +{ + RCSNUM *num; + + if ((num = rcsnum_parse(tag)) == NULL) { + num = rcs_sym_getrev(file, tag); + } + + return (num); +} + + /* * rcs_patch() * -- cgit v1.2.3