Teach "git-read-tree -u" to check out submodules as a directory
This actually allows us to check out a supermodule after cloning, although the submodules themselves will obviously not be checked out, and will just be empty directories. Checking out the submodules will be up to higher levels - we may not even want to! Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Apr 13, 2007 at 09:26 UTC
f0807e62b42df51a079c730dcf4868de9ad44ea5
1 file changed
+32
-13
entry.c
+32
-13
@@ -62,26 +62,33 @@ static int create_file(const char *path, unsigned int mode)
62
return open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
63
}
64
65
+static void *read_blob_entry(struct cache_entry *ce, const char *path, unsigned long *size)
66
+{
67
+ enum object_type type;
68
+ void *new = read_sha1_file(ce->sha1, &type, size);
69
+
70
+ if (new) {
71
+ if (type == OBJ_BLOB)
72
+ return new;
73
+ free(new);
74
+ }
75
+ return NULL;
76
+}
77
+
78
static int write_entry(struct cache_entry *ce, char *path, struct checkout *state, int to_tempfile)
79
{
80
int fd;
68
- void *new;
69
- unsigned long size;
81
long wrote;
71
- enum object_type type;
82
73
- new = read_sha1_file(ce->sha1, &type, &size);
74
- if (!new || type != OBJ_BLOB) {
75
- if (new)
76
- free(new);
77
- return error("git-checkout-index: unable to read sha1 file of %s (%s)",
78
- path, sha1_to_hex(ce->sha1));
79
- }
83
switch (ntohl(ce->ce_mode) & S_IFMT) {
81
- char *buf;
82
- unsigned long nsize;
84
+ char *buf, *new;
85
+ unsigned long size, nsize;
86
87
case S_IFREG:
88
+ new = read_blob_entry(ce, path, &size);
89
+ if (!new)
90
+ return error("git-checkout-index: unable to read sha1 file of %s (%s)",
91
+ path, sha1_to_hex(ce->sha1));
92
if (to_tempfile) {
93
strcpy(path, ".merge_file_XXXXXX");
94
fd = mkstemp(path);
@@ -111,6 +118,10 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
118
return error("git-checkout-index: unable to write file %s", path);
119
break;
120
case S_IFLNK:
121
+ new = read_blob_entry(ce, path, &size);
122
+ if (!new)
123
+ return error("git-checkout-index: unable to read sha1 file of %s (%s)",
124
+ path, sha1_to_hex(ce->sha1));
125
if (to_tempfile || !has_symlinks) {
126
if (to_tempfile) {
127
strcpy(path, ".merge_link_XXXXXX");
@@ -136,8 +147,13 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
147
"symlink %s (%s)", path, strerror(errno));
148
}
149
break;
150
+ case S_IFDIRLNK:
151
+ if (to_tempfile)
152
+ return error("git-checkout-index: cannot create temporary subproject %s", path);
153
+ if (mkdir(path, 0777) < 0)
154
+ return error("git-checkout-index: cannot create subproject directory %s", path);
155
+ break;
156
default:
140
- free(new);
157
return error("git-checkout-index: unknown file mode for %s", path);
158
}
159
@@ -179,6 +195,9 @@ int checkout_entry(struct cache_entry *ce, struct checkout *state, char *topath)
195
*/
196
unlink(path);
197
if (S_ISDIR(st.st_mode)) {
198
+ /* If it is a gitlink, leave it alone! */
199
+ if (S_ISDIRLNK(ntohl(ce->ce_mode)))
200
+ return 0;
201
if (!state->force)
202
return error("%s is a directory", path);
203
remove_subtree(path);