Module Name:    src
Committed By:   apb
Date:           Wed Apr  8 19:03:13 UTC 2009

Modified Files:
        src/usr.sbin/mtree: extern.h mtree.8 mtree.c spec.c

Log Message:
The recent addition of sorting to "mtree -C" broke some third party
scripts.  Now make sorting optional, controled by the "-S" flag.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.sbin/mtree/extern.h
cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/mtree/mtree.8
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/mtree/mtree.c
cvs rdiff -u -r1.73 -r1.74 src/usr.sbin/mtree/spec.c

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

Modified files:

Index: src/usr.sbin/mtree/extern.h
diff -u src/usr.sbin/mtree/extern.h:1.30 src/usr.sbin/mtree/extern.h:1.31
--- src/usr.sbin/mtree/extern.h:1.30	Thu Dec 14 20:09:36 2006
+++ src/usr.sbin/mtree/extern.h	Wed Apr  8 19:03:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.30 2006/12/14 20:09:36 he Exp $	*/
+/*	$NetBSD: extern.h,v 1.31 2009/04/08 19:03:13 apb Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -71,7 +71,7 @@
 int	 verify(void);
 
 extern int	dflag, eflag, iflag, lflag, mflag, rflag, sflag, tflag, uflag;
-extern int	mtree_Mflag, mtree_Wflag;
+extern int	mtree_Mflag, mtree_Sflag, mtree_Wflag;
 extern size_t	mtree_lineno;
 extern u_int32_t crc_total;
 extern int	ftsoptions, keys;

Index: src/usr.sbin/mtree/mtree.8
diff -u src/usr.sbin/mtree/mtree.8:1.48 src/usr.sbin/mtree/mtree.8:1.49
--- src/usr.sbin/mtree/mtree.8:1.48	Wed Mar 11 18:10:05 2009
+++ src/usr.sbin/mtree/mtree.8	Wed Apr  8 19:03:13 2009
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mtree.8,v 1.48 2009/03/11 18:10:05 joerg Exp $
+.\"	$NetBSD: mtree.8,v 1.49 2009/04/08 19:03:13 apb Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -56,7 +56,7 @@
 .\"
 .\"     @(#)mtree.8	8.2 (Berkeley) 12/11/93
 .\"
-.Dd February 1, 2009
+.Dd April 8, 2009
 .Dt MTREE 8
 .Os
 .Sh NAME
@@ -64,7 +64,7 @@
 .Nd map a directory hierarchy
 .Sh SYNOPSIS
 .Nm
-.Op Fl cCdDelLMPruUWx
+.Op Fl cCdDelLMPrSuUWx
 .Bk -words
 .Op Fl i | Fl m
 .Ek
@@ -131,6 +131,9 @@
 and
 .Fl I
 can be used to control which files are printed.
+The
+.Fl S
+option can be used to sort the output.
 .It Fl D
 As per
 .Fl C ,
@@ -245,6 +248,27 @@
 .Sy cksum
 was specified.
 The checksum is seeded with the specified value.
+.It Fl S
+When reading a specification into an internal data structure,
+sort the entries.
+This will affect the order in which the
+.Fl c
+option checks entries, and the order of the output produced by the
+.Fl C
+or
+.Fl D
+options.
+It will
+The sort order is the same as that used by the
+.Fl c
+option, which is that entries within the same directory are
+sorted in the order used by
+.Xr strcmp 3 ,
+except that entries for subdirectories sort after other entries.
+By default, if the
+.Fl S
+option is not used, entries within the same directory are collected
+together (separated from entries for other directories), but not sorted.
 .It Fl u
 Modify the owner, group, permissions, and flags of existing files,
 the device type of devices, and symbolic link targets,

Index: src/usr.sbin/mtree/mtree.c
diff -u src/usr.sbin/mtree/mtree.c:1.34 src/usr.sbin/mtree/mtree.c:1.35
--- src/usr.sbin/mtree/mtree.c:1.34	Mon Jul 21 13:36:59 2008
+++ src/usr.sbin/mtree/mtree.c	Wed Apr  8 19:03:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: mtree.c,v 1.34 2008/07/21 13:36:59 lukem Exp $	*/
+/*	$NetBSD: mtree.c,v 1.35 2009/04/08 19:03:13 apb Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1990, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)mtree.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mtree.c,v 1.34 2008/07/21 13:36:59 lukem Exp $");
+__RCSID("$NetBSD: mtree.c,v 1.35 2009/04/08 19:03:13 apb Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,7 +77,8 @@
 	dir = NULL;
 	init_excludes();
 
-	while ((ch = getopt(argc, argv, "cCdDeE:f:I:ik:K:lLmMN:p:PrR:s:tuUWxX:"))
+	while ((ch = getopt(argc, argv,
+	    "cCdDeE:f:I:ik:K:lLmMN:p:PrR:s:StuUWxX:"))
 	    != -1) {
 		switch((char)ch) {
 		case 'c':
@@ -159,6 +160,9 @@
 			if (*p)
 				mtree_err("illegal seed value -- %s", optarg);
 			break;
+		case 'S':
+			mtree_Sflag = 1;
+			break;
 		case 't':
 			tflag = 1;
 			break;

Index: src/usr.sbin/mtree/spec.c
diff -u src/usr.sbin/mtree/spec.c:1.73 src/usr.sbin/mtree/spec.c:1.74
--- src/usr.sbin/mtree/spec.c:1.73	Tue Apr  7 18:06:41 2009
+++ src/usr.sbin/mtree/spec.c	Wed Apr  8 19:03:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: spec.c,v 1.73 2009/04/07 18:06:41 apb Exp $	*/
+/*	$NetBSD: spec.c,v 1.74 2009/04/08 19:03:13 apb Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -67,7 +67,7 @@
 #if 0
 static char sccsid[] = "@(#)spec.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: spec.c,v 1.73 2009/04/07 18:06:41 apb Exp $");
+__RCSID("$NetBSD: spec.c,v 1.74 2009/04/08 19:03:13 apb Exp $");
 #endif
 #endif /* not lint */
 
@@ -91,6 +91,7 @@
 size_t	mtree_lineno;			/* Current spec line number */
 int	mtree_Mflag;			/* Merge duplicate entries */
 int	mtree_Wflag;			/* Don't "whack" permissions */
+int	mtree_Sflag;			/* Sort entries */
 
 static	dev_t	parsedev(char *);
 static	void	replacenode(NODE *, NODE *);
@@ -664,7 +665,7 @@
  *	Add the centry node as a child of the pathparent node.	If
  *	centry is a duplicate, call replacenode().  If centry is not
  *	a duplicate, insert it into the linked list referenced by
- *	pathparent->child.  Keep the list sorted.
+ *	pathparent->child.  Keep the list sorted if Sflag is set.
  */
 static void
 addchild(NODE *pathparent, NODE *centry)
@@ -698,13 +699,16 @@
 			/* centry appears after cur in sort order */
 			insertpos = cur;
 		}
-		if (cmp < 0 || cur->next == NULL) {
+		if ((mtree_Sflag && cmp < 0) || cur->next == NULL) {
 			/*
 			 * centry appears before cur in sort order,
 			 * or we reached the end of the list; insert
 			 * centry either just after insertpos, or at the
-			 * beginning of the list.
+			 * beginning of the list.  If we are not sorting,
+			 * then always append to the list.
 			 */
+			if (!mtree_Sflag)
+				insertpos = cur;
 			if (insertpos) {
 				centry->next = insertpos->next;
 				insertpos->next = centry;

Reply via email to