# [PATCH UPDATED] cg-commit chokes when given a very large list of files

1 messages from 2005-07-18 to 2005-07-18. Participants: Bryan Larsen.
Thread: https://gitlist.dev/t/1272

## Bryan Larsen, 2005-07-18 04:37

Subject: [PATCH UPDATED] cg-commit chokes when given a very large list of files
Message-ID: <20050718043713.22322.21445.sendpatchset@bryan-larsens-ibook-g4.local>
URL: https://gitlist.dev/e/20050718043713.22322.21445.sendpatchset%40bryan-larsens-ibook-g4.local

```
cg-commit currently chokes when passed a very large list of files.  Fix it.

Resent again.  This time we completely avoid messing with IFS, resulting 
in support for filenames with line feeds.

Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
---

 cg-Xlib   |   18 ++++++++++++++++++
 cg-commit |    6 +++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -49,6 +49,24 @@ mktemp () {
 	$(which mktemp) $dirarg $prefix"$1"
 }
 
+
+# this function is useful when you want to execute a command that's bigger
+# than the system's limit.
+#
+# this is similar to piping output to xargs -0r
+# 
+# example usage:  eval_via_xargs "git-update-cache --add --" "$@"
+eval_via_xargs () {
+    local cmd=$1
+    shift
+    if [ "$1" ] ; then	
+	( for f in "$@" ; do
+	    echo -ne ${f}\\000
+	done ) | xargs -0 $cmd
+    fi
+}
+
+
 stat () {
 	if [ "$1" != "-c" ] || [ "$2" != "%s" ]; then
 		echo "INTERNAL ERROR: Unsupported stat call $@" >&2
diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -289,9 +289,9 @@ precommit_update () {
 		eval "queue$op[\${#queue$op[@]}]=\"\$fname\""
 	done
 	# XXX: Do we even need to do the --add and --remove update-caches?
-	[ "$queueN" ] && { git-update-cache --add ${infoonly} -- "${queueN[@]}" || return 1; }
-	[ "$queueD" ] && { git-update-cache --force-remove -- "${queueD[@]}" || return 1; }
-	[ "$queueM" ] && { git-update-cache ${infoonly} -- "${queueM[@]}" || return 1; }
+	eval_via_xargs "git-update-cache --add ${infoonly} --" "${queueN[@]}" || return 1
+	eval_via_xargs "git-update-cache --force-remove --" "${queueD[@]}" || return 1
+	eval_via_xargs "git-update-cache ${infoonly} --" "${queueM[@]}" || return 1
 	return 0
 }
 

```
