MCPcopy Create free account
hub / github.com/git/git / write_one

Function write_one

cache-tree.c:505–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

503}
504
505static void write_one(struct strbuf *buffer, struct cache_tree *it,
506 const char *path, int pathlen)
507{
508 int i;
509
510 /* One "cache-tree" entry consists of the following:
511 * path (NUL terminated)
512 * entry_count, subtree_nr ("%d %d\n")
513 * tree-sha1 (missing if invalid)
514 * subtree_nr "cache-tree" entries for subtrees.
515 */
516 strbuf_grow(buffer, pathlen + 100);
517 strbuf_add(buffer, path, pathlen);
518 strbuf_addf(buffer, "%c%d %d\n", 0, it->entry_count, it->subtree_nr);
519
520#if DEBUG_CACHE_TREE
521 if (0 <= it->entry_count)
522 fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
523 pathlen, path, it->entry_count, it->subtree_nr,
524 oid_to_hex(&it->oid));
525 else
526 fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n",
527 pathlen, path, it->subtree_nr);
528#endif
529
530 if (0 <= it->entry_count) {
531 strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz);
532 }
533 for (i = 0; i < it->subtree_nr; i++) {
534 struct cache_tree_sub *down = it->down[i];
535 if (i) {
536 struct cache_tree_sub *prev = it->down[i-1];
537 if (subtree_name_cmp(down->name, down->namelen,
538 prev->name, prev->namelen) <= 0)
539 die("fatal - unsorted cache subtree");
540 }
541 write_one(buffer, down->cache_tree, down->name, down->namelen);
542 }
543}
544
545void cache_tree_write(struct strbuf *sb, struct cache_tree *root)
546{

Callers 1

cache_tree_writeFunction · 0.70

Calls 6

strbuf_growFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addfFunction · 0.85
oid_to_hexFunction · 0.85
subtree_name_cmpFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected