Merge branch 'sb/submodule-clone-retry'
[gitweb.git] / submodule-config.c
index debab294d421675cdebb129b257808614f607a09..faedb1a4899639567d8d6d6af75338c26be8f7ae 100644 (file)
@@ -199,6 +199,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
        submodule->update_strategy.command = NULL;
        submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
        submodule->ignore = NULL;
+       submodule->recommend_shallow = -1;
 
        hashcpy(submodule->gitmodules_sha1, gitmodules_sha1);
 
@@ -353,6 +354,14 @@ static int parse_config(const char *var, const char *value, void *data)
                else if (parse_submodule_update_strategy(value,
                         &submodule->update_strategy) < 0)
                                die(_("invalid value for %s"), var);
+       } else if (!strcmp(item.buf, "shallow")) {
+               if (!me->overwrite && submodule->recommend_shallow != -1)
+                       warn_multiple_config(me->commit_sha1, submodule->name,
+                                            "shallow");
+               else {
+                       submodule->recommend_shallow =
+                               git_config_bool(var, value);
+               }
        }
 
        strbuf_release(&name);
@@ -362,21 +371,20 @@ static int parse_config(const char *var, const char *value, void *data)
 }
 
 static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
-                                     unsigned char *gitmodules_sha1)
+                                     unsigned char *gitmodules_sha1,
+                                     struct strbuf *rev)
 {
-       struct strbuf rev = STRBUF_INIT;
        int ret = 0;
 
        if (is_null_sha1(commit_sha1)) {
-               hashcpy(gitmodules_sha1, null_sha1);
+               hashclr(gitmodules_sha1);
                return 1;
        }
 
-       strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
-       if (get_sha1(rev.buf, gitmodules_sha1) >= 0)
+       strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
+       if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
                ret = 1;
 
-       strbuf_release(&rev);
        return ret;
 }
 
@@ -390,7 +398,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 {
        struct strbuf rev = STRBUF_INIT;
        unsigned long config_size;
-       char *config;
+       char *config = NULL;
        unsigned char sha1[20];
        enum object_type type;
        const struct submodule *submodule = NULL;
@@ -411,8 +419,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
                return entry->config;
        }
 
-       if (!gitmodule_sha1_from_commit(commit_sha1, sha1))
-               return NULL;
+       if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
+               goto out;
 
        switch (lookup_type) {
        case lookup_name:
@@ -423,16 +431,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
                break;
        }
        if (submodule)
-               return submodule;
+               goto out;
 
        config = read_sha1_file(sha1, &type, &config_size);
-       if (!config)
-               return NULL;
-
-       if (type != OBJ_BLOB) {
-               free(config);
-               return NULL;
-       }
+       if (!config || type != OBJ_BLOB)
+               goto out;
 
        /* fill the submodule config into the cache */
        parameter.cache = cache;
@@ -441,6 +444,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
        parameter.overwrite = 0;
        git_config_from_mem(parse_config, "submodule-blob", rev.buf,
                        config, config_size, &parameter);
+       strbuf_release(&rev);
        free(config);
 
        switch (lookup_type) {
@@ -451,6 +455,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
        default:
                return NULL;
        }
+
+out:
+       strbuf_release(&rev);
+       free(config);
+       return submodule;
 }
 
 static const struct submodule *config_from_path(struct submodule_cache *cache,