changeset 13885:31eec1000095

3272 findunref should support git Reviewed by: Garrett D'Amore <garrett@damore.org> Reviewed by: Joshua M. Clulow <josh@sysmgr.org> Approved by: Eric Schrock <eric.schrock@delphix.com>
author Richard Lowe <richlowe@richlowe.net>
date Wed, 10 Oct 2012 22:15:50 -0400
parents 3ddfdcd2a5b8
children e3261d03efbf
files usr/src/tools/findunref/findunref.1 usr/src/tools/findunref/findunref.c usr/src/tools/scripts/nightly.sh
diffstat 3 files changed, 91 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/tools/findunref/findunref.1	Tue Oct 30 15:27:39 2012 -0400
+++ b/usr/src/tools/findunref/findunref.1	Wed Oct 10 22:15:50 2012 -0400
@@ -1,30 +1,30 @@
-.\" " CDDL HEADER START
-.\" "
-.\" " The contents of this file are subject to the terms of the
-.\" " Common Development and Distribution License (the "License").
-.\" " You may not use this file except in compliance with the License.
-.\" "
-.\" " You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-.\" " or http://www.opensolaris.org/os/licensing.
-.\" " See the License for the specific language governing permissions
-.\" " and limitations under the License.
-.\" "
-.\" " When distributing Covered Code, include this CDDL HEADER in each
-.\" " file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-.\" " If applicable, add the following below this CDDL HEADER, with the
-.\" " fields enclosed by brackets "[]" replaced with your own identifying
-.\" " information: Portions Copyright [yyyy] [name of copyright owner]
-.\" "
-.\" " CDDL HEADER END
-.\" "
-.\" "Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
-.\" "Use is subject to license terms.
-.TH findunref 1 "11 Aug 2009"
+.\" CDDL HEADER START
+.\"
+.\" The contents of this file are subject to the terms of the
+.\" Common Development and Distribution License (the "License").
+.\" You may not use this file except in compliance with the License.
+.\"
+.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+.\" or http://www.opensolaris.org/os/licensing.
+.\" See the License for the specific language governing permissions
+.\" and limitations under the License.
+.\"
+.\" When distributing Covered Code, include this CDDL HEADER in each
+.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+.\" If applicable, add the following below this CDDL HEADER, with the
+.\" fields enclosed by brackets "[]" replaced with your own identifying
+.\" information: Portions Copyright [yyyy] [name of copyright owner]
+.\"
+.\" CDDL HEADER END
+.\"
+.\" Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+.\" Use is subject to license terms.
+.TH findunref 1 "Oct 30, 2012"
 .I findunref
 \- find unused files in a source tree
 .SH SYNOPSIS
 findunref [\fB-s\fP \fIsubtree\fP] [\fB-t\fP \fItstampfile\fP]
-[\fB-S\fP \fBhg\fP|\fBtw\fP] \fIsrcroot\fP \fIexceptfile\fP
+[\fB-S\fP \fBhg\fP|\fBtw\fP|\fBgit\fP] \fIsrcroot\fP \fIexceptfile\fP
 .LP
 .SH DESCRIPTION
 .IX "OS-Net build tools" "findunref" "" "\fBfindunref\fP"
@@ -50,10 +50,15 @@
 .LP
 Depending on how findunref is invoked, it can either check all files, or
 limit its checks to files under control of a specific source code
-management (SCM) system.  To limit checks to files managed by Mercurial,
-the \fBhg\fP(1) utility must be present in \fB/usr/bin\fP and any relevant
-repositories must be located at or under \fIsrcroot\fP.  Nested Mercurial
-repositories are supported.
+management (SCM) system.
+.LP
+To limit checks to files managed by Mercurial, the \fBhg\fP(1) utility must be
+present in \fB$PATH\fP and any relevant repositories must be located at or
+under \fIsrcroot\fP.  Nested Mercurial repositories are supported.
+.LP
+To limit checks to files managed by Git, the \fBgit\fP(1) utility must be
+present in \fB$PATH\fP and any relevant repositories must be located at or
+under \fIsrcroot\fP.  Nested Git repositories are \fInot\fR supported.
 .SH OPTIONS
 .TP 10
 .B -s \fIsubtree\fP
@@ -61,15 +66,17 @@
 directories under \fIsrcroot\fP are examined.
 .TP 10
 .B -t \fItstampfile\fP
-Consider files older than \fItstampfile\fP to be unreferenced. 
+Consider files older than \fItstampfile\fP to be unreferenced.
 By default, \fIsrcroot\fB/.build.tstamp\fR is used.
 .TP 10
-.B -S \fBhg\fP|\fBtw\fP
+.B -S \fBhg\fP|\fBtw\fP|\fBgit\fP
 Only check files that are managed by the specified SCM.  To simplify
 interaction with \fBwhich_scm\fP(1), the SCM names "mercurial" and
-"teamware" may also be specified.  By default, all files are checked.
+"teamware" may also be specified for "hg" and "tw", respectively.
+By default, all files are checked.
 .SH SEE ALSO
 .LP
+\fBgit\fP(1),
 \fBhg\fP(1),
 \fBnightly\fP(1),
 \fBwhich_scm\fP(1)
@@ -83,7 +90,7 @@
 .LP
 .nf
 comm -12 /path/to/unref-i386.out
-         /path/to/unref-sparc.out > unref.out 
+         /path/to/unref-sparc.out > unref.out
 .fi
 .LP
 This merged file can then be compared against the gate's latest
--- a/usr/src/tools/findunref/findunref.c	Tue Oct 30 15:27:39 2012 -0400
+++ b/usr/src/tools/findunref/findunref.c	Wed Oct 10 22:15:50 2012 -0400
@@ -76,8 +76,8 @@
 	chdirscm_func_t	*chdirfunc;
 } scm_t;
 
-static checkscm_func_t check_tw, check_hg;
-static chdirscm_func_t chdir_hg;
+static checkscm_func_t check_tw, check_hg, check_git;
+static chdirscm_func_t chdir_hg, chdir_git;
 static int	pnset_add(pnset_t *, const char *);
 static int	pnset_check(const pnset_t *, const char *);
 static void	pnset_empty(pnset_t *);
@@ -92,11 +92,13 @@
 	{ "teamware",	check_tw,	NULL		},
 	{ "hg",		check_hg,	chdir_hg 	},
 	{ "mercurial",	check_hg,	chdir_hg	},
+	{ "git",	check_git,	chdir_git	},
 	{ NULL,		NULL, 		NULL		}
 };
 
 static const scm_t	*scm;
 static hgdata_t		hgdata;
+static pnset_t		*gitmanifest = NULL;
 static time_t		tstamp;		/* timestamp to compare files to */
 static pnset_t		*exsetp;	/* pathname globs to ignore */
 static const char	*progname;
@@ -150,7 +152,7 @@
 
 	if (argc != 2) {
 usage:		(void) fprintf(stderr, "usage: %s [-s <subtree>] "
-		    "[-t <tstampfile>] [-S hg|tw] <srcroot> <exceptfile>\n",
+		    "[-t <tstampfile>] [-S hg|tw|git] <srcroot> <exceptfile>\n",
 		    progname);
 		return (EXIT_FAILURE);
 	}
@@ -201,7 +203,7 @@
 
 	pnsetp = calloc(sizeof (pnset_t), 1);
 	if (pnsetp == NULL ||
-	    asprintf(&hgcmd, "/usr/bin/hg manifest -R %s", hgroot) == -1)
+	    asprintf(&hgcmd, "hg manifest -R %s", hgroot) == -1)
 		goto fail;
 
 	fp = popen(hgcmd, "r");
@@ -229,6 +231,45 @@
 	return (NULL);
 }
 
+static void
+chdir_git(const char *path)
+{
+	FILE *fp = NULL;
+	char *gitcmd = NULL;
+	char *newline;
+	char fn[MAXPATHLEN];
+	pnset_t *pnsetp;
+
+	pnsetp = calloc(sizeof (pnset_t), 1);
+	if ((pnsetp == NULL) ||
+	    (asprintf(&gitcmd, "git ls-files %s", path) == -1))
+		goto fail;
+
+	if ((fp = popen(gitcmd, "r")) == NULL)
+		goto fail;
+
+	while (fgets(fn, sizeof (fn), fp) != NULL) {
+		if ((newline = strrchr(fn, '\n')) != NULL)
+			*newline = '\0';
+
+		if (pnset_add(pnsetp, fn) == 0)
+			goto fail;
+	}
+
+	(void) pclose(fp);
+	free(gitcmd);
+	gitmanifest = pnsetp;
+	return;
+fail:
+	warn("cannot load git manifest");
+	if (fp != NULL)
+		(void) pclose(fp);
+	if (pnsetp != NULL)
+		free(pnsetp);
+	if (gitcmd != NULL)
+		free(gitcmd);
+}
+
 /*
  * If necessary, change our active manifest to be appropriate for `path'.
  */
@@ -308,6 +349,13 @@
 
 	return (hgdata.manifest != NULL && pnset_check(hgdata.manifest, path));
 }
+/* ARGSUSED */
+static int
+check_git(const char *path, const struct FTW *ftwp)
+{
+	path += 2;		/* Skip "./" */
+	return (gitmanifest != NULL && pnset_check(gitmanifest, path));
+}
 
 /*
  * Check if a file is under TeamWare control by checking for its corresponding
--- a/usr/src/tools/scripts/nightly.sh	Tue Oct 30 15:27:39 2012 -0400
+++ b/usr/src/tools/scripts/nightly.sh	Wed Oct 10 22:15:50 2012 -0400
@@ -2124,7 +2124,7 @@
 	fi
 
 	case "$scm_type" in
-	none|subversion|teamware|mercurial)
+	none|subversion|git|teamware|mercurial)
 		;;
 	*)	scm_type=none
 		;;