From ebf2aca63475599bf68ff60d7e365f3bffae6445 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 9 Apr 2023 13:37:29 +0800 Subject: [PATCH] Update git blob include processor - Update `path` to accept semicolon-delimited list of paths when `diff` option is used. - Add `other` option for diffs. --- .../asciidoctor/git-blob-include-processor/README.adoc | 4 ++++ .../asciidoctor/git-blob-include-processor/extension.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gems/lib/asciidoctor/git-blob-include-processor/README.adoc b/gems/lib/asciidoctor/git-blob-include-processor/README.adoc index 101150e..2fc2dd7 100644 --- a/gems/lib/asciidoctor/git-blob-include-processor/README.adoc +++ b/gems/lib/asciidoctor/git-blob-include-processor/README.adoc @@ -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"`). diff --git a/gems/lib/asciidoctor/git-blob-include-processor/extension.rb b/gems/lib/asciidoctor/git-blob-include-processor/extension.rb index 2b51c4e..fee79ab 100644 --- a/gems/lib/asciidoctor/git-blob-include-processor/extension.rb +++ b/gems/lib/asciidoctor/git-blob-include-processor/extension.rb @@ -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' - reader.push_include git_object.diff(**options).patch + 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