Skip to content

Commit 08a461f

Browse files
convert: add "status=delayed" to filter process protocol
Some `clean` / `smudge` filters might require a significant amount of time to process a single blob. During this process the Git checkout operation is blocked and Git needs to wait until the filter is done to continue with the checkout. Teach the filter process protocol (introduced in edcc858) to accept the status "delayed" as response to a filter request. Upon this response Git continues with the checkout operation. After the checkout operation Git calls "finish_delayed_checkout" which queries the filter for remaining blobs. If the filter is still working on the completion, then the filter is expected to block. If the filter has completed all remaining blobs then an empty response is expected. Git has a multiple code paths that checkout a blob. Support delayed checkouts only in `clone` (in unpack-trees.c) and `checkout` operations. Signed-off-by: Lars Schneider <[email protected]>
1 parent 8305728 commit 08a461f

9 files changed

Lines changed: 587 additions & 90 deletions

File tree

‎Documentation/gitattributes.txt‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ packet: git< capability=clean
425425
packet: git< capability=smudge
426426
packet: git< 0000
427427
------------------------
428-
Supported filter capabilities in version 2 are "clean" and
429-
"smudge".
428+
Supported filter capabilities in version 2 are "clean", "smudge",
429+
and "delay".
430430

431431
Afterwards Git sends a list of "key=value" pairs terminated with
432432
a flush packet. The list will contain at least the filter command
@@ -512,12 +512,77 @@ the protocol then Git will stop the filter process and restart it
512512
with the next file that needs to be processed. Depending on the
513513
`filter.<driver>.required` flag Git will interpret that as error.
514514

515-
After the filter has processed a blob it is expected to wait for
516-
the next "key=value" list containing a command. Git will close
515+
After the filter has processed a command it is expected to wait for
516+
a "key=value" list containing the next command. Git will close
517517
the command pipe on exit. The filter is expected to detect EOF
518518
and exit gracefully on its own. Git will wait until the filter
519519
process has stopped.
520520

521+
Delay
522+
^^^^^
523+
524+
If the filter supports the "delay" capability, then Git can send the
525+
flag "delay-able" after the filter command and pathname. This flag
526+
denotes that the filter can delay filtering the current blob (e.g. to
527+
compensate network latencies) by responding with no content but with
528+
the status "delayed" and a flush packet. Git will answer with a
529+
"delay-id", a number that identifies the blob, and a flush packet. The
530+
filter acknowledges this number with a "success" status and a flush
531+
packet.
532+
------------------------
533+
packet: git> command=smudge
534+
packet: git> pathname=path/testfile.dat
535+
packet: git> delay-able=1
536+
packet: git> 0000
537+
packet: git> CONTENT
538+
packet: git> 0000
539+
packet: git< status=delayed
540+
packet: git< 0000
541+
packet: git> delay-id=1
542+
packet: git> 0000
543+
packet: git< status=success
544+
packet: git< 0000
545+
------------------------
546+
547+
If the filter supports the "delay" capability then it must support the
548+
"list_available_blobs" command. If Git sends this command, then the
549+
filter is expected to return a list of "delay_ids" of blobs that are
550+
available. The list must be terminated with a flush packet followed
551+
by a "success" status that is also terminated with a flush packet. If
552+
no blobs for the delayed paths are available, yet, then the filter is
553+
expected to block the response until at least one blob becomes
554+
available. The filter can tell Git that it has no more delayed blobs
555+
by sending an empty list.
556+
------------------------
557+
packet: git> command=list_available_blobs
558+
packet: git> 0000
559+
packet: git< 7
560+
packet: git< 13
561+
packet: git< 0000
562+
packet: git< status=success
563+
packet: git< 0000
564+
------------------------
565+
566+
After Git received the "delay_ids", it will request the corresponding
567+
blobs again. These requests contain a "delay-id" and an empty content
568+
section. The filter is expected to respond with the smudged content
569+
in the usual way as explained above.
570+
------------------------
571+
packet: git> command=smudge
572+
packet: git> pathname=test-delay10.a
573+
packet: git> delay-id=0
574+
packet: git> 0000
575+
packet: git> 0000 # empty content!
576+
packet: git< status=success
577+
packet: git< 0000
578+
packet: git< SMUDGED_CONTENT
579+
packet: git< 0000
580+
packet: git< 0000
581+
------------------------
582+
583+
Example
584+
^^^^^^^
585+
521586
A long running filter demo implementation can be found in
522587
`contrib/long-running-filter/example.pl` located in the Git
523588
core repository. If you develop your own long running filter

‎builtin/checkout.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ static int checkout_paths(const struct checkout_opts *opts,
355355
state.force = 1;
356356
state.refresh_cache = 1;
357357
state.istate = &the_index;
358+
359+
enable_delayed_checkout(&state);
358360
for (pos = 0; pos < active_nr; pos++) {
359361
struct cache_entry *ce = active_cache[pos];
360362
if (ce->ce_flags & CE_MATCHED) {
@@ -369,6 +371,7 @@ static int checkout_paths(const struct checkout_opts *opts,
369371
pos = skip_same_name(ce, pos) - 1;
370372
}
371373
}
374+
errs |= finish_delayed_checkout(&state);
372375

373376
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
374377
die(_("unable to write new index file"));

‎cache.h‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,19 +1421,54 @@ const char *show_ident_date(const struct ident_split *id,
14211421
*/
14221422
extern int ident_cmp(const struct ident_split *, const struct ident_split *);
14231423

1424+
enum ce_delay_state {
1425+
CE_DELAY_DISABLED = 0,
1426+
CE_DELAY_AVAILABLE = 1,
1427+
CE_DELAY_APPLIED = 2,
1428+
CE_DELAY_RETRY = 3
1429+
};
1430+
1431+
struct delayed_checkout {
1432+
enum ce_delay_state state;
1433+
/* The value of "delay_id" has different meaning depending on the
1434+
* "state" variable:
1435+
* - CE_DELAY_DISABLED => "delay_id" not used.
1436+
* - CE_DELAY_AVAILABLE => "delay_id" is available to be presented
1437+
* to the filter in case the filter wants to
1438+
* delay the response of a blob.
1439+
* - CE_DELAY_APPLIED => "delay_id" was presented to and applied by
1440+
* the filter for a blob. The corresponding
1441+
* cache entry in stored in the "entries"
1442+
* array under the index "delay_id".
1443+
* - CE_DELAY_RETRY => Git requests a blob from the filter that
1444+
* was previously delayed using the "delay_id".
1445+
*/
1446+
int delay_id;
1447+
/* List of filter drivers that have delayed blobs. */
1448+
struct string_list filters;
1449+
/* Array of cache entries that have been delayed. */
1450+
struct cache_entry **entries;
1451+
int entries_nr;
1452+
int entries_alloc;
1453+
};
1454+
14241455
struct checkout {
14251456
struct index_state *istate;
14261457
const char *base_dir;
1458+
struct delayed_checkout *delayed_checkout;
14271459
int base_dir_len;
14281460
unsigned force:1,
14291461
quiet:1,
14301462
not_new:1,
14311463
refresh_cache:1;
14321464
};
1433-
#define CHECKOUT_INIT { NULL, "" }
1465+
#define CHECKOUT_INIT { NULL, "", NULL }
1466+
14341467

14351468
#define TEMPORARY_FILENAME_LENGTH 25
14361469
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
1470+
extern void enable_delayed_checkout(struct checkout *state);
1471+
extern int finish_delayed_checkout(struct checkout *state);
14371472

14381473
struct cache_def {
14391474
struct strbuf path;

0 commit comments

Comments
 (0)