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:
> > 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.

> > 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 :-)

> > 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.

> >     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.

> >             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.

Pavel Roskin

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to