8
#include "list.h"
9
#include "streaming.h"
10
#include "sha1-lookup.h"
11
+#include "commit.h"
12
+#include "object.h"
13
+#include "tag.h"
14
+#include "tree-walk.h"
15
+#include "tree.h"
16
17
char *odb_pack_name(struct strbuf *buf,
18
const unsigned char *sha1,
648
return NULL;
649
650
/*
646
- * ".pack" is long enough to hold any suffix we're adding (and
651
+ * ".promisor" is long enough to hold any suffix we're adding (and
652
* the use xsnprintf double-checks that)
653
*/
649
- alloc = st_add3(path_len, strlen(".pack"), 1);
654
+ alloc = st_add3(path_len, strlen(".promisor"), 1);
655
p = alloc_packed_git(alloc);
656
memcpy(p->pack_name, path, path_len);
657
659
if (!access(p->pack_name, F_OK))
660
p->pack_keep = 1;
661
662
+ xsnprintf(p->pack_name + path_len, alloc - path_len, ".promisor");
663
+ if (!access(p->pack_name, F_OK))
664
+ p->pack_promisor = 1;
665
+
666
xsnprintf(p->pack_name + path_len, alloc - path_len, ".pack");
667
if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
668
free(p);
790
if (ends_with(de->d_name, ".idx") ||
791
ends_with(de->d_name, ".pack") ||
792
ends_with(de->d_name, ".bitmap") ||
784
- ends_with(de->d_name, ".keep"))
793
+ ends_with(de->d_name, ".keep") ||
794
+ ends_with(de->d_name, ".promisor"))
795
string_list_append(&garbage, path.buf);
796
else
797
report_garbage(PACKDIR_FILE_GARBAGE, path.buf);
1899
for (p = packed_git; p; p = p->next) {
1900
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
1901
continue;
1902
+ if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
1903
+ !p->pack_promisor)
1904
+ continue;
1905
if (open_pack_index(p)) {
1906
pack_errors = 1;
1907
continue;
1912
}
1913
return r ? r : pack_errors;
1914
}
1915
+
1916
+static int add_promisor_object(const struct object_id *oid,
1917
+ struct packed_git *pack,
1918
+ uint32_t pos,
1919
+ void *set_)
1920
+{
1921
+ struct oidset *set = set_;
1922
+ struct object *obj = parse_object(oid);
1923
+ if (!obj)
1924
+ return 1;
1925
+
1926
+ oidset_insert(set, oid);
1927
+
1928
+ /*
1929
+ * If this is a tree, commit, or tag, the objects it refers
1930
+ * to are also promisor objects. (Blobs refer to no objects.)
1931
+ */
1932
+ if (obj->type == OBJ_TREE) {
1933
+ struct tree *tree = (struct tree *)obj;
1934
+ struct tree_desc desc;
1935
+ struct name_entry entry;
1936
+ if (init_tree_desc_gently(&desc, tree->buffer, tree->size))
1937
+ /*
1938
+ * Error messages are given when packs are
1939
+ * verified, so do not print any here.
1940
+ */
1941
+ return 0;
1942
+ while (tree_entry_gently(&desc, &entry))
1943
+ oidset_insert(set, entry.oid);
1944
+ } else if (obj->type == OBJ_COMMIT) {
1945
+ struct commit *commit = (struct commit *) obj;
1946
+ struct commit_list *parents = commit->parents;
1947
+
1948
+ oidset_insert(set, &commit->tree->object.oid);
1949
+ for (; parents; parents = parents->next)
1950
+ oidset_insert(set, &parents->item->object.oid);
1951
+ } else if (obj->type == OBJ_TAG) {
1952
+ struct tag *tag = (struct tag *) obj;
1953
+ oidset_insert(set, &tag->tagged->oid);
1954
+ }
1955
+ return 0;
1956
+}
1957
+
1958
+int is_promisor_object(const struct object_id *oid)
1959
+{
1960
+ static struct oidset promisor_objects;
1961
+ static int promisor_objects_prepared;
1962
+
1963
+ if (!promisor_objects_prepared) {
1964
+ if (repository_format_partial_clone) {
1965
+ for_each_packed_object(add_promisor_object,
1966
+ &promisor_objects,
1967
+ FOR_EACH_OBJECT_PROMISOR_ONLY);
1968
+ }
1969
+ promisor_objects_prepared = 1;
1970
+ }
1971
+ return oidset_contains(&promisor_objects, oid);
1972
+}