Add rest option that allows to add string into ref_array_item
and then put it into specific place of the output.
We are using it now in cat-file command: user could put anything
in the input after objectname, and it will appear in the output
in place of %(rest).

Signed-off-by: Olga Telezhnaia <olyatelezhn...@gmail.com>
---
 ref-filter.c | 4 ++++
 ref-filter.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/ref-filter.c b/ref-filter.c
index 736e1f9cc38fc..46bf89b3330de 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -485,6 +485,7 @@ static struct {
        { "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
        { "then", SOURCE_NONE },
        { "else", SOURCE_NONE },
+       { "rest", SOURCE_NONE },
 };
 
 #define REF_FORMATTING_STATE_INIT  { 0, NULL }
@@ -1623,6 +1624,9 @@ static int populate_value(struct ref_array_item *ref, 
struct strbuf *err)
                        else
                                v->s = xstrdup(" ");
                        continue;
+               } else if (starts_with(name, "rest")) {
+                       v->s = xstrdup(ref->request_rest ? ref->request_rest : 
"");
+                       continue;
                } else if (starts_with(name, "align")) {
                        v->handler = align_atom_handler;
                        v->s = xstrdup("");
diff --git a/ref-filter.h b/ref-filter.h
index 4d7d36e9f522d..aaeda9f324f5c 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -40,6 +40,7 @@ struct ref_array_item {
        const char *symref;
        struct commit *commit;
        struct atom_value *value;
+       const char *request_rest;
        char refname[FLEX_ARRAY];
 };
 

--
https://github.com/git/git/pull/568

Reply via email to