threads / patch / 319

patchcogito recursive cg-add and cg-rm

Subject: [PATCH] cogito recursive cg-add and cg-rm

## tl;dr

4 messages between Apr 26, 2005 and Apr 26, 2005. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Joshua T. Corbin· Apr 26, 2005, 04:27 UTC · lore

This patch adds recursive addition and removal to cg-add and cg-rm, recursion can be disabled with the -n switch.

Signed-off-by: Joshua T. Corbin <jcorbin@wunjo.org>
Show changes to diff +55 −7
Index: cg-add
===================================================================
--- f262000f302b749e485f5eb971e6aabefbb85680/cg-add  (mode:100755 
sha1:8ba5351a4c7e28a577ea1aa4afa1078c54e9bccc)
+++ ddd5e0ab084034b713bb2f7d9de6f365d5a2e5bf/cg-add  (mode:100755 
sha1:1b7a821fd0b3f9702508503a082869ed4ec3ab52)
@@ -5,9 +5,31 @@
 #
 # Takes a list of file names at the command line, and schedules them
 # for addition to the GIT repository at the next commit.
+# Optional "-n" parameter specifies that you don't want to add directories
+# recursively.
 
 . cg-Xlib
 
-[ "$1" ] || die "usage: cg-add FILE..."
+[ "$1" ] || die "usage: cg-add [-n] FILE..."
 
-update-cache --add -- "$@"
+recur=1
+if [ "$1" = "-n" ]; then
+  shift
+  recur=
+fi
+
+if [ $recur ]; then
+  ADDFILE=$(mktemp -t gitadd.XXXXXX)
+  while [ "$1" ]; do
+    if [ -d "$1" ]; then
+      find $1 -type f -and -not -name '.*'
+    else
+      echo "$1"
+    fi
+    shift
+  done > $ADDFILE
+  update-cache --add -- $(cat $ADDFILE)
+  rm -f $RMFILE
+else
+  update-cache --add -- "$@"
+fi
Index: cg-help
===================================================================
--- f262000f302b749e485f5eb971e6aabefbb85680/cg-help  (mode:100755 
sha1:86f29161aadf15411244db9514a1fdfb03e664bd)
+++ ddd5e0ab084034b713bb2f7d9de6f365d5a2e5bf/cg-help  (mode:100755 
sha1:36480174eba9cc54e9baba100cbd368fbced5c76)
@@ -11,7 +11,7 @@
 Usage: cg-COMMAND [ARG]...
 
 Available commands:
- cg-add  FILE...
+ cg-add  [-n] FILE...
  cg-branch-add BNAME SOURCE_LOC
  cg-branch-ls
  cg-cancel
@@ -27,7 +27,7 @@
  cg-mkpatch [COMMIT_ID | COMMIT_ID:COMMIT_ID]
  cg-patch   < patch on stdin
  cg-pull  [BNAME]
- cg-rm  FILE...
+ cg-rm  [-n] FILE...
  cg-seek  [COMMIT_ID]
  cg-status
  cg-tag  TNAME [COMMIT_ID]
Index: cg-rm
===================================================================
--- f262000f302b749e485f5eb971e6aabefbb85680/cg-rm  (mode:100755 
sha1:029a03128eb7a8dd807335fea2ff52cb2bcda4fa)
+++ ddd5e0ab084034b713bb2f7d9de6f365d5a2e5bf/cg-rm  (mode:100755 
sha1:1e0c64567767668454a0360785ac84883c7bbd58)
@@ -5,10 +5,36 @@
 #
 # Takes a list of file names at the command line, and schedules them
 # for removal from the GIT repository at the next commit.
+# Optional "-n" parameter specifies that you don't want to remove directories
+# recursively.
 
 . cg-Xlib
 
-[ "$1" ] || die "usage: cg-rm FILE..."
+[ "$1" ] || die "usage: cg-rm [-n] FILE..."
 
-rm -f "$@"
-update-cache --remove -- "$@"
+recur=1
+if [ "$1" = "-n" ]; then
+  shift
+  recur=
+fi
+
+if [ $recur ]; then
+  RMFILE=$(mktemp -t gitrm.XXXXXX)
+  RMDIRS=
+  while [ "$1" ]; do
+    if [ -d "$1" ]; then
+      RMDIRS="$DIRS $1"
+      find $1 -type f -and -not -name '.*'
+    else
+      echo "$1"
+    fi
+    shift
+  done > $RMFILE
+  rm -f $(cat $RMFILE)
+  rmdir $(find $RMDIRS -depth -type d)
+  update-cache --remove -- $(cat $RMFILE)
+  rm -f $RMFILE
+else
+  rm -f "$@"
+  update-cache --remove -- "$@"
+fi
Joshua T. Corbin· Apr 26, 2005, 05:17 UTC · re: Joshua T. Corbin · lore

Re: [PATCH] cogito recursive cg-add and cg-rm

Small one line fix on top of the previos patch, apparently I was too hasty and didn't test cg-rm on a single file ;)

Signed-off-by: Joshua T. Corbin <jcorbin@wunjo.org>
Show changes to diff +1 −1
Index: cg-rm
===================================================================
--- bb131a04832677b22959ffe47f68900b94accc0c/cg-rm  (mode:100755 
sha1:f2d2e0c042fdf9496d53e833a50d960331e145b4)
+++ 5b396356f2c852f95a4226e955e186f46851a1f0/cg-rm  (mode:100755 
sha1:7701a83878c1e02dbce3abc0e3f1290c56c1be16)
@@ -40,7 +40,7 @@
     shift
   done > $RMFILE
   rm -f $(cat $RMFILE)
-  rmdir $(find $RMDIRS -depth -type d)
+  [ -n "$RMDIRS" ] && rmdir $(find $RMDIRS -depth -type d)
   update-cache --remove -- $(cat $RMFILE)
   rm -f $RMFILE
 else
Petr Baudis· Apr 26, 2005, 12:39 UTC · re: Joshua T. Corbin · lore

Re: [PATCH] cogito recursive cg-add and cg-rm

Dear diary, on Tue, Apr 26, 2005 at 06:27:02AM CEST, I got a letter where "Joshua T. Corbin" <jcorbin@wunjo.org> told me that...

> This patch adds recursive addition and removal to cg-add and cg-rm, recursion 
> can be disabled with the -n switch.
> 
> Signed-off-by: Joshua T. Corbin <jcorbin@wunjo.org>

I'd actually prefer -r to explicitly turn the recursion on. That is more consistent with the rest of the UNIX world and I really don't feel comfortable with cg-rm recursing by default. ;-)

Also please use tabs for indentation.
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Joshua T. Corbin· Apr 26, 2005, 13:21 UTC · re: Petr Baudis · lore

Re: [PATCH] cogito recursive cg-add and cg-rm

On 26 April 2005 08:39, Petr Baudis wrote:
Show 11 quoted lines
> Dear diary, on Tue, Apr 26, 2005 at 06:27:02AM CEST, I got a letter
> where "Joshua T. Corbin" <jcorbin@wunjo.org> told me that...
>
> > This patch adds recursive addition and removal to cg-add and cg-rm,
> > recursion can be disabled with the -n switch.
> >
> > Signed-off-by: Joshua T. Corbin <jcorbin@wunjo.org>
>
> I'd actually prefer -r to explicitly turn the recursion on. That is more
> consistent with the rest of the UNIX world and I really don't feel
> comfortable with cg-rm recursing by default. ;-)

Hmm, I guess for it to work the way I was inteding would take a little more work; it should bail if any of the files are not in the repository or are locally modified.

> Also please use tabs for indentation.
Will do
-- 
Regards,
Joshua T. Corbin <jcorbin@wunjo.org>

← back to recent threads