summaryrefslogtreecommitdiff
path: root/usr/src/tools
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2012-10-10 22:15:50 -0400
committerRichard Lowe <richlowe@richlowe.net>2012-11-08 18:05:52 -0500
commit1b1e41dddacfa4b5e760a44f8da7c420cf162bcb (patch)
treead982360c45b36d6820174db483f8019508d7e86 /usr/src/tools
parente4942d465a2e74517e911b593b47863c51bd3362 (diff)
downloadillumos-joyent-1b1e41dddacfa4b5e760a44f8da7c420cf162bcb.tar.gz
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>
Diffstat (limited to 'usr/src/tools')
-rw-r--r--usr/src/tools/findunref/findunref.169
-rw-r--r--usr/src/tools/findunref/findunref.c56
-rw-r--r--usr/src/tools/scripts/nightly.sh2
3 files changed, 91 insertions, 36 deletions
diff --git a/usr/src/tools/findunref/findunref.1 b/usr/src/tools/findunref/findunref.1
index 29af536a19..a9f4af87b7 100644
--- a/usr/src/tools/findunref/findunref.1
+++ b/usr/src/tools/findunref/findunref.1
@@ -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 @@ desired, \fIexceptfile\fP can be \fB/dev/null\fP.
.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 @@ Only look under \fIsubtree\fP for unreferenced files. By default, all
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 @@ be merged with \fBcomm\fP(1):
.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
diff --git a/usr/src/tools/findunref/findunref.c b/usr/src/tools/findunref/findunref.c
index 11764c4963..c270c42854 100644
--- a/usr/src/tools/findunref/findunref.c
+++ b/usr/src/tools/findunref/findunref.c
@@ -76,8 +76,8 @@ typedef struct {
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 @@ static const scm_t scms[] = {
{ "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 @@ main(int argc, char *argv[])
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 @@ load_manifest(const char *hgroot)
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 @@ fail:
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 @@ check_hg(const char *path, const struct FTW *ftwp)
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
diff --git a/usr/src/tools/scripts/nightly.sh b/usr/src/tools/scripts/nightly.sh
index 8d52a1f7c1..9ad9454f4d 100644
--- a/usr/src/tools/scripts/nightly.sh
+++ b/usr/src/tools/scripts/nightly.sh
@@ -2124,7 +2124,7 @@ function child_wstype {
fi
case "$scm_type" in
- none|subversion|teamware|mercurial)
+ none|subversion|git|teamware|mercurial)
;;
*) scm_type=none
;;