]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-index: add 'sdir' index extension
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 30 Mar 2021 13:10:54 +0000 (13:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Mar 2021 19:57:46 +0000 (12:57 -0700)
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>
Documentation/technical/index-format.txt
read-cache.c

index 3b74c05647dbac90fb6d2071ca5915c69d029b10..65da0daaa5634ceab48a0a377167f58cf1c82f14 100644 (file)
@@ -392,3 +392,15 @@ The remaining data of each directory block is grouped by type:
        in this block of entries.
 
     - 32-bit count of cache entries in this block
+
+== Sparse Directory Entries
+
+  When using sparse-checkout in cone mode, some entire directories within
+  the index can be summarized by pointing to a tree object instead of the
+  entire expanded list of paths within that tree. An index containing such
+  entries is a "sparse index". Index format versions 4 and less were not
+  implemented with such entries in mind. Thus, for these versions, an
+  index containing sparse directory entries will include this extension
+  with signature { 's', 'd', 'i', 'r' }. Like the split-index extension,
+  tools should avoid interacting with a sparse index unless they understand
+  this extension.
index dd3980c12b5384b4d128d3259b8a2aaf05b531b9..b8f092d1b7eb7df497985a110a9a3ffd63b47f49 100644 (file)
@@ -47,6 +47,7 @@
 #define CACHE_EXT_FSMONITOR 0x46534D4E   /* "FSMN" */
 #define CACHE_EXT_ENDOFINDEXENTRIES 0x454F4945 /* "EOIE" */
 #define CACHE_EXT_INDEXENTRYOFFSETTABLE 0x49454F54 /* "IEOT" */
+#define CACHE_EXT_SPARSE_DIRECTORIES 0x73646972 /* "sdir" */
 
 /* changes that can be kept in $GIT_DIR/index (basically all extensions) */
 #define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
@@ -1763,6 +1764,10 @@ static int read_index_extension(struct index_state *istate,
        case CACHE_EXT_INDEXENTRYOFFSETTABLE:
                /* already handled in do_read_index() */
                break;
+       case CACHE_EXT_SPARSE_DIRECTORIES:
+               /* no content, only an indicator */
+               istate->sparse_index = 1;
+               break;
        default:
                if (*ext < 'A' || 'Z' < *ext)
                        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,
                if (err)
                        return -1;
        }
+       if (istate->sparse_index) {
+               if (write_index_ext_header(&c, &eoie_c, newfd, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0)
+                       return -1;
+       }
 
        /*
         * CACHE_EXT_ENDOFINDEXENTRIES must be written as the last entry before the SHA1