Module Name:    src
Committed By:   christos
Date:           Fri Sep 15 21:03:26 UTC 2017

Modified Files:
        src/external/gpl2/xcvs/dist/src: cvs.h filesubr.c find_names.c import.c
            rcs.c subr.c update.c vers_ts.c

Log Message:
1/2 the number of {l,s}stat(2) calls by exposing the stat data found
when calling islink()!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/gpl2/xcvs/dist/src/cvs.h \
    src/external/gpl2/xcvs/dist/src/subr.c
cvs rdiff -u -r1.5 -r1.6 src/external/gpl2/xcvs/dist/src/filesubr.c
cvs rdiff -u -r1.3 -r1.4 src/external/gpl2/xcvs/dist/src/find_names.c
cvs rdiff -u -r1.7 -r1.8 src/external/gpl2/xcvs/dist/src/import.c
cvs rdiff -u -r1.6 -r1.7 src/external/gpl2/xcvs/dist/src/rcs.c
cvs rdiff -u -r1.11 -r1.12 src/external/gpl2/xcvs/dist/src/update.c
cvs rdiff -u -r1.2 -r1.3 src/external/gpl2/xcvs/dist/src/vers_ts.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl2/xcvs/dist/src/cvs.h
diff -u src/external/gpl2/xcvs/dist/src/cvs.h:1.4 src/external/gpl2/xcvs/dist/src/cvs.h:1.5
--- src/external/gpl2/xcvs/dist/src/cvs.h:1.4	Thu Mar  8 15:50:26 2012
+++ src/external/gpl2/xcvs/dist/src/cvs.h	Fri Sep 15 17:03:26 2017
@@ -516,7 +516,7 @@ typedef	RETSIGTYPE (*SIGCLEANUPPROC)	(in
 int SIG_register (int sig, SIGCLEANUPPROC sigcleanup);
 bool isdir (const char *file);
 bool isfile (const char *file);
-ssize_t islink (const char *file);
+ssize_t islink (const char *file, struct stat *stp);
 bool isdevice (const char *file);
 bool isreadable (const char *file);
 bool iswritable (const char *file);
Index: src/external/gpl2/xcvs/dist/src/subr.c
diff -u src/external/gpl2/xcvs/dist/src/subr.c:1.4 src/external/gpl2/xcvs/dist/src/subr.c:1.5
--- src/external/gpl2/xcvs/dist/src/subr.c:1.4	Mon May 30 13:49:51 2016
+++ src/external/gpl2/xcvs/dist/src/subr.c	Fri Sep 15 17:03:26 2017
@@ -13,7 +13,7 @@
  * Various useful functions for the CVS support code.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: subr.c,v 1.4 2016/05/30 17:49:51 christos Exp $");
+__RCSID("$NetBSD: subr.c,v 1.5 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 
@@ -719,7 +719,7 @@ resolve_symlink (char **filename)
     if (filename == NULL || *filename == NULL)
 	return;
 
-    while ((rsize = islink (*filename)) > 0)
+    while ((rsize = islink (*filename, NULL)) > 0)
     {
 #ifdef HAVE_READLINK
 	/* The clean thing to do is probably to have each filesubr.c

Index: src/external/gpl2/xcvs/dist/src/filesubr.c
diff -u src/external/gpl2/xcvs/dist/src/filesubr.c:1.5 src/external/gpl2/xcvs/dist/src/filesubr.c:1.6
--- src/external/gpl2/xcvs/dist/src/filesubr.c:1.5	Tue May 17 10:00:09 2016
+++ src/external/gpl2/xcvs/dist/src/filesubr.c	Fri Sep 15 17:03:26 2017
@@ -13,7 +13,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: filesubr.c,v 1.5 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: filesubr.c,v 1.6 2017/09/15 21:03:26 christos Exp $");
 
 /* These functions were moved out of subr.c because they need different
    definitions under operating systems (like, say, Windows NT) with different
@@ -25,6 +25,13 @@ __RCSID("$NetBSD: filesubr.c,v 1.5 2016/
 #include "xsize.h"
 
 static int deep_remove_dir (const char *path);
+#ifndef S_ISBLK
+#define S_ISBLK(a) 0
+#endif
+#ifndef S_ISCHR
+#define S_ISCHR(a) 0
+#endif
+#define IS_DEVICE(sbp) (S_ISBLK((sbp)->st_mode) || S_ISCHR((sbp)->st_mode))
 
 /*
  * Copies "from" to "to".
@@ -44,7 +51,7 @@ copy_file (const char *from, const char 
 
     /* If the file to be copied is a link or a device, then just create
        the new link or device appropriately. */
-    if ((rsize = islink (from)) > 0)
+    if ((rsize = islink (from, &sb)) > 0)
     {
 	char *source = Xreadlink (from, rsize);
 	if (symlink (source, to) == -1)
@@ -53,11 +60,9 @@ copy_file (const char *from, const char 
 	return;
     }
 
-    if (isdevice (from))
+    if (sb.st_ino != -1 && IS_DEVICE (&sb))
     {
 #if defined(HAVE_MKNOD) && defined(HAVE_STRUCT_STAT_ST_RDEV)
-	if (stat (from, &sb) < 0)
-	    error (1, errno, "cannot stat %s", from);
 	mknod (to, sb.st_mode, sb.st_rdev);
 #else
 	error (1, 0, "cannot copy device files on this system (%s)", from);
@@ -136,14 +141,22 @@ isdir (const char *file)
  * Returns size of the link if it is a symbolic link.
  */
 ssize_t
-islink (const char *file)
+islink (const char *file, struct stat *sbp)
 {
     ssize_t retsize = 0;
 #ifdef S_ISLNK
     struct stat sb;
+    if (sbp == NULL)
+	sbp = &sb;
 
-    if ((lstat (file, &sb) >= 0) && S_ISLNK (sb.st_mode))
-	retsize = sb.st_size;
+    if (lstat (file, sbp) < 0) {
+	sbp->st_ino = -1;
+	return 0;
+    }
+    if (S_ISLNK (sbp->st_mode))
+	retsize = sbp->st_size;
+#else
+    sbp->st_ino = -1;
 #endif
     return retsize;
 }
@@ -161,15 +174,7 @@ isdevice (const char *file)
 
     if (lstat (file, &sb) < 0)
 	return false;
-#ifdef S_ISBLK
-    if (S_ISBLK (sb.st_mode))
-	return true;
-#endif
-#ifdef S_ISCHR
-    if (S_ISCHR (sb.st_mode))
-	return true;
-#endif
-    return false;
+    return IS_DEVICE(&sb);
 }
 
 

Index: src/external/gpl2/xcvs/dist/src/find_names.c
diff -u src/external/gpl2/xcvs/dist/src/find_names.c:1.3 src/external/gpl2/xcvs/dist/src/find_names.c:1.4
--- src/external/gpl2/xcvs/dist/src/find_names.c:1.3	Tue May 17 10:00:09 2016
+++ src/external/gpl2/xcvs/dist/src/find_names.c	Fri Sep 15 17:03:26 2017
@@ -21,7 +21,7 @@
  * repository (and optionally the attic)
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: find_names.c,v 1.3 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: find_names.c,v 1.4 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include <glob.h>
@@ -494,7 +494,7 @@ find_dirs (char *dir, List *list, int ch
 #endif
 		/* Note that we only get here if we already set tmp
 		   above.  */
-		if (islink (tmp))
+		if (islink (tmp, NULL))
 		    goto do_it_again;
 #ifdef DT_DIR
 	    }

Index: src/external/gpl2/xcvs/dist/src/import.c
diff -u src/external/gpl2/xcvs/dist/src/import.c:1.7 src/external/gpl2/xcvs/dist/src/import.c:1.8
--- src/external/gpl2/xcvs/dist/src/import.c:1.7	Mon May 30 13:49:51 2016
+++ src/external/gpl2/xcvs/dist/src/import.c	Fri Sep 15 17:03:26 2017
@@ -21,7 +21,7 @@
  * Additional arguments specify more Vendor Release Tags.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: import.c,v 1.7 2016/05/30 17:49:51 christos Exp $");
+__RCSID("$NetBSD: import.c,v 1.8 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "lstat.h"
@@ -520,9 +520,9 @@ import_descend (char *message, char *vta
 	    else if (
 #ifdef DT_DIR
 		     dp->d_type == DT_LNK
-		     || (dp->d_type == DT_UNKNOWN && islink (dp->d_name))
+		     || (dp->d_type == DT_UNKNOWN && islink (dp->d_name, NULL))
 #else
-		     islink (dp->d_name)
+		     islink (dp->d_name, NULL)
 #endif
 		     )
 	    {
@@ -1722,7 +1722,7 @@ import_descend_dir (char *message, char 
     int ierrno, err;
     char *rcs = NULL;
 
-    if (islink (dir))
+    if (islink (dir, NULL))
 	return 0;
     if (save_cwd (&cwd))
     {

Index: src/external/gpl2/xcvs/dist/src/rcs.c
diff -u src/external/gpl2/xcvs/dist/src/rcs.c:1.6 src/external/gpl2/xcvs/dist/src/rcs.c:1.7
--- src/external/gpl2/xcvs/dist/src/rcs.c:1.6	Tue May 17 10:00:09 2016
+++ src/external/gpl2/xcvs/dist/src/rcs.c	Fri Sep 15 17:03:26 2017
@@ -14,7 +14,7 @@
  * manipulation
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rcs.c,v 1.6 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: rcs.c,v 1.7 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "edit.h"
@@ -4549,7 +4549,7 @@ workfile);
 	    {
 		/* Symbolic links should be removed before replacement, so that
 		   `fopen' doesn't follow the link and open the wrong file. */
-		if (islink (sout))
+		if (islink (sout, NULL))
 		    if (unlink_file (sout) < 0)
 			error (1, errno, "cannot remove %s", sout);
 		ofp = CVS_FOPEN (sout, expand == KFLAG_B ? "wb" : "w");
@@ -4561,7 +4561,7 @@ workfile);
 	{
 	    /* Output is supposed to go to WORKFILE, so we should open that
 	       file.  Symbolic links should be removed first (see above). */
-	    if (islink (workfile))
+	    if (islink (workfile, NULL))
 		if (unlink_file (workfile) < 0)
 		    error (1, errno, "cannot remove %s", workfile);
 

Index: src/external/gpl2/xcvs/dist/src/update.c
diff -u src/external/gpl2/xcvs/dist/src/update.c:1.11 src/external/gpl2/xcvs/dist/src/update.c:1.12
--- src/external/gpl2/xcvs/dist/src/update.c:1.11	Wed Jan  4 11:11:20 2017
+++ src/external/gpl2/xcvs/dist/src/update.c	Fri Sep 15 17:03:26 2017
@@ -38,7 +38,7 @@
  * as well.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: update.c,v 1.11 2017/01/04 16:11:20 christos Exp $");
+__RCSID("$NetBSD: update.c,v 1.12 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include <assert.h>
@@ -2678,12 +2678,12 @@ special_file_mismatch (struct file_info 
     {
 	ssize_t rsize;
 
-	if ((rsize = islink (finfo->file)) > 0)
+	if ((rsize = islink (finfo->file, &sb)) > 0)
 	    rev1_symlink = Xreadlink (finfo->file, rsize);
 	else
 	{
 # ifdef HAVE_STRUCT_STAT_ST_RDEV
-	    if (lstat (finfo->file, &sb) < 0)
+	    if (sb.st_ino == -1)
 		error (1, errno, "could not get file information for %s",
 		       finfo->file);
 	    rev1_uid = sb.st_uid;
@@ -2758,12 +2758,12 @@ special_file_mismatch (struct file_info 
     {
 	ssize_t rsize;
 
-	if ((rsize = islink (finfo->file)) > 0)
+	if ((rsize = islink (finfo->file, &sb)) > 0)
 	    rev2_symlink = Xreadlink (finfo->file, rsize);
 	else
 	{
 # ifdef HAVE_STRUCT_STAT_ST_RDEV
-	    if (lstat (finfo->file, &sb) < 0)
+	    if (sb.st_ino == -1)
 		error (1, errno, "could not get file information for %s",
 		       finfo->file);
 	    rev2_uid = sb.st_uid;

Index: src/external/gpl2/xcvs/dist/src/vers_ts.c
diff -u src/external/gpl2/xcvs/dist/src/vers_ts.c:1.2 src/external/gpl2/xcvs/dist/src/vers_ts.c:1.3
--- src/external/gpl2/xcvs/dist/src/vers_ts.c:1.2	Tue May 17 10:00:09 2016
+++ src/external/gpl2/xcvs/dist/src/vers_ts.c	Fri Sep 15 17:03:26 2017
@@ -11,7 +11,7 @@
  * specified in the README file that comes with the CVS source distribution.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: vers_ts.c,v 1.2 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: vers_ts.c,v 1.3 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "lstat.h"
@@ -401,19 +401,19 @@ time_t
 unix_time_stamp (const char *file)
 {
     struct stat sb;
-    time_t mtime = 0L;
+    time_t mtime;
+    bool lnk;
 
-    if (!lstat (file, &sb))
-    {
-	mtime = sb.st_mtime;
-    }
+    if (!(lnk = islink (file, &sb)) && sb.st_ino == -1)
+	return 0;
+    mtime = sb.st_mtime;
 
     /* If it's a symlink, return whichever is the newest mtime of
        the link and its target, for safety.
     */
-    if (!stat (file, &sb))
+    if (lnk && stat (file, &sb) != -1)
     {
-        if (mtime < sb.st_mtime)
+	if (mtime < sb.st_mtime)
 	    mtime = sb.st_mtime;
     }
 

Reply via email to