threads / discuss / 1503

Add an empty directory?

Subject: Add an empty directory?

## tl;dr

7 messages between Aug 13, 2005 and Aug 13, 2005.

replies: 6people: 4as markdown or json

Carl Baldwin· Aug 13, 2005, 17:30 UTC · lore
Greetings,

My appologies if this has already been discussed. I've been through the archives but could easily have missed something.

I have found it useful in the past to have the ability to add an empty directory to the repository. With what little I know about git it seems that this is entirely possible. It would create an empty tree object for the new directory and insert a reference to that in the parent tree object.

If someone could get me started I think I could find the time to create and submit a patch to allow this. Here is what I've tried (with 0.99.4).

% mkdir test % cd test % git-init-db % mkdir dir % git-add-script dir error: open("dir"): No such file or directory fatal: Unable to add dir to database

Cheers, Carl

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Petr Baudis· Aug 13, 2005, 18:00 UTC · re: Carl Baldwin · lore

Re: Add an empty directory?

Dear diary, on Sat, Aug 13, 2005 at 07:30:43PM CEST, I got a letter where Carl Baldwin <cnb@fc.hp.com> told me that...

> Greetings,
Hi,
Show 20 quoted lines
> My appologies if this has already been discussed.  I've been through the
> archives but could easily have missed something.
> 
> I have found it useful in the past to have the ability to add an empty
> directory to the repository.  With what little I know about git it seems
> that this is entirely possible.  It would create an empty tree object
> for the new directory and insert a reference to that in the parent tree
> object.
> 
> If someone could get me started I think I could find the time to create
> and submit a patch to allow this.  Here is what I've tried (with
> 0.99.4).
> 
> % mkdir test
> % cd test
> % git-init-db
> % mkdir dir
> % git-add-script dir
> error: open("dir"): No such file or directory
> fatal: Unable to add dir to database

the object databases supports it, but the index file does not. But yes, it should be supported, I think.

Some argue that this is useless, so some practical example of its usefulness might be a good motivation to get us going. :-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox
Carl Baldwin· Aug 13, 2005, 18:19 UTC · re: Petr Baudis · lore

Re: Add an empty directory?

Hi,
On Sat, Aug 13, 2005 at 08:00:08PM +0200, Petr Baudis wrote:
Show 5 quoted lines
> the object databases supports it, but the index file does not. But yes,
> it should be supported, I think.
> 
> Some argue that this is useless, so some practical example of its
> usefulness might be a good motivation to get us going. :-)

That's fair. So, here goes. I don't particularly condone nor condemn any of these.

- Just yesterday, I was starting a project at work.  I wanted to add a
  doc directory as a reminder to add documentation very soon.  I could
  not do this.
- I've worked with projects that use an obj, .obj, .obj-platform or
  something resembling this and have checked in this directory to make
  sure it exists for all.  Of course, a build system could be made to
  generate this directory when needed avoiding the need to check it in.
- A common practice I've seen with autotools is to use a config
  subdirectory for many of the autogenerated scripts.  If I'm not
  mistaken older versions would not create this directory if it did not
  already exist.  Checking it in was a convenience.

The bottom line is that I don't really see many situations where it is absolutely necessary but it is a convenience. Not supporting it may seem like an artificial limit that really didn't need to be there.

I'll read up on the index file when I get the chance.

Cheers, Carl

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Linus Torvalds· Aug 13, 2005, 19:41 UTC · re: Carl Baldwin · lore

Re: Add an empty directory?

On Sat, 13 Aug 2005, Carl Baldwin wrote:
> 
> The bottom line is that I don't really see many situations where it is
> absolutely necessary but it is a convenience.  Not supporting it may
> seem like an artificial limit that really didn't need to be there.

Well, there is an argument for not supporting it, namely that the way patches work, traditionally a directory that became empty is deleted (because patches have no way of saying "remove directory" or "create directory").

So a system where the existence of a directory flows from the existence of the files within the directory will automatically always do the right thing with patches floating around.

Which is a big deal for me, since most of the kernel development still ends up being done with patches. Yes, we merge things with git, but a lot of the development is about passing patches around for review and commentary.

And the thing is, you can always create the directory in your workspace. Git won't care, and won't know about it, but there's really no downside to it.

			Linus
Petr Baudis· Aug 13, 2005, 19:55 UTC · re: Linus Torvalds · lore

Re: Add an empty directory?

Dear diary, on Sat, Aug 13, 2005 at 09:41:45PM CEST, I got a letter where Linus Torvalds <torvalds@osdl.org> told me that...

Show 10 quoted lines
> On Sat, 13 Aug 2005, Carl Baldwin wrote:
> > 
> > The bottom line is that I don't really see many situations where it is
> > absolutely necessary but it is a convenience.  Not supporting it may
> > seem like an artificial limit that really didn't need to be there.
> 
> Well, there is an argument for not supporting it, namely that the way 
> patches work, traditionally a directory that became empty is deleted 
> (because patches have no way of saying "remove directory" or "create 
> directory").

If we have rename patches, why couldn't our patches deal with directories as well? And git-apply, cg-patch etc might have a way to behave in a "traditional" way for non-git patches and if a patch removes all files in a directory, kill the directory.

That is, I would solve this on the SCM<->patches boundary, not fundamentally limit the SCM itself.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox
Carl Baldwin· Aug 13, 2005, 20:10 UTC · re: Linus Torvalds · lore

Re: Add an empty directory?

On Sat, Aug 13, 2005 at 12:41:45PM -0700, Linus Torvalds wrote:
Show 16 quoted lines
> 
> 
> On Sat, 13 Aug 2005, Carl Baldwin wrote:
> > 
> > The bottom line is that I don't really see many situations where it is
> > absolutely necessary but it is a convenience.  Not supporting it may
> > seem like an artificial limit that really didn't need to be there.
> 
> Well, there is an argument for not supporting it, namely that the way 
> patches work, traditionally a directory that became empty is deleted 
> (because patches have no way of saying "remove directory" or "create 
> directory").
> 
> So a system where the existence of a directory flows from the existence of 
> the files within the directory will automatically always do the right 
> thing with patches floating around.

I see your point here. However, if git supported it then any particular usage model on top of git could choose to do it either way. If it doesn't then that flexibility is not there.

Show 11 quoted lines
> Which is a big deal for me, since most of the kernel development still 
> ends up being done with patches. Yes, we merge things with git, but a lot 
> of the development is about passing patches around for review and 
> commentary.
> 
> And the thing is, you can always create the directory in your workspace. 
> Git won't care, and won't know about it, but there's really no downside to 
> it. 
> 
> 			Linus
> 
-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Junio C Hamano· Aug 13, 2005, 19:45 UTC · re: Petr Baudis · lore

Re: Add an empty directory?

Petr Baudis <pasky@suse.cz> writes:
> the object databases supports it, but the index file does not. But yes,
> it should be supported, I think.

I think if this is done correctly "read-tree -m -u" two-tree switch could even remove directories that existed in the old tree but not in the new tree that has become empty.

On the other hand, although I haven't started looking, adding this to index file might involve a major surgery. Practically everybody expects it is does not have an directory entry. This includes reading trees, merging two or more stages, finding directory/file conflicts, etc. etc...

← back to recent threads