OSDN Git Service

cygwin: allow pushing to UNC paths
[git-core/git.git] / entry.c
diff --git a/entry.c b/entry.c
index 519e042..d2b512d 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -2,6 +2,7 @@
 #include "blob.h"
 #include "dir.h"
 #include "streaming.h"
+#include "submodule.h"
 
 static void create_directories(const char *path, int path_len,
                               const struct checkout *state)
@@ -82,7 +83,7 @@ static int create_file(const char *path, unsigned int mode)
 static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
 {
        enum object_type type;
-       void *new = read_sha1_file(ce->sha1, &type, size);
+       void *new = read_sha1_file(ce->oid.hash, &type, size);
 
        if (new) {
                if (type == OBJ_BLOB)
@@ -127,7 +128,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,
        if (fd < 0)
                return -1;
 
-       result |= stream_blob_to_fd(fd, ce->sha1, filter, 1);
+       result |= stream_blob_to_fd(fd, &ce->oid, filter, 1);
        *fstat_done = fstat_output(fd, state, statbuf);
        result |= close(fd);
 
@@ -146,9 +147,11 @@ static int write_entry(struct cache_entry *ce,
        unsigned long size;
        size_t wrote, newsize = 0;
        struct stat st;
+       const struct submodule *sub;
 
        if (ce_mode_s_ifmt == S_IFREG) {
-               struct stream_filter *filter = get_stream_filter(ce->name, ce->sha1);
+               struct stream_filter *filter = get_stream_filter(ce->name,
+                                                                ce->oid.hash);
                if (filter &&
                    !streaming_write_entry(ce, path, filter,
                                           state, to_tempfile,
@@ -162,7 +165,7 @@ static int write_entry(struct cache_entry *ce,
                new = read_blob_entry(ce, &size);
                if (!new)
                        return error("unable to read sha1 file of %s (%s)",
-                               path, sha1_to_hex(ce->sha1));
+                               path, oid_to_hex(&ce->oid));
 
                if (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile) {
                        ret = symlink(new, path);
@@ -202,6 +205,10 @@ static int write_entry(struct cache_entry *ce,
                        return error("cannot create temporary submodule %s", path);
                if (mkdir(path, 0777) < 0)
                        return error("cannot create submodule directory %s", path);
+               sub = submodule_from_ce(ce);
+               if (sub)
+                       return submodule_move_head(ce->name,
+                               NULL, oid_to_hex(&ce->oid), SUBMODULE_MOVE_HEAD_FORCE);
                break;
        default:
                return error("unknown file mode for %s in index", path);
@@ -258,7 +265,31 @@ int checkout_entry(struct cache_entry *ce,
        strbuf_add(&path, ce->name, ce_namelen(ce));
 
        if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
+               const struct submodule *sub;
                unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
+               /*
+                * Needs to be checked before !changed returns early,
+                * as the possibly empty directory was not changed
+                */
+               sub = submodule_from_ce(ce);
+               if (sub) {
+                       int err;
+                       if (!is_submodule_populated_gently(ce->name, &err)) {
+                               struct stat sb;
+                               if (lstat(ce->name, &sb))
+                                       die(_("could not stat file '%s'"), ce->name);
+                               if (!(st.st_mode & S_IFDIR))
+                                       unlink_or_warn(ce->name);
+
+                               return submodule_move_head(ce->name,
+                                       NULL, oid_to_hex(&ce->oid),
+                                       SUBMODULE_MOVE_HEAD_FORCE);
+                       } else
+                               return submodule_move_head(ce->name,
+                                       "HEAD", oid_to_hex(&ce->oid),
+                                       SUBMODULE_MOVE_HEAD_FORCE);
+               }
+
                if (!changed)
                        return 0;
                if (!state->force) {