diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/add.c | 34 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.h | 4 | ||||
-rw-r--r-- | usr.bin/cvs/entries.c | 110 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 14 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 5 |
5 files changed, 153 insertions, 14 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c index 09722ca22eb..1197d5f1922 100644 --- a/usr.bin/cvs/add.c +++ b/usr.bin/cvs/add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: add.c,v 1.55 2006/06/07 07:01:12 xsa Exp $ */ +/* $OpenBSD: add.c,v 1.56 2006/06/14 15:14:47 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> @@ -106,10 +106,10 @@ cvs_add_local(struct cvs_file *cf) static void add_directory(struct cvs_file *cf) { - int l, added; + int l, added, nb; struct stat st; CVSENTRIES *entlist; - char *entry, *repo; + char *date, *entry, msg[1024], *repo, *tag; cvs_log(LP_TRACE, "add_directory(%s)", cf->file_path); @@ -125,6 +125,9 @@ add_directory(struct cvs_file *cf) cf->file_path); added = 0; } else { + /* Let's see if we have any per-directory tags first. */ + cvs_parse_tagfile(cf->file_wd, &tag, &date, &nb); + l = snprintf(entry, MAXPATHLEN, "%s/%s", cf->file_path, CVS_PATH_CVSDIR); if (l == -1 || l >= MAXPATHLEN) @@ -153,7 +156,7 @@ add_directory(struct cvs_file *cf) cf->file_path); cvs_mkadmin(cf->file_path, current_cvsroot->cr_dir, - entry); + entry, tag, date, nb); xfree(repo); xfree(entry); @@ -168,8 +171,27 @@ add_directory(struct cvs_file *cf) } if (added == 1) { - cvs_printf("Directory %s added to the repository\n", - cf->file_rpath); + snprintf(msg, sizeof(msg), + "Directory %s added to the repository", cf->file_rpath); + + if (tag != NULL) { + (void)strlcat(msg, + "\n--> Using per-directory sticky tag ", + sizeof(msg)); + (void)strlcat(msg, tag, sizeof(msg)); + } + if (date != NULL) { + (void)strlcat(msg, + "\n--> Using per-directory sticky date ", + sizeof(msg)); + (void)strlcat(msg, date, sizeof(msg)); + } + cvs_printf("%s\n", msg); + + if (tag != NULL) + xfree(tag); + if (date != NULL) + xfree(date); } cf->file_status = FILE_SKIP; diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index 5c143b24b37..a7f00dce3f6 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.112 2006/06/12 13:56:00 xsa Exp $ */ +/* $OpenBSD: cvs.h,v 1.113 2006/06/14 15:14:47 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -340,6 +340,8 @@ void cvs_ent_remove(CVSENTRIES *, const char *); void cvs_ent_close(CVSENTRIES *, int); void cvs_ent_free(struct cvs_ent *); int cvs_ent_exists(CVSENTRIES *, const char *); +void cvs_parse_tagfile(char *, char **, char **, int *); +void cvs_write_tagfile(char *, char *, char *, int); /* root.c */ struct cvsroot *cvsroot_parse(const char *); diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c index 7a98988be12..8f35bfdb51f 100644 --- a/usr.bin/cvs/entries.c +++ b/usr.bin/cvs/entries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: entries.c,v 1.58 2006/06/06 05:13:39 joris Exp $ */ +/* $OpenBSD: entries.c,v 1.59 2006/06/14 15:14:47 xsa Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -331,3 +331,111 @@ ent_get_line(CVSENTRIES *ep, const char *name) return (NULL); } + +void +cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp) +{ + FILE *fp; + int linenum; + size_t len; + char linebuf[128], *tagpath; + + if (tagp != NULL) + *tagp = (char *)NULL; + + if (datep != NULL) + *datep = (char *)NULL; + + if (nbp != NULL) + *nbp = 0; + + tagpath = xmalloc(MAXPATHLEN); + + if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) + goto out; + + if ((fp = fopen(tagpath, "r")) == NULL) { + if (errno != ENOENT) + cvs_log(LP_NOTICE, "failed to open `%s' : %s", tagpath, + strerror(errno)); + goto out; + } + + linenum = 0; + + while (fgets(linebuf, (int)sizeof(linebuf), fp) != NULL) { + linenum++; + if ((len = strlen(linebuf)) == 0) + continue; + if (linebuf[len - 1] != '\n') { + cvs_log(LP_NOTICE, "line too long in `%s:%d'", + tagpath, linenum); + break; + } + linebuf[--len] = '\0'; + + switch (*linebuf) { + case 'T': + if (tagp != NULL) + *tagp = xstrdup(linebuf + 1); + break; + case 'D': + if (datep != NULL) + *datep = xstrdup(linebuf + 1); + break; + case 'N': + if (tagp != NULL) + *tagp = xstrdup(linebuf + 1); + if (nbp != NULL) + *nbp = 1; + break; + default: + break; + } + } + if (ferror(fp)) + cvs_log(LP_NOTICE, "failed to read line from `%s'", tagpath); + + (void)fclose(fp); +out: + xfree(tagpath); +} + +void +cvs_write_tagfile(char *dir, char *tag, char *date, int nb) +{ + FILE *fp; + char *tagpath; + + if (cvs_noexec == 1) + return; + + tagpath = xmalloc(MAXPATHLEN); + + if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN) + goto out; + + if ((tag != NULL) || (date != NULL)) { + if ((fp = fopen(tagpath, "w+")) == NULL) { + if (errno != ENOENT) { + cvs_log(LP_NOTICE, "failed to open `%s' : %s", + tagpath, strerror(errno)); + } + goto out; + } + if (tag != NULL) { + if (nb != 0) + (void)fprintf(fp, "N%s\n", tag); + else + (void)fprintf(fp, "T%s\n", tag); + } else + (void)fprintf(fp, "D%s\n", date); + + (void)fclose(fp); + } else { + (void)cvs_unlink(tagpath); + goto out; + } +out: + xfree(tagpath); +} diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 4269f34fdf9..35b42703aa6 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.86 2006/06/07 22:20:59 reyk Exp $ */ +/* $OpenBSD: util.c,v 1.87 2006/06/14 15:14:47 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -620,14 +620,17 @@ cvs_get_repository_name(const char *dir, char *dst, size_t len) } void -cvs_mkadmin(const char *path, const char *root, const char *repo) +cvs_mkadmin(const char *path, const char *root, const char *repo, + char *tag, char *date, int nb) { FILE *fp; size_t len; struct stat st; char buf[MAXPATHLEN]; - cvs_log(LP_TRACE, "cvs_mkadmin(%s, %s, %s)", path, root, repo); + cvs_log(LP_TRACE, "cvs_mkadmin(%s, %s, %s, %s, %s, %d)", + path, root, repo, (tag != NULL) ? tag : "", + (date != NULL) ? date : "", nb); len = cvs_path_cat(path, CVS_PATH_CVSDIR, buf, sizeof(buf)); if (len >= sizeof(buf)) @@ -666,6 +669,8 @@ cvs_mkadmin(const char *path, const char *root, const char *repo) if ((fp = fopen(buf, "w")) == NULL) fatal("cvs_mkadmin: %s: %s", buf, strerror(errno)); (void)fclose(fp); + + cvs_write_tagfile(path, tag, date, nb); } void @@ -720,7 +725,8 @@ cvs_mkpath(const char *path) if (mkdir(rpath, 0755) == -1 && errno != EEXIST) fatal("cvs_mkpath: %s: %s", rpath, strerror(errno)); - cvs_mkadmin(rpath, current_cvsroot->cr_dir, repo); + cvs_mkadmin(rpath, current_cvsroot->cr_dir, repo, + NULL, NULL, 0); } xfree(dir); diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index d4485452722..4f2eb52e624 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.9 2006/05/28 21:38:30 joris Exp $ */ +/* $OpenBSD: util.h,v 1.10 2006/06/14 15:14:47 xsa Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -32,7 +32,8 @@ void cvs_get_repository_name(const char *, char *, size_t); void cvs_modetostr(mode_t, char *, size_t); void cvs_strtomode(const char *, mode_t *); void cvs_splitpath(const char *, char *, size_t, char **); -void cvs_mkadmin(const char *, const char *, const char *); +void cvs_mkadmin(const char *, const char *, const char *, + char *, char *, int); void cvs_mkpath(const char *); int cvs_cksum(const char *, char *, size_t); int cvs_exec(int, char **, int []); |