Skip to contentSkip to conversation

Add an empty directory?

DISCUSSION Carl Baldwin 4 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

Signature · 7 lines
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: [email protected]
 Fort Collins, CO 80525              home: [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#1 lore raw

Dear diary, on Sat, Aug 13, 2005 at 07:30:43PM CEST, I got a letter where Carl Baldwin <[email protected]> told me that...

Quoted 1 line

Greetings,

Hi,

Quoted 13 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).

Quoted 7 lines

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

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox
#2 lore raw

Hi,

Quoted 5 lines · Petr Baudis

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

Signature · 7 lines
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: [email protected]
 Fort Collins, CO 80525              home: [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#3 lore raw
Quoted 4 lines · Carl Baldwin

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

#4 lore raw

Dear diary, on Sat, Aug 13, 2005 at 09:41:45PM CEST, I got a letter where Linus Torvalds <[email protected]> told me that...

Quoted 10 lines · Carl Baldwin
Quoted 4 lines

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.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox
#5 lore raw
In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Carl Baldwin

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.

Quoted 8 lines

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.

Quoted 11 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

Signature · 7 lines
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: [email protected]
 Fort Collins, CO 80525              home: [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#6 lore raw
In reply to Petr Baudis
Quoted 2 lines · Petr Baudis

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