Update git blob include processor

- Update `path` to accept semicolon-delimited list of paths when `diff`
  option is used.
- Add `other` option for diffs.
This commit is contained in:
Gabriel Arazas 2023-04-09 13:37:29 +08:00
parent fbe1feb221
commit aed9896539
2 changed files with 11 additions and 2 deletions

View File

@ -24,10 +24,14 @@ If the resulting operation ends in an error (i.e., non-existing revision, file,
== Attributes
- `path` is the filepath to be retrieved from the revision.
When used with `diff`, it changes into a semicolon-delimited (`;`) list of files to make diffs with multiple files.
- `context-lines` is the number of surrounding lines for the diff.
This is only effective if `diff` option is given.
- `other` is the other commit to be compared with.
This is only effective if `diff` option is given.
There's also a couple of link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options] for this component.
You can give the following options through `opts` attribute (i.e., `opts="diff,reverse"`).

View File

@ -19,11 +19,16 @@ class GitBlobIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
if attrs.key? 'diff-option'
options = {}
options[:paths] = [attrs['path']] if attrs.key? 'path'
options[:paths] = attrs['path'].split(';') if attrs.key? 'path'
options[:context_lines] = attrs['context-lines'] if attrs.key? 'context-lines'
options[:reverse] = true if attrs.key? 'reverse-option'
if attrs.key? 'other'
other = repo.rev_parse attrs['other'] || nil
reader.push_include git_object.diff(other, **options).patch
else
reader.push_include git_object.diff(**options).patch
end
else
inner_entry = case git_object.type
when :blob