chiark / gitweb /
tg-files: list files changed by the topic branch
authorBert Wesarg <bert.wesarg@googlemail.com>
Mon, 4 Oct 2010 18:27:47 +0000 (20:27 +0200)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 2 Nov 2010 21:00:28 +0000 (22:00 +0100)
this could also be a --name-only option to tg-patch. But I like the
similarity to 'quilt files'.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
.gitignore
README
contrib/tg-completion.bash
tg-export.sh
tg-files.sh [new file with mode: 0644]
tg.sh

index 3298889ab3440fb7567ab56d298bceb083332fe2..2a4d16597b3883e5cf9dd2ecefe99c321f830242 100644 (file)
@@ -22,6 +22,8 @@
 /tg-depend.txt
 /tg-export
 /tg-export.txt
+/tg-files
+/tg-files.txt
 /tg-import
 /tg-import.txt
 /tg-info
diff --git a/README b/README
index 5ca042450a7028c5c28ebf8640793a28f48f36c8..266bf3c72e114befead0eb219541ed9c649931ae 100644 (file)
--- a/README
+++ b/README
@@ -272,6 +272,14 @@ tg depend
 
        TODO: Subcommand for removing dependencies, obviously
 
+tg files
+~~~~~~~~
+       List files changed by the current or specified topic branch.
+
+       Options:
+         -i            list files based on index instead of branch
+         -w            list files based on working tree instead of branch
+
 tg info
 ~~~~~~~
        Show a summary information about the current or specified
index ccf1a32751b0316c7ba193f7bd6cf3815cf96a5c..48e47c7047c3c7308cd10b5a0327a63e94cd6fb1 100755 (executable)
@@ -482,6 +482,7 @@ _tg ()
        delete)      _tg_delete ;;
        depend)      _tg_depend ;;
        export)      _tg_export ;;
+       files)       _tg_patch ;;
        help)        _tg_help ;;
        import)      _tg_import ;;
        info)        _tg_info ;;
index 6d82d55751bd41159f04f20f55b753baaec94c44..4b0148c1d7770eb5cb6f1e9fda1a5bf1e327afd1 100644 (file)
@@ -63,15 +63,6 @@ trap 'rm -rf "$playground"' EXIT
 
 ## Collapse driver
 
-# pretty_tree NAME
-# Output tree ID of a cleaned-up tree without tg's artifacts.
-pretty_tree()
-{
-       git ls-tree --full-tree "$1" \
-       | awk -F '      ' '$2 !~ /^.top/' \
-       | git mktree
-}
-
 create_tg_commit()
 {
        name="$1"
diff --git a/tg-files.sh b/tg-files.sh
new file mode 100644 (file)
index 0000000..b88940a
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# (c) Petr Baudis <pasky@suse.cz>  2008
+# GPLv2
+
+name=
+topic=
+
+
+## Parse options
+
+while [ -n "$1" ]; do
+       arg="$1"; shift
+       case "$arg" in
+       -i)
+               [ -z "$topic" ] || die "-i and -w are mutually exclusive"
+               topic=-i;;
+       -w)
+               [ -z "$topic" ] || die "-i and -w are mutually exclusive"
+               topic=-w;;
+       -*)
+               echo "Usage: tg [...] files [-i | -w] [NAME]" >&2
+               exit 1;;
+       *)
+               [ -z "$name" ] || die "name already specified ($name)"
+               name="$arg";;
+       esac
+done
+
+
+[ -n "$name" -a -n "$topic" ] &&
+       die "-i/-w are mutually exclusive with NAME"
+
+[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+       die "not a TopGit-controlled branch"
+
+b_tree=$(pretty_tree "$name" -b)
+t_tree=$(pretty_tree "$name" $topic)
+
+git diff-tree --name-only -r $b_tree $t_tree
+
+# vim:noet
diff --git a/tg.sh b/tg.sh
index 8264a3b074f1d6bbded09e8110f1c07be475ffdd..f1b323b7cbe543994f373523ab2b84b814fd0adc 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -37,6 +37,55 @@ cat_file()
        esac
 }
 
+# get tree for the committed topic
+get_tree_()
+{
+       echo "$1"
+}
+
+# get tree for the base
+get_tree_b()
+{
+       echo "refs/top-bases/$1"
+}
+
+# get tree for the index
+get_tree_i()
+{
+       git write-tree
+}
+
+# get tree for the worktree
+get_tree_w()
+{
+       i_tree=$(git write-tree)
+       (
+               # the file for --index-output needs to sit next to the
+               # current index file
+               : ${GIT_INDEX_FILE:="$git_dir/index"}
+               TMP_INDEX="$(mktemp "${GIT_INDEX_FILE}-tg.XXXXXX")"
+               git read-tree -m $i_tree --index-output="$TMP_INDEX" &&
+               GIT_INDEX_FILE="$TMP_INDEX" &&
+               export GIT_INDEX_FILE &&
+               git diff --name-only -z HEAD |
+                       git update-index -z --add --remove --stdin &&
+               git write-tree &&
+               rm -f "$TMP_INDEX"
+       )
+}
+
+# pretty_tree NAME [-b | -i | -w]
+# Output tree ID of a cleaned-up tree without tg's artifacts.
+# NAME will be ignored for -i and -w, but needs to be present
+pretty_tree()
+{
+       name=$1
+       source=${2#?}
+       git ls-tree --full-tree "$(get_tree_$source "$name")" |
+               awk -F '        ' '$2 !~ /^.top/' |
+               git mktree
+}
+
 # setup_hook NAME
 setup_hook()
 {