Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin Add a program to find the latest timestamp in a cvs ...



details:   https://anonhg.NetBSD.org/src/rev/40e85d846bef
branches:  trunk
changeset: 343191:40e85d846bef
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 24 17:08:16 2016 +0000

description:
Add a program to find the latest timestamp in a cvs repository

diffstat:

 usr.bin/Makefile              |    4 +-
 usr.bin/cvslatest/Makefile    |    6 +
 usr.bin/cvslatest/cvslatest.1 |   76 ++++++++++++++++
 usr.bin/cvslatest/cvslatest.c |  195 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 279 insertions(+), 2 deletions(-)

diffs (truncated from 307 to 300 lines):

diff -r e1f57f71809d -r 40e85d846bef usr.bin/Makefile
--- a/usr.bin/Makefile  Sun Jan 24 16:47:50 2016 +0000
+++ b/usr.bin/Makefile  Sun Jan 24 17:08:16 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.223 2016/01/14 04:27:26 christos Exp $
+#      $NetBSD: Makefile,v 1.224 2016/01/24 17:08:16 christos Exp $
 #      from: @(#)Makefile      8.3 (Berkeley) 1/7/94
 
 .include <bsd.own.mk>
@@ -7,7 +7,7 @@
        banner basename biff bthset btkey btpin \
        bzip2 bzip2recover c89 c99 cal calendar cap_mkdb cdplay \
        checknr chflags chpass cksum cmp cleantags col colcrt colrm \
-       column comm compress config crunch csplit ctags cut \
+       column comm compress config crunch csplit ctags cut cvslatest \
        deroff db dirname du \
        eject elf2aout elf2ecoff env error expand extattr \
        false fdformat fgen fincore find finger flock fmt fold fpr from \
diff -r e1f57f71809d -r 40e85d846bef usr.bin/cvslatest/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/cvslatest/Makefile        Sun Jan 24 17:08:16 2016 +0000
@@ -0,0 +1,6 @@
+#      $NetBSD: Makefile,v 1.1 2016/01/24 17:08:16 christos Exp $
+
+WARNS=6
+PROG=  cvslatest
+
+.include <bsd.prog.mk>
diff -r e1f57f71809d -r 40e85d846bef usr.bin/cvslatest/cvslatest.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/cvslatest/cvslatest.1     Sun Jan 24 17:08:16 2016 +0000
@@ -0,0 +1,76 @@
+.\" $NetBSD: cvslatest.1,v 1.1 2016/01/24 17:08:16 christos Exp $
+.\" Copyright (C) 2015 Thomas Klausner
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd January 7, 2016
+.Dt CVSLATEST 1
+.Os
+.Sh NAME
+.Nm cvslatest
+.Nd find latest timestamp in a set of CVS trees
+.Sh SYNOPSIS
+.Nm
+.Op Fl di
+.Op Fl n Ar name
+.Ar dir Op ...
+.Sh DESCRIPTION
+.Nm
+recursively scans the directories given on the command line
+and looks for
+.Xr cvs 1
+.Pa CVS/Entries
+files.
+.Nm
+then reads these files and parses the timestamps inside.
+Finally,
+.Nm
+prints the UNIX timestamp (seconds since UNIX epoch) of the
+newest file found.
+.Pp
+Supported options:
+.Bl -tag -width XnXnameXX
+.It Fl d
+Turn on debugging output.
+.It Fl i
+Ignore malformed timestamps in
+.Pa CVS/Entries
+files.
+.It Fl n Ar name
+Use
+.Ar name
+instead of
+.Pa CVS
+as the
+.Xr cvs 1
+information directory.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr cvs 1 ,
+.Xr date 1
+.Sh RETURN VALUES
+.Ex -std
+.Sh AUTHORS
+.An Christos Zoulas Aq Mt christos%NetBSD.org@localhost
diff -r e1f57f71809d -r 40e85d846bef usr.bin/cvslatest/cvslatest.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/cvslatest/cvslatest.c     Sun Jan 24 17:08:16 2016 +0000
@@ -0,0 +1,195 @@
+/*     $NetBSD: cvslatest.c,v 1.1 2016/01/24 17:08:16 christos Exp $   */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: cvslatest.c,v 1.1 2016/01/24 17:08:16 christos Exp $");
+
+/*
+ * Find the latest timestamp in a set of CVS trees, by examining the
+ * Entries files
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <fts.h>
+#include <time.h>
+
+static int debug = 0;
+static int ignore = 0;
+
+struct latest {
+       time_t time;
+       char path[MAXPATHLEN];
+};
+
+static void
+printlat(const struct latest *lat)
+{
+       fprintf(stderr, "%s %s", lat->path, ctime(&lat->time));
+}
+
+static void
+getrepo(const char *path, char *repo, size_t maxrepo)
+{
+       FILE *fp;
+       char name[MAXPATHLEN];
+       char *ptr;
+
+       snprintf(name, sizeof(name), "%s/Repository", path);
+       if ((fp = fopen(name, "r")) == NULL)
+               err(EXIT_FAILURE, "Can't open `%s'", name);
+       if (fgets(repo, (int)maxrepo, fp) == NULL)
+               err(EXIT_FAILURE, "Can't read `%s'", name);
+       if ((ptr = strchr(repo, '\n')) == NULL)
+               errx(EXIT_FAILURE, "Malformed line in `%s'", name);
+       *ptr = '\0';
+       fclose(fp);
+}
+
+static void
+getlatest(const char *path, const char *repo, struct latest *lat)
+{
+       static const char fmt[] = "%a %b %d %H:%M:%S %Y";
+       char name[MAXPATHLEN];
+       char entry[MAXPATHLEN * 2];
+       char *fn, *dt, *p;
+       time_t t;
+       struct tm tm;
+       FILE *fp;
+
+       snprintf(name, sizeof(name), "%s/Entries", path);
+       if ((fp = fopen(name, "r")) == NULL)
+               err(EXIT_FAILURE, "Can't open `%s'", name);
+
+       while (fgets(entry, (int)sizeof(entry), fp) != NULL) {
+               if (entry[0] != '/')
+                   continue;
+               if ((fn = strtok(entry, "/")) == NULL)
+                       goto mal;
+               if (strtok(NULL, "/") == NULL)
+                       goto mal;
+               if ((dt = strtok(NULL, "/")) == NULL)
+                       goto mal;
+               if ((p = strptime(dt, fmt, &tm)) == NULL || *p) {
+                       warnx("Malformed time `%s' in `%s'", dt, name);
+                       if (!ignore)
+                               exit(EXIT_FAILURE);
+               }
+               if ((t = mktime(&tm)) == (time_t)-1)
+                       errx(EXIT_FAILURE, "Time conversion `%s' in `%s'",
+                           dt, name);
+               if (lat->time == 0 || lat->time < t) {
+                       lat->time = t;
+                       snprintf(lat->path, sizeof(lat->path),
+                           "%s/%s", repo, fn);
+                       if (debug)
+                               printlat(lat);
+               }
+       }
+
+       fclose(fp);
+       return;
+                       
+mal:
+       errx(EXIT_FAILURE, "Malformed line in `%s'", name);
+}
+
+static void
+cvsscan(char **pathv, const char *name, struct latest *lat)
+{
+        FTS *dh;
+       char repo[MAXPATHLEN];
+        FTSENT *entry;
+
+       lat->time = 0;
+
+        dh = fts_open(pathv, FTS_PHYSICAL, NULL);
+        if (dh == NULL)
+               err(EXIT_FAILURE, "fts_open `%s'", pathv[0]);
+
+        while ((entry = fts_read(dh)) != NULL) {
+                if (entry->fts_info != FTS_D)
+                       continue;
+
+               if (strcmp(entry->fts_name, name) != 0)
+                        continue;
+
+               getrepo(entry->fts_path, repo, sizeof(repo));
+               getlatest(entry->fts_path, repo, lat);
+        }
+
+        (void)fts_close(dh);
+}
+
+static __dead void
+usage(void)
+{
+       fprintf(stderr, "Usage: %s [-di] [-n <name>] <path> ...\n",
+           getprogname());
+       exit(EXIT_FAILURE);
+}
+
+int
+main(int argc, char *argv[])
+{
+       struct latest lat;
+       const char *name = "CVS";
+       int c;
+
+       while ((c = getopt(argc, argv, "din:")) != -1)
+               switch (c) {
+               case 'i':
+                       ignore++;
+                       break;
+               case 'd':
+                       debug++;
+                       break;
+               case 'n':
+                       name = optarg;
+                       break;
+               default:
+                       usage();
+               }
+
+       if (argc == optind)
+               usage();



Home | Main Index | Thread Index | Old Index