quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH v3 2/2] pager support like git


From: Bert Wesarg
Subject: [Quilt-dev] [PATCH v3 2/2] pager support like git
Date: Wed, 18 Nov 2009 23:30:11 +0100

Include the pager support from the TopGit script into Quilt.

Signed-off-by: Bert Wesarg <address@hidden>

---

ChangeLog v3:
  Use exit handler multiplexer to remove pipe
  Use gen_tempfile instead of mktemp

ChangeLog v2:
  Remove QUILT_PAGER_IN_USE, it was irrelevant

 quilt/annotate.in         |    2 ++
 quilt/applied.in          |    2 ++
 quilt/diff.in             |    2 ++
 quilt/files.in            |    2 ++
 quilt/header.in           |    2 ++
 quilt/patches.in          |    2 ++
 quilt/scripts/patchfns.in |   32 ++++++++++++++++++++++++++++++++
 quilt/series.in           |    2 ++
 quilt/unapplied.in        |    2 ++
 9 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/quilt/annotate.in b/quilt/annotate.in
index 8bf50ef..0366f5a 100644
--- a/quilt/annotate.in
+++ b/quilt/annotate.in
@@ -161,6 +161,8 @@ add_exit_handler "rm -f $template"
 # Finally, the annotations listing is merged with the source file line
 # by line.
 
+setup_pager
+
 empty_file ${files[0]} > $template
 for ((n = 0; n < address@hidden; n++))
 do
diff --git a/quilt/applied.in b/quilt/applied.in
index 7ead8da..0cea4b8 100644
--- a/quilt/applied.in
+++ b/quilt/applied.in
@@ -59,6 +59,8 @@ fi
 
 patch=$(find_applied_patch "$1") || exit 1
 
+setup_pager
+
 for patch in $(applied_before "$patch") $patch
 do
        echo "$(print_patch $patch)"
diff --git a/quilt/diff.in b/quilt/diff.in
index 8435024..86da3f5 100644
--- a/quilt/diff.in
+++ b/quilt/diff.in
@@ -310,6 +310,8 @@ then
        || die 1
 fi
 
+setup_pager
+
 for file in "address@hidden"
 do
        if [ -n "$opt_snapshot" -a -e "$QUILT_PC/$snap_subdir/$file" ]
diff --git a/quilt/files.in b/quilt/files.in
index ba8b054..033abe0 100644
--- a/quilt/files.in
+++ b/quilt/files.in
@@ -159,6 +159,8 @@ list_files_in_patch()
        done
 }
 
+setup_pager
+
 for patch in address@hidden
 do
        list_files_in_patch $patch
diff --git a/quilt/header.in b/quilt/header.in
index f1a14e4..a3bbcbc 100644
--- a/quilt/header.in
+++ b/quilt/header.in
@@ -125,6 +125,8 @@ if [ -z "$opt_replace" -a -z "$opt_append" -a -z 
"$opt_edit" ]
 then
        [ -e "$patch_file" ] || exit 0
 
+       setup_pager
+
        cat_file "$patch_file" \
        | patch_header \
        | maybe_strip_diffstat \
diff --git a/quilt/patches.in b/quilt/patches.in
index 31d7ef1..fe95300 100644
--- a/quilt/patches.in
+++ b/quilt/patches.in
@@ -147,6 +147,8 @@ fi
 
 [ -n "$opt_color" ] && setup_colors
 
+setup_pager
+
 scan_applied "$color_series_app" "$applied" "$opt_file" \
        $(patches_before $top)
 [ -n "$top" ] && \
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index 48f0d37..50578ec 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -972,6 +972,38 @@ quilt_command()
        QUILT_COMMAND="" bash $BASH_OPTS -c "${SUBDIR:+cd $SUBDIR;} . 
$QUILT_DIR/$command" "quilt $command" "$@"
 }
 
+# isatty FD
+isatty()
+{
+       test -t $1
+}
+
+# setup_pager
+# Spawn pager process and redirect the rest of our output to it
+setup_pager()
+{
+       isatty 1 || return 0
+
+       # QUILT_PAGER = GIT_PAGER | PAGER | less
+       # NOTE: GIT_PAGER='' is significant
+       QUILT_PAGER=${GIT_PAGER-${PAGER-less}}
+
+       [ -z "$QUILT_PAGER"  -o  "$QUILT_PAGER" = "cat" ]  && return 0
+
+       # now spawn pager
+       export LESS="${LESS:-FRSX}"     # as in pager.c:pager_preexec()
+
+       _pager_fifo_dir="$(gen_tempfile -d)"
+       _pager_fifo="$_pager_fifo_dir/0"
+       mkfifo -m 600 "$_pager_fifo"
+
+       "$QUILT_PAGER" < "$_pager_fifo" &
+       exec > "$_pager_fifo"           # dup2(pager_fifo.in, 1)
+
+       # atexit(close(1); wait pager)
+       add_exit_handler "exec >&-; rm \"$_pager_fifo\"; rmdir 
\"$_pager_fifo_dir\"; wait"
+}
+
 #
 # If the working directory does not contain a $QUILT_PATCHES directory,
 # quilt searches for its base directory up the directory tree. If no
diff --git a/quilt/series.in b/quilt/series.in
index c3e6d25..f2fee9e 100644
--- a/quilt/series.in
+++ b/quilt/series.in
@@ -86,6 +86,8 @@ then
        usage
 fi
 
+setup_pager
+
 if [ -n "$opt_verbose$opt_color" ]
 then
        [ -n "$opt_color" ] && setup_colors
diff --git a/quilt/unapplied.in b/quilt/unapplied.in
index 6d0703c..5678595 100644
--- a/quilt/unapplied.in
+++ b/quilt/unapplied.in
@@ -65,6 +65,8 @@ else
        patch=$(find_unapplied_patch) || exit 1
 fi
 
+setup_pager
+
 (
        echo "$patch"
        patches_after "$patch"
-- 
tg: (e423f7e..) bw/pager (depends on: bw/exit-handler)




reply via email to

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