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

Re: New script: cg-clean

From
PRPavel Roskin <proski@gnu.org>
Date
Aug 12, 2005, 00:54 UTC
Message-ID
<1123808053.4248.47.camel@dv>
In-Reply-To
<20050811232925.GK25280@pasky.ji.cz>
Hi, Petr!

Unfortunately, my latest revision of cg-clean has "committed suicide" just when I was about to post it. Anyway, I would prefer to wait until you apply my patch to cg-status to ignore all ignores. That would allow me to reuse cg-status.

On Fri, 2005-08-12 at 01:29 +0200, Petr Baudis wrote:
Show 6 quoted lines
> > Here's the simplified cg-clean script.  Note that the "-d" option is not
> > working with the current version of git of a bug in git-ls-files.  I can
> > work it around by scanning all directories in bash, but I think it's
> > easier to fix git (remove "continue" before DT_REG in ls-files.c).
> 
> Is that fixed already?

It turn out it's quite tricky. git-ls-files doesn't distinguish between known and unknown directories. One way to do it would be to check all cached files and find all directories they are in. Another approach would involve "git-ls-tree -r", but I don't think it would be right because we work with cache and current files, not with committed data (but my knowledge is limited to make a call - I still need to read the documentation about git).

What I did was following:

"git-ls-files --cached" is run, directories are extracted, sorted but "sort -u" and put to a temporary file dirlist1. "find -type d" is run, ".git" is filtered out, the list is merged with dirlist1, sorted by "sort -u", and put to dirlist2. dirlist1 and dirlist2 are compared by diff, the entries in dirlist2 are unknown directories. (That's the kind of task where Perl hashes would be great). A technical detail - both lists are limited to $_git_relpath if it's defined.

Show 7 quoted lines
> > Processing of .gitignore was taken from cg-status, and I don't really
> > understand it.  But I think it's important to keep that code in sync.
> > It could later go to cg-Xlib.
> 
> It became much simpler a short while later, thankfully. Judging from
> your another patch, I suppose you are going to update this script
> accordingly?
Yes, I'm going to use "cg-status -w" for files.
> > # -d::
> > #	Also clean directories.
> 
> Perhaps add "and their contents" to prevent bad surprises.
Too late :-)
Show 7 quoted lines
> > filelist=$(mktemp -t gitlsfiles.XXXXXX)
> > git-ls-files --others $EXCLUDE >"$filelist"
> > save_IFS="$IFS"
> > IFS=$'\n'
> > for file in $(cat "$filelist"); do
> 
> Why can't you use git-ls-files | IFS=$'\n' while ?
Good idea.
Show 9 quoted lines
> > 	IFS="$save_IFS"
> > 	if [ -d "$file" ]; then
> > 		if [ "$cleandir" ]; then
> > 			# Try really hard by changing permissions
> > 			chmod -R 700 "$file"
> > 			rm -rf "$file"
> > 		fi
> 
> An error message would be in order otherwise, I guess.

You mean, list directories if "-d" is not specified? Good idea. Also, the latest revision included the "-v" option for "verbose" - it would show everything that gets deleted.

Show 5 quoted lines
> > 		return
> 
> I suppose you mean continue? I'm not really sure what does return do
> here, if it jumps out of the do block or what, and continue is nicely
> explicit. :-)
My error, it was fixed soon after I posted the script.
-- 
Regards,
Pavel Roskin
Previous: Petr BaudisNext: Petr Baudis
Message 6 of 8 in “New script: cg-clean”
  1. Pavel RoskinJul 8, 2005
  2. Wolfgang DenkJul 8, 2005
  3. Petr BaudisJul 10, 2005
  4. Pavel RoskinAug 6, 2005
  5. Petr BaudisAug 11, 2005
  6. Pavel RoskinAug 12, 2005
  7. Petr BaudisAug 12, 2005
  8. Pavel RoskinAug 12, 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.