{"thread":{"id":"1176","subject":"New script: cg-clean","startedAt":"2005-07-08T22:34:44Z","lastAt":"2005-08-12T03:59:00Z","messageCount":8,"participants":["Pavel Roskin","Wolfgang Denk","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"5835","messageId":"1120862084.17812.6.camel@dv","threadId":"1176","inReplyTo":null,"subject":"New script: cg-clean","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-07-08T22:34:44Z","receivedAt":"2005-07-08T22:34:44Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello, Petr!\n\nPlease consider this script for Cogito.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\n#!/usr/bin/env bash\n#\n# Clean unknown files from the working tree.\n# Copyright (c) Pavel Roskin, 2005\n#\n# Cleans file and directories that are not under version control.\n# Only regular files that are not ignored by cg-status are cleaned\n# by default.\n#\n# OPTIONS\n# -------\n# -i::\n#\tClean files ignored by cg-status, such as object files.\n#\n# -s::\n#\tClean symlinks, fifos, sockets and other special files.\n#\n# -r::\n#\tClean directories.\n#\n# -R::\n#\tClean directories, try harder.  Make directories writeable\n#\trecursively before removing.\n#\n# -a::\n#\tClean all the above.\n#\n# If any other arguments are specified, they will be the only files\n# considered for removal.  It will also imply the `-a' option.\n\nUSAGE=\"cg-clean [-i] [-s] [-r] [-R] [-a] [FILE]...\"\n\n. ${COGITO_LIB}cg-Xlib\n\ncleanexclude=\ncleanspecial=\ncleandir=\ncleandirhard=\nwhile optparse; do\n\tif optparse -i; then\n\t\tcleanexclude=1\n\telif optparse -s; then\n\t\tcleanspecial=1\n\telif optparse -r; then\n\t\tcleandir=1\n\telif optparse -R; then\n\t\tcleandirhard=1\n\telif optparse -a; then\n\t\tcleanexclude=1\n\t\tcleandirhard=1\n\telse\n\t\toptfail\n\tfi\ndone\n\nif [ \"$ARGS\" ]; then\n\tcleanexclude=1\n\tcleandirhard=1\nfi\n\n# Good candidate for cg-Xlib\n# Put exclude options for git-ls-files to EXCLUDE\nset_exclude() {\n\tstdignores=('*.[ao]' '.*' tags '*~' '#*' ',,merge*')\n\tfor ign in \"${stdignores[@]}\"; do\n\t\tEXCLUDE=\"$EXCLUDE --exclude=$ign\"\n\tdone\n\n\tEXCLUDEFILE=$_git/exclude\n\tif [ -f \"$EXCLUDEFILE\" ]; then\n\t\tEXCLUDE=\"$EXCLUDE --exclude-from=$EXCLUDEFILE\"\n\tfi\n}\n\nEXCLUDE=\nif [ -z \"$cleanexclude\" ]; then\n\tset_exclude\nfi\t\n\ngit-update-cache --refresh > /dev/null\n\ndo_clean() {\n\t# FIXME - very suboptimal\n\tif [ \"$ARGS\" ]; then\n\t\tlocal found=\n\t\tfor arg in \"${ARGS[@]}\"; do\n\t\t\tif [ \"$arg\" = \"$file\" ]; then\n\t\t\t\tfound=1\n\t\t\t\tbreak\n\t\t\tfi\n\t\tdone\n\t\t[ \"$found\" ] || return\n\tfi\n\n\tif [ \"$cleandirhard\" ]; then\n\t\tchmod -R 700 \"$file\"\n\t\trm -rf \"$file\"\n\t\treturn\n\tfi\n\n\tif [ \"$cleandir\" ]; then\n\t\trm -rf \"$file\"\n\t\treturn\n\tfi\n\n\tif [ \"$cleanspecial\" ]; then\n\t\t[ -d \"$file\" ] && return\n\t\trm -f \"$file\"\n\t\treturn\n\tfi\n\n\t[ -f \"$file\" ] && rm -f \"$file\"\n}\n\n# Need to use temporary file so that changing IFS doesn't affect $EXCLUDE\n# expansion.\nfilelist=$(mktemp -t gitlsfiles.XXXXXX)\ngit-ls-files --others $EXCLUDE >\"$filelist\"\nIFS=$'\\n'\nfor file in $(cat \"$filelist\"); do\n\tdo_clean \"$file\"\ndone\n\nrm -f \"$filelist\"\n\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"5837","messageId":"20050708225959.5BCA13539FE@atlas.denx.de","threadId":"1176","inReplyTo":"1120862084.17812.6.camel@dv","subject":"Re: New script: cg-clean","fromName":"Wolfgang Denk","fromEmail":"wd@denx.de","sentAt":"2005-07-08T22:59:59Z","receivedAt":"2005-07-08T22:59:59Z","isPatch":false,"sender":{"key":"wd@denx.de","avatar":null},"body":"In message <1120862084.17812.6.camel@dv> Pavel Roskin wrote:\n> \n> Please consider this script for Cogito.\n...\n> # OPTIONS\n> # -------\n> # -i::\n> #\tClean files ignored by cg-status, such as object files.\n\nMay I suggest to give \"-i\" the standard \"--interactive\" meaning\n(= prompt before removal) like with \"rm\" etc. ?\n\nThanks.\n\n\nWolfgang Denk\n\n-- \nSoftware Engineering:  Embedded and Realtime Systems,  Embedded Linux\nPhone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de\nHow come everyone's going so slow if it's called rush hour?\n"},{"id":"5896","messageId":"20050710154618.GF24249@pasky.ji.cz","threadId":"1176","inReplyTo":"1120862084.17812.6.camel@dv","subject":"Re: New script: cg-clean","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-07-10T15:46:18Z","receivedAt":"2005-07-10T15:46:18Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jul 09, 2005 at 12:34:44AM CEST, I got a letter\nwhere Pavel Roskin <proski@gnu.org> told me that...\n> Hello, Petr!\n\nHello,\n\n> Please consider this script for Cogito.\n> \n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n\nthe script is definitively interesting, but I have couple of notes\nabout it first:\n\n(i) -i sounds wrong for anything but being interactive here ;-) What\nabout -A?\n\n(ii) I'm confused - if -a is all of the above, how do I clean _only_\nregular files, and only those not ignored by cg-status?\n\n(iii) Makes it any sense to remove only special files?\n\n(iv) -r implies being recursive, but it has nothing to do with that\nhere.\n\n(v) Semantically, I think it's quite close to cg-reset. What about\nmaking it part of cg-reset instead of a separate command? I tend to be\ncareful about command inflation. (That's part of being careful about the\nusability in general.) That's just an idea and possibly a bad one, what\ndo you think?\n\nThanks,\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n<Espy> be careful, some twit might quote you out of context..\n"},{"id":"6874","messageId":"1123312443.17959.34.camel@dv.roinet.com","threadId":"1176","inReplyTo":"20050710154618.GF24249@pasky.ji.cz","subject":"Re: New script: cg-clean","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-08-06T07:14:03Z","receivedAt":"2005-08-06T07:14:03Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello, Petr!\n\nSorry for delay.\n\nOn Sun, 2005-07-10 at 17:46 +0200, Petr Baudis wrote:\n> Dear diary, on Sat, Jul 09, 2005 at 12:34:44AM CEST, I got a letter\n> where Pavel Roskin <proski@gnu.org> told me that...\n> > Hello, Petr!\n> \n> Hello,\n> \n> > Please consider this script for Cogito.\n> > \n> > Signed-off-by: Pavel Roskin <proski@gnu.org>\n> \n> the script is definitively interesting, but I have couple of notes\n> about it first:\n> \n> (i) -i sounds wrong for anything but being interactive here ;-) What\n> about -A?\n\nI agree that -i could be confusing, but -A would seem to imply \"All\", so\nlet it be -x from \"exclude\".\n\n> (ii) I'm confused - if -a is all of the above, how do I clean _only_\n> regular files, and only those not ignored by cg-status?\n\ncg-clean without options.  I'm changing the description to avoid\nconfusion.\n\n> (iii) Makes it any sense to remove only special files?\n\nI thought it would make sense to have an option to remove them in\naddition to regular files, but now I think it's not worth the trouble to\ndistinguish between them.\n\n> (iv) -r implies being recursive, but it has nothing to do with that\n> here.\n\nRenamed to -d.  Other confusing options have been removed.  \"-a\" is\nretired because it's not hard to type \"-dx\".  Explicit arguments are not\naccepted - one can easily use \"rm\" instead.  That should make cg-clean\nmuch simpler.\n\n> (v) Semantically, I think it's quite close to cg-reset. What about\n> making it part of cg-reset instead of a separate command? I tend to be\n> careful about command inflation. (That's part of being careful about the\n> usability in general.) That's just an idea and possibly a bad one, what\n> do you think?\n\nI understand your concern, but cg-reset does other things.  cg-reset\nchanges the branch.  cg-clean allows to start the build from scratch\nwithout changing the branch.\n\nIt's not uncommon for me to revert patches one-by-one looking for the\npatch that breaks something.  I could make minor changes e.g for\ndebugging or to fix breakage in certain revisions.  I would revert such\nby cg-clean before going to another revision.  cg-reset would be an\noverkill - it would move me to the latest release.\n\nI can imagine that cg-reset would call cg-clean (optionally) to allow\nfresh start on the main branch.  The opposite would be wrong.\n\nHere's the simplified cg-clean script.  Note that the \"-d\" option is not\nworking with the current version of git of a bug in git-ls-files.  I can\nwork it around by scanning all directories in bash, but I think it's\neasier to fix git (remove \"continue\" before DT_REG in ls-files.c).\n\nProcessing of .gitignore was taken from cg-status, and I don't really\nunderstand it.  But I think it's important to keep that code in sync.\nIt could later go to cg-Xlib.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\n#!/usr/bin/env bash\n#\n# Clean unknown files from the working tree.\n# Copyright (c) Pavel Roskin, 2005\n#\n# Cleans file and directories that are not under version control.\n# When run without arguments, files ignored by cg-status and directories\n# are not removed.\n#\n# OPTIONS\n# -------\n# -d::\n#\tAlso clean directories.\n#\n# -x::\n#\tAlso clean files ignored by cg-status, such as object files.\n\nUSAGE=\"cg-clean [-d] [-x]\"\n\n. ${COGITO_LIB}cg-Xlib\n\ncleanexclude=\ncleandir=\nwhile optparse; do\n\tif optparse -d; then\n\t\tcleandir=1\n\telif optparse -x; then\n\t\tcleanexclude=1\n\telse\n\t\toptfail\n\tfi\ndone\n\n# Good candidate for cg-Xlib\n# Put exclude options for git-ls-files to EXCLUDE\nset_exclude() {\n\tEXCLUDE=\n\n\tstdignores=('*.[ao]' '.*' tags '*~' '#*' ',,merge*')\n\tfor ign in \"${stdignores[@]}\"; do\n\t\tEXCLUDE=\"$EXCLUDE --exclude=$ign\"\n\tdone\n\n\tEXCLUDEFILE=$_git/exclude\n\tif [ -f \"$EXCLUDEFILE\" ]; then\n\t\tEXCLUDE=\"$EXCLUDE --exclude-from=$EXCLUDEFILE\"\n\tfi\n\n\t{\n\t\tpath=\"$_git_relpath\"\n\t\tdir=\n\t\t[ -r .gitignore ] && EXCLUDE=\"$EXCLUDE --exclude-from=.gitignore\"\n\t\twhile [[ \"$path\" == */* ]]; do\n\t\t\tdir=\"${dir:-.}/${path%%/*}\"\n\t\t\tpath=\"${path#*/}\"\n\t\t\t[ -r $dir/.gitignore ] && EXCLUDE=\"$EXCLUDE --exclude-from=$dir/.gitignore\"\n\t\tdone\n\t}\n}\n\nif [ -z \"$cleanexclude\" ]; then\n\tset_exclude\nelse\n\tEXCLUDE=\nfi\t\n\ngit-update-cache --refresh > /dev/null\n\n# Need to use temporary file so that changing IFS doesn't affect $EXCLUDE\n# expansion.\nfilelist=$(mktemp -t gitlsfiles.XXXXXX)\ngit-ls-files --others $EXCLUDE >\"$filelist\"\nsave_IFS=\"$IFS\"\nIFS=$'\\n'\nfor file in $(cat \"$filelist\"); do\n\tIFS=\"$save_IFS\"\n\tif [ -d \"$file\" ]; then\n\t\tif [ \"$cleandir\" ]; then\n\t\t\t# Try really hard by changing permissions\n\t\t\tchmod -R 700 \"$file\"\n\t\t\trm -rf \"$file\"\n\t\tfi\n\t\treturn\n\tfi\n\trm -f \"$file\"\ndone\n\nrm -f \"$filelist\"\n\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"7091","messageId":"20050811232925.GK25280@pasky.ji.cz","threadId":"1176","inReplyTo":"1123312443.17959.34.camel@dv.roinet.com","subject":"Re: New script: cg-clean","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-08-11T23:29:26Z","receivedAt":"2005-08-11T23:29:26Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Aug 06, 2005 at 09:14:03AM CEST, I got a letter\nwhere Pavel Roskin <proski@gnu.org> told me that...\n> Hello, Petr!\n\nHello,\n\n> Sorry for delay.\n\nno problem, and sorry for another delay on my side too. :-)\n\n> On Sun, 2005-07-10 at 17:46 +0200, Petr Baudis wrote:\n> > (v) Semantically, I think it's quite close to cg-reset. What about\n> > making it part of cg-reset instead of a separate command? I tend to be\n> > careful about command inflation. (That's part of being careful about the\n> > usability in general.) That's just an idea and possibly a bad one, what\n> > do you think?\n> \n> I understand your concern, but cg-reset does other things.  cg-reset\n> changes the branch.  cg-clean allows to start the build from scratch\n> without changing the branch.\n> \n> It's not uncommon for me to revert patches one-by-one looking for the\n> patch that breaks something.  I could make minor changes e.g for\n> debugging or to fix breakage in certain revisions.  I would revert such\n> by cg-clean before going to another revision.  cg-reset would be an\n> overkill - it would move me to the latest release.\n> \n> I can imagine that cg-reset would call cg-clean (optionally) to allow\n> fresh start on the main branch.  The opposite would be wrong.\n\nYes, that makes sense.\n\n> Here's the simplified cg-clean script.  Note that the \"-d\" option is not\n> working with the current version of git of a bug in git-ls-files.  I can\n> work it around by scanning all directories in bash, but I think it's\n> easier to fix git (remove \"continue\" before DT_REG in ls-files.c).\n\nIs that fixed already?\n\n> Processing of .gitignore was taken from cg-status, and I don't really\n> understand it.  But I think it's important to keep that code in sync.\n> It could later go to cg-Xlib.\n\nIt became much simpler a short while later, thankfully. Judging from\nyour another patch, I suppose you are going to update this script\naccordingly?\n\n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n> \n> #!/usr/bin/env bash\n> #\n> # Clean unknown files from the working tree.\n> # Copyright (c) Pavel Roskin, 2005\n> #\n> # Cleans file and directories that are not under version control.\n> # When run without arguments, files ignored by cg-status and directories\n> # are not removed.\n> #\n> # OPTIONS\n> # -------\n> # -d::\n> #\tAlso clean directories.\n\nPerhaps add \"and their contents\" to prevent bad surprises.\n\n> #\n> # -x::\n> #\tAlso clean files ignored by cg-status, such as object files.\n> \n> USAGE=\"cg-clean [-d] [-x]\"\n> \n> . ${COGITO_LIB}cg-Xlib\n> \n> cleanexclude=\n> cleandir=\n> while optparse; do\n> \tif optparse -d; then\n> \t\tcleandir=1\n> \telif optparse -x; then\n> \t\tcleanexclude=1\n> \telse\n> \t\toptfail\n> \tfi\n> done\n> \n> # Good candidate for cg-Xlib\n> # Put exclude options for git-ls-files to EXCLUDE\n..snip..\n> \n> git-update-cache --refresh > /dev/null\n> \n> # Need to use temporary file so that changing IFS doesn't affect $EXCLUDE\n> # expansion.\n> filelist=$(mktemp -t gitlsfiles.XXXXXX)\n> git-ls-files --others $EXCLUDE >\"$filelist\"\n> save_IFS=\"$IFS\"\n> IFS=$'\\n'\n> for file in $(cat \"$filelist\"); do\n\nWhy can't you use git-ls-files | IFS=$'\\n' while ?\n\n> \tIFS=\"$save_IFS\"\n> \tif [ -d \"$file\" ]; then\n> \t\tif [ \"$cleandir\" ]; then\n> \t\t\t# Try really hard by changing permissions\n> \t\t\tchmod -R 700 \"$file\"\n> \t\t\trm -rf \"$file\"\n> \t\tfi\n\nAn error message would be in order otherwise, I guess.\n\n> \t\treturn\n\nI suppose you mean continue? I'm not really sure what does return do\nhere, if it jumps out of the do block or what, and continue is nicely\nexplicit. :-)\n\n> \tfi\n> \trm -f \"$file\"\n> done\n> \n> rm -f \"$filelist\"\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nIf you want the holes in your knowledge showing up try teaching\nsomeone.  -- Alan Cox\n"},{"id":"7095","messageId":"1123808053.4248.47.camel@dv","threadId":"1176","inReplyTo":"20050811232925.GK25280@pasky.ji.cz","subject":"Re: New script: cg-clean","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-08-12T00:54:13Z","receivedAt":"2005-08-12T00:54:13Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hi, Petr!\n\nUnfortunately, my latest revision of cg-clean has \"committed suicide\"\njust when I was about to post it.  Anyway, I would prefer to wait until\nyou apply my patch to cg-status to ignore all ignores.  That would allow\nme to reuse cg-status.\n\nOn Fri, 2005-08-12 at 01:29 +0200, Petr Baudis wrote:\n> > Here's the simplified cg-clean script.  Note that the \"-d\" option is not\n> > working with the current version of git of a bug in git-ls-files.  I can\n> > work it around by scanning all directories in bash, but I think it's\n> > easier to fix git (remove \"continue\" before DT_REG in ls-files.c).\n> \n> Is that fixed already?\n\nIt turn out it's quite tricky.  git-ls-files doesn't distinguish between\nknown and unknown directories.  One way to do it would be to check all\ncached files and find all directories they are in.  Another approach\nwould involve \"git-ls-tree -r\", but I don't think it would be right\nbecause we work with cache and current files, not with committed data\n(but my knowledge is limited to make a call - I still need to read the\ndocumentation about git).\n\nWhat I did was following:\n\n\"git-ls-files --cached\" is run, directories are extracted, sorted but\n\"sort -u\" and put to a temporary file dirlist1.  \"find -type d\" is run,\n\".git\" is filtered out, the list is merged with dirlist1, sorted by\n\"sort -u\", and put to dirlist2.  dirlist1 and dirlist2 are compared by\ndiff, the entries in dirlist2 are unknown directories.  (That's the kind\nof task where Perl hashes would be great).  A technical detail - both\nlists are limited to $_git_relpath if it's defined.\n\n> > Processing of .gitignore was taken from cg-status, and I don't really\n> > understand it.  But I think it's important to keep that code in sync.\n> > It could later go to cg-Xlib.\n> \n> It became much simpler a short while later, thankfully. Judging from\n> your another patch, I suppose you are going to update this script\n> accordingly?\n\nYes, I'm going to use \"cg-status -w\" for files.\n\n> > # -d::\n> > #\tAlso clean directories.\n> \n> Perhaps add \"and their contents\" to prevent bad surprises.\n\nToo late :-)\n\n> > filelist=$(mktemp -t gitlsfiles.XXXXXX)\n> > git-ls-files --others $EXCLUDE >\"$filelist\"\n> > save_IFS=\"$IFS\"\n> > IFS=$'\\n'\n> > for file in $(cat \"$filelist\"); do\n> \n> Why can't you use git-ls-files | IFS=$'\\n' while ?\n\nGood idea.\n\n> > \tIFS=\"$save_IFS\"\n> > \tif [ -d \"$file\" ]; then\n> > \t\tif [ \"$cleandir\" ]; then\n> > \t\t\t# Try really hard by changing permissions\n> > \t\t\tchmod -R 700 \"$file\"\n> > \t\t\trm -rf \"$file\"\n> > \t\tfi\n> \n> An error message would be in order otherwise, I guess.\n\nYou mean, list directories if \"-d\" is not specified?  Good idea.  Also,\nthe latest revision included the \"-v\" option for \"verbose\" - it would\nshow everything that gets deleted.\n\n> > \t\treturn\n> \n> I suppose you mean continue? I'm not really sure what does return do\n> here, if it jumps out of the do block or what, and continue is nicely\n> explicit. :-)\n\nMy error, it was fixed soon after I posted the script.\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"7096","messageId":"20050812010811.GM25280@pasky.ji.cz","threadId":"1176","inReplyTo":"1123808053.4248.47.camel@dv","subject":"Re: New script: cg-clean","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-08-12T01:08:11Z","receivedAt":"2005-08-12T01:08:11Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Fri, Aug 12, 2005 at 02:54:13AM CEST, I got a letter\nwhere Pavel Roskin <proski@gnu.org> told me that...\n> Hi, Petr!\n\nHi,\n\n> Unfortunately, my latest revision of cg-clean has \"committed suicide\"\n> just when I was about to post it.  Anyway, I would prefer to wait until\n> you apply my patch to cg-status to ignore all ignores.  That would allow\n> me to reuse cg-status.\n\nwell, I did quite a while ago. Unless the kernel.org mirroring system\nbroke, it should be already public.\n\n> On Fri, 2005-08-12 at 01:29 +0200, Petr Baudis wrote:\n> > > Here's the simplified cg-clean script.  Note that the \"-d\" option is not\n> > > working with the current version of git of a bug in git-ls-files.  I can\n> > > work it around by scanning all directories in bash, but I think it's\n> > > easier to fix git (remove \"continue\" before DT_REG in ls-files.c).\n> > \n> > Is that fixed already?\n> \n> It turn out it's quite tricky.  git-ls-files doesn't distinguish between\n> known and unknown directories.\n\nIn the long term, I would prefer to have directory information in the\nindex file - to make this kind of tasks easier, allow juggling with\nempty directories etc.\n\n> One way to do it would be to check all\n> cached files and find all directories they are in.  Another approach\n> would involve \"git-ls-tree -r\", but I don't think it would be right\n> because we work with cache and current files, not with committed data\n> (but my knowledge is limited to make a call - I still need to read the\n> documentation about git).\n\nYes, we should certainly follow the index, otherwise you will e.g. lose\nthe files added by cg-add but not committed yet.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nIf you want the holes in your knowledge showing up try teaching\nsomeone.  -- Alan Cox\n"},{"id":"7103","messageId":"1123819140.4248.55.camel@dv","threadId":"1176","inReplyTo":"20050812010811.GM25280@pasky.ji.cz","subject":"Re: New script: cg-clean","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-08-12T03:59:00Z","receivedAt":"2005-08-12T03:59:00Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Fri, 2005-08-12 at 03:08 +0200, Petr Baudis wrote:\n> Dear diary, on Fri, Aug 12, 2005 at 02:54:13AM CEST, I got a letter\n> where Pavel Roskin <proski@gnu.org> told me that...\n> > Hi, Petr!\n> \n> Hi,\n> \n> > Unfortunately, my latest revision of cg-clean has \"committed suicide\"\n> > just when I was about to post it.  Anyway, I would prefer to wait until\n> > you apply my patch to cg-status to ignore all ignores.  That would allow\n> > me to reuse cg-status.\n> \n> well, I did quite a while ago. Unless the kernel.org mirroring system\n> broke, it should be already public.\n\nYes, it's there.  Thank you.\n\nThis is another attempt at cg-clean.  Verbose mode is now default (i.e.\neverything that's removed is reported), \"-q\" makes the script quiet.\nI've reinstated the \"hard\" option, it's now \"-D\".\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\n#!/usr/bin/env bash\n#\n# Clean unknown files from the working tree.\n# Copyright (c) Pavel Roskin, 2005\n#\n# Cleans file and directories that are not under version control.\n# When run without arguments, files ignored by cg-status and directories\n# are not removed.\n#\n# OPTIONS\n# -------\n# -d::\n#\tAlso clean directories and their contents.\n#\n# -D::\n#\tSame as -d but try harder (change permissions first).\n#\n# -q::\n#\tQuiet - don't report what's being cleaned.\n#\n# -x::\n#\tAlso clean files ignored by cg-status, such as object files.\n\nUSAGE=\"cg-clean [-d] [-D] [-q] [-x]\"\n\n. ${COGITO_LIB}cg-Xlib || exit 1\n\nnoexclude=\ncleandir=\ncleandirhard=\nquiet=\nwhile optparse; do\n\tif optparse -d; then\n\t\tcleandir=1\n\telif optparse -D; then\n\t\tcleandir=1\n\t\tcleandirhard=1\n\telif optparse -q; then\n\t\tquiet=1\n\telif optparse -x; then\n\t\tnoexclude=1\n\telse\n\t\toptfail\n\tfi\ndone\n\n[ \"$ARGS\" ] && usage\n\nclean_dirs()\n{\n\tdirlist=$(mktemp -t gitlsfiles.XXXXXX)\n\tgit-ls-files --cached | sed -n 's|^'\"$_git_relpath\"'||p' |\n\tsed -n 's|/[^/]*$||p' | sort -u >\"$dirlist\"\n\n\tsave_IFS=\"$IFS\"\n\tIFS=$'\\n'\n\n\tfpath=${_git_relpath-./}\n\tfind \"$fpath\" -type d -print | \\\n\tsed 's|^'\"$fpath\"'||;/^$/d;/^\\.git$/d;/^\\.git\\//d' |\n\tcat - \"$dirlist\" | sort -u | diff - \"$dirlist\" |\n\tsed -n 's/< //p' |\n\n\tfor file in $(cat); do\n\t\tpath=\"${_git_relpath}$file\"\n\t\tif [ -z \"$cleandir\" ]; then\n\t\t\techo \"Not removing $file/\"\n\t\t\tcontinue\n\t\tfi\n\t\tif [ ! -d \"$path\" ]; then\n\t\t\t# Perhaps directory was removed with its parent\n\t\t\tcontinue\n\t\tfi\n\t\t[ \"$quiet\" ] || echo \"Removing $file/\"\n\t\tif [ \"$cleandirhard\" ]; then\n\t\t\tchmod -R 700 \"$path\"\n\t\tfi\n\t\trm -rf \"$path\"\n\t\tif [ -e \"$path\" -o -L \"$path\" ]; then\n\t\t\techo \"Cannot remove $file/\"\n\t\tfi\n\tdone\n\n\tIFS=\"$save_IFS\"\n\trm -f \"$dirlist\"\n}\n\nclean_files()\n{\n\txopt=\n\tif [ \"$noexclude\" ]; then\n\t\txopt=\"-x\"\n\tfi\n\n\tsave_IFS=\"$IFS\"\n\tIFS=$'\\n'\n\n\tcg-status \"$xopt\" -w | sed -n 's/^? //p' |\n\tfor file in $(cat); do\n\t\tpath=\"${_git_relpath}$file\"\n\t\tif [ -d \"$path\" ]; then\n\t\t\t# Sanity check, shouldn't happen\n\t\t\techo \"FATAL: cg-status reports directories\" >&2\n\t\t\texit 1\n\t\telif [ -e \"$path\" -o -L \"$path\" ]; then\n\t\t\t[ \"$quiet\" ] || echo \"Removing $file\"\n\t\t\trm -f \"$path\"\n\t\t\tif [ -e \"$path\" -o -L \"$path\" ]; then\n\t\t\t\techo \"Cannot remove $file\"\n\t\t\tfi\n\t\telse\n\t\t\techo \"File $file has disappeared!\"\n\t\tfi\n\tdone\n\n\tIFS=\"$save_IFS\"\n}\n\n# Even if -d or -D is not specified, we want to tell user about\n# directories that are not removed\nif [ -z \"$quiet\" -o \"$cleandir\" ]; then\n\tclean_dirs\nfi\n\nclean_files\n\n\n\n-- \nRegards,\nPavel Roskin\n"}]}