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

Function convert_to_sparse_rec

sparse-index.c:60–130  ·  view source on GitHub ↗

* Returns the number of entries "inserted" into the index. */

Source from the content-addressed store, hash-verified

58 * Returns the number of entries "inserted" into the index.
59 */
60static int convert_to_sparse_rec(struct index_state *istate,
61 int num_converted,
62 int start, int end,
63 const char *ct_path, size_t ct_pathlen,
64 struct cache_tree *ct)
65{
66 int i, can_convert = 1;
67 int start_converted = num_converted;
68 struct strbuf child_path = STRBUF_INIT;
69
70 /*
71 * Is the current path outside of the sparse cone?
72 * Then check if the region can be replaced by a sparse
73 * directory entry (everything is sparse and merged).
74 */
75 if (path_in_sparse_checkout(ct_path, istate))
76 can_convert = 0;
77
78 for (i = start; can_convert && i < end; i++) {
79 struct cache_entry *ce = istate->cache[i];
80
81 if (ce_stage(ce) ||
82 S_ISGITLINK(ce->ce_mode) ||
83 !(ce->ce_flags & CE_SKIP_WORKTREE))
84 can_convert = 0;
85 }
86
87 if (can_convert) {
88 struct cache_entry *se;
89 se = construct_sparse_dir_entry(istate, ct_path, ct);
90
91 istate->cache[num_converted++] = se;
92 return 1;
93 }
94
95 for (i = start; i < end; ) {
96 int count, span, pos = -1;
97 const char *base, *slash;
98 struct cache_entry *ce = istate->cache[i];
99
100 /*
101 * Detect if this is a normal entry outside of any subtree
102 * entry.
103 */
104 base = ce->name + ct_pathlen;
105 slash = strchr(base, '/');
106
107 if (slash)
108 pos = cache_tree_subtree_pos(ct, base, slash - base);
109
110 if (pos < 0) {
111 istate->cache[num_converted++] = ce;
112 i++;
113 continue;
114 }
115
116 strbuf_setlen(&child_path, 0);
117 strbuf_add(&child_path, ce->name, slash - ce->name + 1);

Callers 1

convert_to_sparseFunction · 0.85

Calls 6

path_in_sparse_checkoutFunction · 0.85
cache_tree_subtree_posFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_addFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected