git p4 test: examine behavior with locked (+l) files
[gitweb.git] / shallow.c
index 5f626c013890b60c991200434589425a0e16cef9..961cf6f02480e04d1baebb8f508aa17c5fea6355 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -90,8 +90,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                                cur_depth = *(int *)commit->util;
                        }
                }
-               if (parse_commit(commit))
-                       die("invalid commit");
+               parse_commit_or_die(commit);
                cur_depth++;
                if (cur_depth >= depth) {
                        commit_list_insert(commit, &result);
@@ -175,6 +174,29 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
        return data.count;
 }
 
+char *setup_temporary_shallow(void)
+{
+       struct strbuf sb = STRBUF_INIT;
+       int fd;
+
+       if (write_shallow_commits(&sb, 0)) {
+               struct strbuf path = STRBUF_INIT;
+               strbuf_addstr(&path, git_path("shallow_XXXXXX"));
+               fd = xmkstemp(path.buf);
+               if (write_in_full(fd, sb.buf, sb.len) != sb.len)
+                       die_errno("failed to write to %s",
+                                 path.buf);
+               close(fd);
+               strbuf_release(&sb);
+               return strbuf_detach(&path, NULL);
+       }
+       /*
+        * is_repository_shallow() sees empty string as "no shallow
+        * file".
+        */
+       return xstrdup("");
+}
+
 void setup_alternate_shallow(struct lock_file *shallow_lock,
                             const char **alternate_shallow_file)
 {