quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH 19/39] backup-files: Use internal implementation of d


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 19/39] backup-files: Use internal implementation of dirname
Date: Sat, 19 Mar 2011 10:52:49 +0100
User-agent: quilt/0.48-17.1

Use quilt's internal implementation of dirname. This is more
efficient than calling an external binary, and avoids a dependency.

Signed-off-by: Jean Delvare <address@hidden>
Reviewed-by: Raphael Hertzog <address@hidden>
---
 Makefile.in                   |    6 ++---
 quilt/scripts/backup-files.in |    3 ++
 quilt/scripts/patchfns.in     |   38 +-----------------------------------
 quilt/scripts/utilfns         |   44 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+), 39 deletions(-)

--- a/quilt/scripts/backup-files.in
+++ b/quilt/scripts/backup-files.in
@@ -44,6 +44,9 @@ usage () {
 "
 }
 
+: address@hidden@}
+. $QUILT_DIR/scripts/utilfns
+
 ensure_nolinks() {
        local filename="$1"
        local link_count tmpname
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -43,6 +43,8 @@ if [ -n "$QUILT_COMMAND" ]; then
        unset args
 fi
 
+. $QUILT_DIR/scripts/utilfns
+
 # ========================================================
 
 declare -a exit_handlers
@@ -88,42 +90,6 @@ quote_re()
        echo "$1" | sed -e 's:\([][?{(|)}^$/.+*\\]\):\\\1:g'
 }
 
-basename()
-{
-       local path=$1
-       while [ "${path:(-1)}" = "/" ]
-       do
-               path=${path%/}
-       done
-       echo "${path##*/}"
-}
-
-dirname()
-{
-       local path=$1
-       while [ "${path:(-1)}" = "/" ]
-       do
-               path=${path%/}
-       done
-       local basename="${path##*/}"
-       path="${path:0:${#path}-${#basename}}"
-       while [ "${path:(-1)}" = "/" ]
-       do
-               path=${path%/}
-       done
-       if [ -n "$path" ]
-       then
-               echo "$path"
-       else
-               if [ ${1:0:1} = "/" ]
-               then
-                       echo "/"
-               else
-                       echo "."
-               fi
-       fi
-}
-
 patch_file_name()
 {
        echo "$QUILT_PATCHES/$1"
--- a/Makefile.in
+++ b/Makefile.in
@@ -200,7 +200,7 @@ doc/quilt.1: doc/quilt.1.in $(QUILT:%=qu
        done < $< 2>&1 > $@
 
 .PHONY :: reference
-reference : $(QUILT:%=quilt/%) quilt/scripts/patchfns compat
+reference : $(QUILT:%=quilt/%) quilt/scripts/patchfns quilt/scripts/utilfns 
compat
        @unset LANG LC_MESSAGES LC_CTYPE LC_ALL;                        \
        for i in $(QUILT);                                              \
        do                                                              \
@@ -296,7 +296,7 @@ install-main :: scripts
        $(INSTALL) -m 755 $(patsubst %,quilt/scripts/%,                 \
                          $(filter-out patchfns,$(SCRIPTS)))            \
                   $(BUILD_ROOT)$(datadir)/$(PACKAGE)/scripts
-       $(INSTALL) -m 644 quilt/scripts/patchfns                        \
+       $(INSTALL) -m 644 quilt/scripts/patchfns quilt/scripts/utilfns  \
                   $(BUILD_ROOT)$(datadir)/$(PACKAGE)/scripts
 ifneq ($(PATCH_WRAPPER),)
        $(INSTALL) -d $(BUILD_ROOT)$(datadir)/$(PACKAGE)/wrapper
@@ -363,7 +363,7 @@ test/.patch-wrapper.ok : bin/patch-wrapp
 
 # Include a run-time generated list of dependencies for each test case
 test/.depend : Makefile $(TESTS)
-       @(  printf "%s : bin/quilt quilt/scripts/patchfns 
quilt/scripts/backup-files $(COMPAT)\n" $(TESTS); \
+       @(  printf "%s : bin/quilt quilt/scripts/patchfns quilt/scripts/utilfns 
quilt/scripts/backup-files $(COMPAT)\n" $(TESTS); \
            $(AWK) 'sub(/.*\$$ *quilt /, "")                            \
                        { print FILENAME, ":", "quilt/"$$1}' $(TESTS); \
            $(AWK) 'sub(/.*\<quilt_command /, "") && ($$1 !~ /[^a-z]/)  \
--- /dev/null
+++ b/quilt/scripts/utilfns
@@ -0,0 +1,44 @@
+# This file contains the common functions used by patchfns and backup-files.
+# It is meant to be sourced by bash scripts.
+
+#  This script is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+#
+#  See the COPYING and AUTHORS files for more details.
+
+basename()
+{
+       local path=$1
+       while [ "${path:(-1)}" = "/" ]
+       do
+               path=${path%/}
+       done
+       echo "${path##*/}"
+}
+
+dirname()
+{
+       local path=$1
+       while [ "${path:(-1)}" = "/" ]
+       do
+               path=${path%/}
+       done
+       local basename="${path##*/}"
+       path="${path:0:${#path}-${#basename}}"
+       while [ "${path:(-1)}" = "/" ]
+       do
+               path=${path%/}
+       done
+       if [ -n "$path" ]
+       then
+               echo "$path"
+       else
+               if [ ${1:0:1} = "/" ]
+               then
+                       echo "/"
+               else
+                       echo "."
+               fi
+       fi
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]