Skip to content

Commit bda891e

Browse files
committed
Merge branch 'zh/ref-filter-raw-data'
Prepare the "ref-filter" machinery that drives the "--format" option of "git for-each-ref" and its friends to be used in "git cat-file --batch". * zh/ref-filter-raw-data: ref-filter: add %(rest) atom ref-filter: use non-const ref_format in *_atom_parser() ref-filter: --format=%(raw) support --perl ref-filter: add %(raw) atom ref-filter: add obj-type check in grab contents
2 parents 5c933f0 + b9dee07 commit bda891e

File tree

10 files changed

+465
-63
lines changed

10 files changed

+465
-63
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ and `date` to extract the named component. For email fields (`authoremail`,
235235
without angle brackets, and `:localpart` to get the part before the `@` symbol
236236
out of the trimmed email.
237237

238+
The raw data in an object is `raw`.
239+
240+
raw:size::
241+
The raw data size of the object.
242+
243+
Note that `--format=%(raw)` can not be used with `--python`, `--shell`, `--tcl`,
244+
because such language may not support arbitrary binary data in their string
245+
variable type.
246+
238247
The message in a commit or a tag object is `contents`, from which
239248
`contents:<part>` can be used to extract various parts out of:
240249

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int verify_tag(const char *name, const char *ref,
146146
const struct object_id *oid, void *cb_data)
147147
{
148148
int flags;
149-
const struct ref_format *format = cb_data;
149+
struct ref_format *format = cb_data;
150150
flags = GPG_VERIFY_VERBOSE;
151151

152152
if (format->format)

quote.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,23 @@ void perl_quote_buf(struct strbuf *sb, const char *src)
471471
strbuf_addch(sb, sq);
472472
}
473473

474+
void perl_quote_buf_with_len(struct strbuf *sb, const char *src, size_t len)
475+
{
476+
const char sq = '\'';
477+
const char bq = '\\';
478+
const char *c = src;
479+
const char *end = src + len;
480+
481+
strbuf_addch(sb, sq);
482+
while (c != end) {
483+
if (*c == sq || *c == bq)
484+
strbuf_addch(sb, bq);
485+
strbuf_addch(sb, *c);
486+
c++;
487+
}
488+
strbuf_addch(sb, sq);
489+
}
490+
474491
void python_quote_buf(struct strbuf *sb, const char *src)
475492
{
476493
const char sq = '\'';

quote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne
9595

9696
/* quoting as a string literal for other languages */
9797
void perl_quote_buf(struct strbuf *sb, const char *src);
98+
void perl_quote_buf_with_len(struct strbuf *sb, const char *src, size_t len);
9899
void python_quote_buf(struct strbuf *sb, const char *src);
99100
void tcl_quote_buf(struct strbuf *sb, const char *src);
100101
void basic_regex_quote_buf(struct strbuf *sb, const char *src);

0 commit comments

Comments
 (0)