threads / patch / 555

patchcg-init breaks if . contains sub-dir

Subject: [PATCH Cogito] cg-init breaks if . contains sub-dir

## tl;dr

22 messages between May 9, 2005 and May 12, 2005. Diffs are folded; open one to read it.

replies: 21people: 11as markdown or json

Brandon Philips· May 9, 2005, 23:39 UTC · lore
Hi Petr,
cg-init has the ability to cg-add all files in the current directory.

But if the current directory has a sub directory cg-init breaks because the `find *` command on line 34 returns directories which cg-add doesn't accept.

Regards
Brandon Philips
Shameless plug: cogito-0.10 available in Gentoo

-- http://ifup.org

---
cg-init: needs update
Show changes to diff +1 −1
Index: cg-init
===================================================================
--- 972d8624458936868e6f392b40858b7c362af8cd/cg-init  (mode:100755)
+++ uncommitted/cg-init  (mode:100755)
@@ -31,7 +31,7 @@
 	echo "Cloned (origin $uri available as branch \"origin\")"
 else
 	git-read-tree # Seed the dircache
-	find * | xargs cg-add
+	find * ! -type d | xargs cg-add 
 	cg-commit -C -m"Initial commit" -e
 fi
 exit 0
Matthias Urlichs· May 10, 2005, 03:41 UTC · re: Brandon Philips · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Hi, Brandon Philips wrote:
> -	find * | xargs cg-add
> +	find * ! -type d | xargs cg-add

Actually, (almost) every use of "find | xargs" which is not a subset of "find -print0 | xargs -0r" is a bug.

So please don't do that. Special files aren't liked by git either, thus:
        find * -type f -print0 | xargs -0r cg-add
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Brian Gerst· May 10, 2005, 05:17 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Matthias Urlichs wrote:
Show 14 quoted lines
> Hi, Brandon Philips wrote:
> 
> 
>>-	find * | xargs cg-add
>>+	find * ! -type d | xargs cg-add
> 
> 
> Actually, (almost) every use of "find | xargs" which is not a subset of
> "find -print0 | xargs -0r" is a bug.
> 
> So please don't do that. Special files aren't liked by git either, thus:
> 
>         find * -type f -print0 | xargs -0r cg-add
> 
But it can handle symlinks:
	find * -type f -o -type l -print0 | xargs -0r cg-add
--
				Brian Gerst
Jan-Benedict Glaw· May 10, 2005, 07:52 UTC · re: Brian Gerst · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

On Tue, 2005-05-10 01:17:31 -0400, Brian Gerst <bgerst@didntduck.org> wrote:
> But it can handle symlinks:
> 
> 	find * -type f -o -type l -print0 | xargs -0r cg-add

This won't work because the explicit OR (-o) lower precedence compared to the implicit AND between "-type l" and "-print0", thus this find command will do print0 IFF the matched entry is a symlink. Use something like this instead:

	find * \( -type f -o tyle l \) -print0 | ...
MfG, JBG
-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
Jan-Benedict Glaw· May 10, 2005, 08:04 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

On Tue, 2005-05-10 09:52:27 +0200, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
Show 11 quoted lines
> On Tue, 2005-05-10 01:17:31 -0400, Brian Gerst <bgerst@didntduck.org> wrote:
> > But it can handle symlinks:
> > 
> > 	find * -type f -o -type l -print0 | xargs -0r cg-add
> 
> This won't work because the explicit OR (-o) lower precedence compared
> to the implicit AND between "-type l" and "-print0", thus this find
> command will do print0 IFF the matched entry is a symlink. Use something
> like this instead:
> 
> 	find * \( -type f -o tyle l \) -print0 | ...

Btw, this won't find dot files, so using "." as the path list (instead of "*") might be wise...

MfG, JBG
-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
Matthias Urlichs· May 10, 2005, 08:36 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Hi,
Jan-Benedict Glaw:
Show 5 quoted lines
> > 	find * \( -type f -o tyle l \) -print0 | ...
> 
> Btw, this won't find dot files, so using "." as the path list (instead
> of "*") might be wise...
> 
git doesn't want to handle dot files anyway.
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Martin Waitz· May 10, 2005, 08:56 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

hoi :)
On Tue, May 10, 2005 at 10:36:09AM +0200, Matthias Urlichs wrote:
Show 7 quoted lines
> Jan-Benedict Glaw:
> > > 	find * \( -type f -o tyle l \) -print0 | ...
> > 
> > Btw, this won't find dot files, so using "." as the path list (instead
> > of "*") might be wise...
> > 
> git doesn't want to handle dot files anyway.

but find will output dotfiles in subdirectories. So you have to prune the list anyway.

-- 
Martin Waitz
Jan-Benedict Glaw· May 10, 2005, 08:56 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

On Tue, 2005-05-10 10:36:09 +0200, Matthias Urlichs <smurf@smurf.noris.de> wrote:
Show 7 quoted lines
> Jan-Benedict Glaw:
> > > 	find * \( -type f -o tyle l \) -print0 | ...
> > 
> > Btw, this won't find dot files, so using "." as the path list (instead
> > of "*") might be wise...
> > 
> git doesn't want to handle dot files anyway.

...which I actually consider to be a bug. Why should git care about the filename, as long as it doesn't clash with ".git"? After all, it's just a plumbing mechanism designed to locate file contents by SHA-1 hashes. It shouldn't deal with file names at all, really:-)

MfG, JBG
-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
David Greaves· May 10, 2005, 09:47 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Jan-Benedict Glaw wrote:
Show 24 quoted lines
>On Tue, 2005-05-10 10:36:09 +0200, Matthias Urlichs <smurf@smurf.noris.de> wrote:
>  
>
>>Jan-Benedict Glaw:
>>    
>>
>>>>	find * \( -type f -o tyle l \) -print0 | ...
>>>>        
>>>>
>>>Btw, this won't find dot files, so using "." as the path list (instead
>>>of "*") might be wise...
>>>
>>>      
>>>
>>git doesn't want to handle dot files anyway.
>>    
>>
>
>...which I actually consider to be a bug. Why should git care about the
>filename, as long as it doesn't clash with ".git"?  After all, it's just
>a plumbing mechanism designed to locate file contents by SHA-1 hashes.
>It shouldn't deal with file names at all, really:-)
>  
>

I tend to agree that a generic 'content tracking system' shouldn't impose this kind of rule. Requiring well formed filenames (eg no //, no trailing /s) is fine - but dot-file-discrimination?

When I first saw it, I expected this kind of rule to (eventually) be lifted from the plumbing to the porcelain. The minor problem is that Linus seems to like getting his hands dirty and keeps using the plumbing ;) (eek - these analogies...)

David
David Greaves· May 10, 2005, 08:42 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Jan-Benedict Glaw wrote:
Show 24 quoted lines
>On Tue, 2005-05-10 09:52:27 +0200, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
>  
>
>>On Tue, 2005-05-10 01:17:31 -0400, Brian Gerst <bgerst@didntduck.org> wrote:
>>    
>>
>>>But it can handle symlinks:
>>>
>>>	find * -type f -o -type l -print0 | xargs -0r cg-add
>>>      
>>>
>>This won't work because the explicit OR (-o) lower precedence compared
>>to the implicit AND between "-type l" and "-print0", thus this find
>>command will do print0 IFF the matched entry is a symlink. Use something
>>like this instead:
>>
>>	find * \( -type f -o tyle l \) -print0 | ...
>>    
>>
>
>Btw, this won't find dot files, so using "." as the path list (instead
>of "*") might be wise...
>  
>
This is a good thing - git ignores dot-files. see:
  http://www.dgreaves.com/git/git-update-cache.html
*
<file> *
    Files to act on. Note that files begining with *.* are discarded.
    This includes ./file and dir/./file. If you don't want this, then
    use cleaner names. The same applies to directories ending */* and
    paths with *//* 

Cogito should eventually spot and remove these since find * will obviously find files beginning with a dot in subdirectories.

David
Junio C Hamano· May 10, 2005, 09:01 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

>>>>> "JBG" == Jan-Benedict Glaw <jbglaw@lug-owl.de> writes:
>> find * \( -type f -o tyle l \) -print0 | ...

JBG> Btw, this won't find dot files, so using "." as the path list (instead JBG> of "*") might be wise...

Huh? Since when GIT started managing paths whose _any_ of their path component starts with a dot?

Jan-Benedict Glaw· May 10, 2005, 09:32 UTC · re: Junio C Hamano · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

On Tue, 2005-05-10 02:01:41 -0700, Junio C Hamano <junkio@cox.net> wrote:
Show 9 quoted lines
> >>>>> "JBG" == Jan-Benedict Glaw <jbglaw@lug-owl.de> writes:
> 
> >> find * \( -type f -o tyle l \) -print0 | ...
> 
> JBG> Btw, this won't find dot files, so using "." as the path list (instead
> JBG> of "*") might be wise...
> 
> Huh?  Since when GIT started managing paths whose _any_ of their
> path component starts with a dot?

The Catholic Church never ever had female priests, so how could this be a good thing?

Ever thought about keeping some important files (of your $HOME) in some SCM? For sure, some of those are dot files:-)

MfG, JBG
-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
Matthias Urlichs· May 10, 2005, 09:39 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Hi,
Jan-Benedict Glaw:
> Ever thought about keeping some important files (of your $HOME) in some
> SCM? For sure, some of those are dot files:-)
> 
Yeah, but so are various local temporary files.
Please don't change that without talking to Linus.

FWIW, I keep important files backed up (backuppc is your friend). No need to bother with an SCM for that.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Jan-Benedict Glaw· May 10, 2005, 09:45 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

On Tue, 2005-05-10 11:39:24 +0200, Matthias Urlichs <smurf@smurf.noris.de> wrote:
Show 7 quoted lines
> Jan-Benedict Glaw:
> > Ever thought about keeping some important files (of your $HOME) in some
> > SCM? For sure, some of those are dot files:-)
>
> Yeah, but so are various local temporary files.
> 
> Please don't change that without talking to Linus.

I won't. You haven't seen a patch from me "fixing" this, too. *I* consider this as a defect, but that doesn't mean that I'll force others to take this view, too. But maybe I'll talk Linus into this when he's back from his trip.

MfG, JBG
-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
Matthias Urlichs· May 10, 2005, 09:58 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Hi,
Jan-Benedict Glaw:
Show 6 quoted lines
> > Please don't change that without talking to Linus.
> 
> I won't.  You haven't seen a patch from me "fixing" this, too.  *I*
> consider this as a defect, but that doesn't mean that I'll force others
> to take this view, too.  But maybe I'll talk Linus into this when he's
> back from his trip.

That would be a good idea; I do support dropping (or at least relaxing) that rule. For excluding unwanted files, I'd suggest using a .git/ignore file with nice shiny patterns (*.a *.o *.swp ...) inside -- git already supports that anyway.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
David Mansfield· May 10, 2005, 21:31 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Matthias Urlichs wrote:
Show 17 quoted lines
> Hi,
> 
> Jan-Benedict Glaw:
> 
>>>Please don't change that without talking to Linus.
>>
>>I won't.  You haven't seen a patch from me "fixing" this, too.  *I*
>>consider this as a defect, but that doesn't mean that I'll force others
>>to take this view, too.  But maybe I'll talk Linus into this when he's
>>back from his trip.
> 
> 
> That would be a good idea; I do support dropping (or at least relaxing)
> that rule. For excluding unwanted files, I'd suggest using a .git/ignore
> file with nice shiny patterns (*.a *.o *.swp ...) inside -- git already
> supports that anyway.
> 

Speaking of which, for a large project, (such as the kernel) it is a pain in the butt if exclude lists only consider the 'basename' of the file, and cannot include any path matching information.

For a long time there were generated files in the kernel which had the same names as non-generated files somewhere else in the kernel tree (under a different path). Making an automated 'take latest patch from Linus, apply, commit' was really a pain because of this.

Is there/will there be support for path matching in the ignore files?
If the answer is no, but people like the idea, I could look into it.
David
Matthias Urlichs· May 11, 2005, 05:25 UTC · re: David Mansfield · lore

[PATCH Cogito] match pathnames in exclude handling

Hi,
David Mansfield:
> Is there/will there be support for path matching in the ignore files?
> 
> If the answer is no, but people like the idea, I could look into it.
> 
I already did, last week. (I do need to cleanup my changes...)

The idea is that "foo" matches anywhere, "foo/bar" the exact pathname. As a special case, "./foo" matches in the root directory only.

NB: "*" can cross subdirectory paths, so "*/foo/bar" does match
"a/b/c/foo/bar".
Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>
---
Show changes to diff +13 −5
Index: ls-files.c
===================================================================
--- 972d8624458936868e6f392b40858b7c362af8cd/ls-files.c  (mode:100644)
+++ 12deb13b12cdb338fe3fdc2e77a024490d6c39ea/ls-files.c  (mode:100644)
@@ -80,9 +80,17 @@
 	if (nr_excludes) {
 		const char *basename = strrchr(pathname, '/');
 		basename = (basename) ? basename+1 : pathname;
-		for (i = 0; i < nr_excludes; i++)
-			if (fnmatch(excludes[i], basename, 0) == 0)
-				return 1;
+		for (i = 0; i < nr_excludes; i++) {
+			if (excludes[i][0] != '.' || excludes[i][1] != '/') {
+				if (fnmatch(excludes[i], pathname, 0) == 0)
+					return 1;
+				if (basename != pathname && fnmatch(excludes[i], pathname, 0) == 0)
+					return 1;
+			} else {
+				if (fnmatch(excludes[i]+2, pathname, 0) == 0)
+					return 1;
+			}
+		}
 	}
 	return 0;
 }
@@ -129,10 +137,10 @@
 
 			if (de->d_name[0] == '.')
 				continue;
-			if (excluded(de->d_name) != show_ignored)
-				continue;
 			len = strlen(de->d_name);
 			memcpy(fullname + baselen, de->d_name, len+1);
+			if (excluded(fullname) != show_ignored)
+				continue;
 
 			switch (DTYPE(de)) {
 			struct stat st;
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
H. Peter Anvin· May 11, 2005, 21:30 UTC · re: Matthias Urlichs · lore

Re: [PATCH Cogito] match pathnames in exclude handling

Matthias Urlichs wrote:
Show 9 quoted lines
> 
> I already did, last week. (I do need to cleanup my changes...)
> 
> The idea is that "foo" matches anywhere, "foo/bar" the exact pathname.
> As a special case, "./foo" matches in the root directory only.
> 
> NB: "*" can cross subdirectory paths, so "*/foo/bar" does match
> "a/b/c/foo/bar".
> 

How does that mean foo*.c would match foo/bar/quux.c? That's probably a bad thing.

I do like the (sadly, rarely used) convention that ** matches / whereas 
* doesn't.
	-hpa
Matthias Urlichs· May 12, 2005, 07:54 UTC · re: H. Peter Anvin · lore

Re: [PATCH Cogito] match pathnames in exclude handling

Hi,
H. Peter Anvin:
> How does that mean foo*.c would match foo/bar/quux.c?  That's probably a 
> bad thing.
> 

No, of course not -- that was a thinko on my part when I typed the examples. :-/

> I do like the (sadly, rarely used) convention that ** matches / whereas 
> * doesn't.
> 

fnmatch() doesn't support that. Of course, if there's demand for it, it should be reasonably easy to have our own extended copy.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
H. Peter Anvin· May 10, 2005, 15:14 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Jan-Benedict Glaw wrote:
Show 17 quoted lines
> On Tue, 2005-05-10 11:39:24 +0200, Matthias Urlichs <smurf@smurf.noris.de> wrote:
> 
>>Jan-Benedict Glaw:
>>
>>>Ever thought about keeping some important files (of your $HOME) in some
>>>SCM? For sure, some of those are dot files:-)
>>
>>Yeah, but so are various local temporary files.
>>
>>Please don't change that without talking to Linus.
> 
> 
> I won't.  You haven't seen a patch from me "fixing" this, too.  *I*
> consider this as a defect, but that doesn't mean that I'll force others
> to take this view, too.  But maybe I'll talk Linus into this when he's
> back from his trip.
> 
Another vote for fixing this!
	-hpa
Petr Baudis· May 12, 2005, 18:53 UTC · re: Jan-Benedict Glaw · lore

Re: [PATCH Cogito] cg-init breaks if . contains sub-dir

Dear diary, on Tue, May 10, 2005 at 09:52:27AM CEST, I got a letter where Jan-Benedict Glaw <jbglaw@lug-owl.de> told me that...

Show 11 quoted lines
> On Tue, 2005-05-10 01:17:31 -0400, Brian Gerst <bgerst@didntduck.org> wrote:
> > But it can handle symlinks:
> > 
> > 	find * -type f -o -type l -print0 | xargs -0r cg-add
> 
> This won't work because the explicit OR (-o) lower precedence compared
> to the implicit AND between "-type l" and "-print0", thus this find
> command will do print0 IFF the matched entry is a symlink. Use something
> like this instead:
> 
> 	find * \( -type f -o tyle l \) -print0 | ...
Thanks to all the four co-authors, applied.
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

← back to recent threads