Skip to content

Commit cd42415

Browse files
derrickstoleegitster
authored andcommitted
sparse-index: add 'sdir' index extension
The index format does not currently allow for sparse directory entries. This violates some expectations that older versions of Git or third-party tools might not understand. We need an indicator inside the index file to warn these tools to not interact with a sparse index unless they are aware of sparse directory entries. Add a new _required_ index extension, 'sdir', that indicates that the index may contain sparse directory entries. This allows us to continue to use the differences in index formats 2, 3, and 4 before we create a new index version 5 in a later change. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 836e25c commit cd42415

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Documentation/technical/index-format.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,15 @@ The remaining data of each directory block is grouped by type:
392392
in this block of entries.
393393

394394
- 32-bit count of cache entries in this block
395+
396+
== Sparse Directory Entries
397+
398+
When using sparse-checkout in cone mode, some entire directories within
399+
the index can be summarized by pointing to a tree object instead of the
400+
entire expanded list of paths within that tree. An index containing such
401+
entries is a "sparse index". Index format versions 4 and less were not
402+
implemented with such entries in mind. Thus, for these versions, an
403+
index containing sparse directory entries will include this extension
404+
with signature { 's', 'd', 'i', 'r' }. Like the split-index extension,
405+
tools should avoid interacting with a sparse index unless they understand
406+
this extension.

read-cache.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define CACHE_EXT_FSMONITOR 0x46534D4E /* "FSMN" */
4848
#define CACHE_EXT_ENDOFINDEXENTRIES 0x454F4945 /* "EOIE" */
4949
#define CACHE_EXT_INDEXENTRYOFFSETTABLE 0x49454F54 /* "IEOT" */
50+
#define CACHE_EXT_SPARSE_DIRECTORIES 0x73646972 /* "sdir" */
5051

5152
/* changes that can be kept in $GIT_DIR/index (basically all extensions) */
5253
#define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
@@ -1763,6 +1764,10 @@ static int read_index_extension(struct index_state *istate,
17631764
case CACHE_EXT_INDEXENTRYOFFSETTABLE:
17641765
/* already handled in do_read_index() */
17651766
break;
1767+
case CACHE_EXT_SPARSE_DIRECTORIES:
1768+
/* no content, only an indicator */
1769+
istate->sparse_index = 1;
1770+
break;
17661771
default:
17671772
if (*ext < 'A' || 'Z' < *ext)
17681773
return error(_("index uses %.4s extension, which we do not understand"),
@@ -3020,6 +3025,10 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
30203025
if (err)
30213026
return -1;
30223027
}
3028+
if (istate->sparse_index) {
3029+
if (write_index_ext_header(&c, &eoie_c, newfd, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0)
3030+
return -1;
3031+
}
30233032

30243033
/*
30253034
* CACHE_EXT_ENDOFINDEXENTRIES must be written as the last entry before the SHA1

0 commit comments

Comments
 (0)