From owner-cvs-all Sat Aug 11 12:45:37 2001 Delivered-To: cvs-all@freebsd.org Received: from earth.backplane.com (earth-nat-cw.backplane.com [208.161.114.67]) by hub.freebsd.org (Postfix) with ESMTP id 3EC0837B407; Sat, 11 Aug 2001 12:45:22 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.11.4/8.11.2) id f7BJjIo19532; Sat, 11 Aug 2001 12:45:18 -0700 (PDT) (envelope-from dillon) Date: Sat, 11 Aug 2001 12:45:18 -0700 (PDT) From: Matt Dillon Message-Id: <200108111945.f7BJjIo19532@earth.backplane.com> To: Josef Karthauser Cc: Eivind Eklund , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: CVS patch implements update -T (was Re: Remote CVS/Template) References: <3B4F1FCD.7F2D4842@FreeBSD.org> <20010713120140Q.jkh@osd.bsdi.com> <20010713211017.A57434@heechee.tobez.org> <20010713123241X.jkh@osd.bsdi.com> <200107132214.f6DMET571067@earth.backplane.com> <20010715143503.A10888@FreeBSD.org> <20010810133132.G624@tao.org.uk> Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Ok, here is a patch. I think this is fairly reasonable. It handles the case where the developer normally operates from a local CVS tree (e.g. for cvs update), and may or may not use an override when comitting. cvs update -T typical use: Add 'T' option to your ~/.cvsrc file for the update command. This option will create/update CVS/Template by copying (CVSROOT)/rcstemplate to CVS/Template if the mtimes do not match or CVS/Template is found not to exist. It will call setutimes() to force the mtimes to match after the copy succeeds for more optimal operation. (I haven't included the manual page update to this patch set yet). -Matt Index: cvs.h =================================================================== RCS file: /home/ncvs/src/contrib/cvs/src/cvs.h,v retrieving revision 1.11.2.1 diff -u -r1.11.2.1 cvs.h --- cvs.h 2000/10/31 09:37:52 1.11.2.1 +++ cvs.h 2001/08/11 19:20:46 @@ -530,6 +530,7 @@ void ParseTag PROTO((char **tagp, char **datep, int *nonbranchp)); void WriteTag PROTO ((char *dir, char *tag, char *date, int nonbranch, char *update_dir, char *repository)); +void WriteTemplate PROTO ((char *dir, char *repository)); void cat_module PROTO((int status)); void check_entries PROTO((char *dir)); void close_module PROTO((DBM * db)); Index: entries.c =================================================================== RCS file: /home/ncvs/src/contrib/cvs/src/entries.c,v retrieving revision 1.1.1.5.2.1 diff -u -r1.1.1.5.2.1 entries.c --- entries.c 2000/10/31 09:37:52 1.1.1.5.2.1 +++ entries.c 2001/08/11 19:37:56 @@ -632,6 +632,58 @@ } /* + * Write out/Clear the CVS/Template file. + */ +void +WriteTemplate (dir, update_dir) + char *dir; + char *update_dir; +{ + char *tmp = NULL; + char *root = NULL; + char *root_template = NULL; + struct stat st1; + struct stat st2; + + root = Name_Root(dir, update_dir); + asprintf(&tmp, "%s/%s", dir, CVSADM_TEMPLATE); + asprintf(&root_template, "%s/CVSROOT/rcstemplate", root); + + if (stat(root_template, &st1) == 0) { + if (stat(tmp, &st2) < 0 || st1.st_mtime != st2.st_mtime) { + FILE *fi; + FILE *fo; + + if ((fi = open_file(root_template, "r")) != NULL) { + if ((fo = open_file(tmp, "w")) != NULL) { + int n; + char buf[256]; + + while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) + fwrite(buf, 1, n, fo); + fflush(fo); + if (ferror(fi) || ferror(fo)) { + fclose(fo); + remove(tmp); + } else { + struct timeval times[2]; + fclose(fo); + times[0].tv_sec = st1.st_mtime; + times[0].tv_usec = 0; + times[1] = times[0]; + utimes(tmp, times); + } + } + fclose(fi); + } + } + } + free(tmp); + free(root); + free(root_template); +} + +/* * Write out/Clear the CVS/Tag file. */ void Index: update.c =================================================================== RCS file: /home/ncvs/src/contrib/cvs/src/update.c,v retrieving revision 1.6.2.1 diff -u -r1.6.2.1 update.c --- update.c 2000/10/31 09:37:58 1.6.2.1 +++ update.c 2001/08/11 19:26:12 @@ -100,6 +100,7 @@ static int force_tag_match = 1; static int update_build_dirs = 0; static int update_prune_dirs = 0; +static int pull_template = 0; static int pipeout = 0; #ifdef SERVER_SUPPORT static int patches = 0; @@ -125,6 +126,7 @@ "\t-j rev\tMerge in changes made between current revision and rev.\n", "\t-I ign\tMore files to ignore (! to reset).\n", "\t-W spec\tWrappers specification line.\n", + "\t-T\tCreate CVS/Template.\n", "(Specify the --help global option for a list of other help options)\n", NULL }; @@ -149,7 +151,7 @@ /* parse the args */ optind = 0; - while ((c = getopt (argc, argv, "+ApCPflRQqduk:r:D:j:I:W:")) != -1) + while ((c = getopt (argc, argv, "+ApCPflRQTqduk:r:D:j:I:W:")) != -1) { switch (c) { @@ -187,6 +189,9 @@ "-q or -Q must be specified before \"%s\"", command_name); break; + case 'T': + pull_template = 1; + break; case 'd': update_build_dirs = 1; break; @@ -1029,6 +1034,12 @@ WriteTag (dir, tag, date, 0, update_dir, repository); rewrite_tag = 1; nonbranch = 0; + } + + /* keep the CVS/Template file current */ + if (pull_template) + { + WriteTemplate (dir, update_dir); } /* initialize the ignore list for this directory */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message