@@ -293,7 +293,15 @@ checkout, when the `smudge` command is specified, the command is
293
293
fed the blob object from its standard input, and its standard
294
294
output is used to update the worktree file. Similarly, the
295
295
`clean` command is used to convert the contents of worktree file
296
- upon checkin.
296
+ upon checkin. By default these commands process only a single
297
+ blob and terminate. If a long running `process` filter is used
298
+ in place of `clean` and/or `smudge` filters, then Git can process
299
+ all blobs with a single filter command invocation for the entire
300
+ life of a single Git command, for example `git add --all`. If a
301
+ long running `process` filter is configured then it always takes
302
+ precedence over a configured single blob filter. See section
303
+ below for the description of the protocol used to communicate with
304
+ a `process` filter.
297
305
298
306
One use of the content filtering is to massage the content into a shape
299
307
that is more convenient for the platform, filesystem, and the user to use.
@@ -373,6 +381,153 @@ not exist, or may have different contents. So, smudge and clean commands
373
381
should not try to access the file on disk, but only act as filters on the
374
382
content provided to them on standard input.
375
383
384
+ Long Running Filter Process
385
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
386
+
387
+ If the filter command (a string value) is defined via
388
+ `filter.<driver>.process` then Git can process all blobs with a
389
+ single filter invocation for the entire life of a single Git
390
+ command. This is achieved by using a packet format (pkt-line,
391
+ see technical/protocol-common.txt) based protocol over standard
392
+ input and standard output as follows. All packets, except for the
393
+ "*CONTENT" packets and the "0000" flush packet, are considered
394
+ text and therefore are terminated by a LF.
395
+
396
+ Git starts the filter when it encounters the first file
397
+ that needs to be cleaned or smudged. After the filter started
398
+ Git sends a welcome message ("git-filter-client"), a list of supported
399
+ protocol version numbers, and a flush packet. Git expects to read a welcome
400
+ response message ("git-filter-server"), exactly one protocol version number
401
+ from the previously sent list, and a flush packet. All further
402
+ communication will be based on the selected version. The remaining
403
+ protocol description below documents "version=2". Please note that
404
+ "version=42" in the example below does not exist and is only there
405
+ to illustrate how the protocol would look like with more than one
406
+ version.
407
+
408
+ After the version negotiation Git sends a list of all capabilities that
409
+ it supports and a flush packet. Git expects to read a list of desired
410
+ capabilities, which must be a subset of the supported capabilities list,
411
+ and a flush packet as response:
412
+ ------------------------
413
+ packet: git> git-filter-client
414
+ packet: git> version=2
415
+ packet: git> version=42
416
+ packet: git> 0000
417
+ packet: git< git-filter-server
418
+ packet: git< version=2
419
+ packet: git< 0000
420
+ packet: git> capability=clean
421
+ packet: git> capability=smudge
422
+ packet: git> capability=not-yet-invented
423
+ packet: git> 0000
424
+ packet: git< capability=clean
425
+ packet: git< capability=smudge
426
+ packet: git< 0000
427
+ ------------------------
428
+ Supported filter capabilities in version 2 are "clean" and
429
+ "smudge".
430
+
431
+ Afterwards Git sends a list of "key=value" pairs terminated with
432
+ a flush packet. The list will contain at least the filter command
433
+ (based on the supported capabilities) and the pathname of the file
434
+ to filter relative to the repository root. Right after the flush packet
435
+ Git sends the content split in zero or more pkt-line packets and a
436
+ flush packet to terminate content. Please note, that the filter
437
+ must not send any response before it received the content and the
438
+ final flush packet.
439
+ ------------------------
440
+ packet: git> command=smudge
441
+ packet: git> pathname=path/testfile.dat
442
+ packet: git> 0000
443
+ packet: git> CONTENT
444
+ packet: git> 0000
445
+ ------------------------
446
+
447
+ The filter is expected to respond with a list of "key=value" pairs
448
+ terminated with a flush packet. If the filter does not experience
449
+ problems then the list must contain a "success" status. Right after
450
+ these packets the filter is expected to send the content in zero
451
+ or more pkt-line packets and a flush packet at the end. Finally, a
452
+ second list of "key=value" pairs terminated with a flush packet
453
+ is expected. The filter can change the status in the second list
454
+ or keep the status as is with an empty list. Please note that the
455
+ empty list must be terminated with a flush packet regardless.
456
+
457
+ ------------------------
458
+ packet: git< status=success
459
+ packet: git< 0000
460
+ packet: git< SMUDGED_CONTENT
461
+ packet: git< 0000
462
+ packet: git< 0000 # empty list, keep "status=success" unchanged!
463
+ ------------------------
464
+
465
+ If the result content is empty then the filter is expected to respond
466
+ with a "success" status and a flush packet to signal the empty content.
467
+ ------------------------
468
+ packet: git< status=success
469
+ packet: git< 0000
470
+ packet: git< 0000 # empty content!
471
+ packet: git< 0000 # empty list, keep "status=success" unchanged!
472
+ ------------------------
473
+
474
+ In case the filter cannot or does not want to process the content,
475
+ it is expected to respond with an "error" status.
476
+ ------------------------
477
+ packet: git< status=error
478
+ packet: git< 0000
479
+ ------------------------
480
+
481
+ If the filter experiences an error during processing, then it can
482
+ send the status "error" after the content was (partially or
483
+ completely) sent.
484
+ ------------------------
485
+ packet: git< status=success
486
+ packet: git< 0000
487
+ packet: git< HALF_WRITTEN_ERRONEOUS_CONTENT
488
+ packet: git< 0000
489
+ packet: git< status=error
490
+ packet: git< 0000
491
+ ------------------------
492
+
493
+ In case the filter cannot or does not want to process the content
494
+ as well as any future content for the lifetime of the Git process,
495
+ then it is expected to respond with an "abort" status at any point
496
+ in the protocol.
497
+ ------------------------
498
+ packet: git< status=abort
499
+ packet: git< 0000
500
+ ------------------------
501
+
502
+ Git neither stops nor restarts the filter process in case the
503
+ "error"/"abort" status is set. However, Git sets its exit code
504
+ according to the `filter.<driver>.required` flag, mimicking the
505
+ behavior of the `filter.<driver>.clean` / `filter.<driver>.smudge`
506
+ mechanism.
507
+
508
+ If the filter dies during the communication or does not adhere to
509
+ the protocol then Git will stop the filter process and restart it
510
+ with the next file that needs to be processed. Depending on the
511
+ `filter.<driver>.required` flag Git will interpret that as error.
512
+
513
+ After the filter has processed a blob it is expected to wait for
514
+ the next "key=value" list containing a command. Git will close
515
+ the command pipe on exit. The filter is expected to detect EOF
516
+ and exit gracefully on its own. Git will wait until the filter
517
+ process has stopped.
518
+
519
+ A long running filter demo implementation can be found in
520
+ `contrib/long-running-filter/example.pl` located in the Git
521
+ core repository. If you develop your own long running filter
522
+ process then the `GIT_TRACE_PACKET` environment variables can be
523
+ very helpful for debugging (see linkgit:git[1]).
524
+
525
+ Please note that you cannot use an existing `filter.<driver>.clean`
526
+ or `filter.<driver>.smudge` command with `filter.<driver>.process`
527
+ because the former two use a different inter process communication
528
+ protocol than the latter one.
529
+
530
+
376
531
Interaction between checkin/checkout attributes
377
532
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
378
533
0 commit comments