git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make cg-status report added/removed files correctly

From
Dan Holmsand <holmsand@gmail.com>
Date
May 29, 2005, 22:11 UTC
Message-ID
<d7deh7$sbk$1@sea.gmane.org>

cg-status presently only cares about the cache (by parsing the output of git-update-cache and git-ls-files), when it should look at the tree in HEAD.

This patch fixes this, by using git-diff-cache HEAD instead (using git-diff-files only to detect the difference between missing files and cg-rm'd ones).

It also uses the exclusion mechanism in git-ls-files, instead of parsing git-ls-files output, and adds '*~' and '#*' to the list of patterns excluded by default.

Signed-off-by: Dan Holmsand <holmsand@gmail.com>
diff --git a/cg-status b/cg-status
--- a/cg-status
+++ b/cg-status
@@ -7,33 +7,24 @@
 
 . ${COGITO_LIB}cg-Xlib
 
+[ 0 -eq $# ] || die "no arguments allowed"
+
 EXCLUDEFILE=$_git/exclude
 EXCLUDE=
 if [ -f $EXCLUDEFILE ]; then
 	EXCLUDE="--exclude-from=$EXCLUDEFILE"
 fi
 
-{
-	git-ls-files -z -t --others --deleted --unmerged $EXCLUDE
-} | sort -z -k 2 | xargs -0 sh -c '
-while [ "$1" ]; do
-	tag=${1% *};
-	filename=${1#* };
-	case "$filename" in
-	*.[ao] | tags | ,,merge*) ;;
-	*)   echo "$tag $filename";;
-	esac
-	shift
-done
-' padding
+git-update-cache --refresh > /dev/null
+
+git-ls-files --others --exclude='*.[ao]' --exclude='.*' --exclude=tags \
+	--exclude='*~' --exclude='#*' \
+	--exclude=',,merge*' $EXCLUDE | sed 's,^,? ,'
 
-{
-	git-update-cache --refresh
-} | cut -f 1 -d ":" | xargs sh -c '
-while [ "$1" ]; do
-	tag="M";
-	filename=${1%: *};
-	echo "$tag $filename";
-	shift
+git-diff-cache HEAD | cut -f5- -d' ' | 
+while IFS=$'\t' read -r mode file; do
+	if [ "$mode" = D ]; then
+		[ "$(git-diff-files "$file")" ] && mode=!
+	fi
+	echo "$mode $file"
 done
-' padding
Message 1 of 1 in “Make cg-status report added/removed files correctly”
  1. Make cg-status report added/removed files correctlyDan Holmsand, May 29, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.