Skip to content

Commit

Permalink
Merge branch 'zh/ref-filter-raw-data'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Aug 24, 2021
2 parents 5c933f0 + b9dee07 commit bda891e
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 63 deletions.
9 changes: 9 additions & 0 deletions Documentation/git-for-each-ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ and `date` to extract the named component. For email fields (`authoremail`,
without angle brackets, and `:localpart` to get the part before the `@` symbol
out of the trimmed email.

The raw data in an object is `raw`.

raw:size::
The raw data size of the object.

Note that `--format=%(raw)` can not be used with `--python`, `--shell`, `--tcl`,
because such language may not support arbitrary binary data in their string
variable type.

The message in a commit or a tag object is `contents`, from which
`contents:<part>` can be used to extract various parts out of:

Expand Down
2 changes: 1 addition & 1 deletion builtin/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static int verify_tag(const char *name, const char *ref,
const struct object_id *oid, void *cb_data)
{
int flags;
const struct ref_format *format = cb_data;
struct ref_format *format = cb_data;
flags = GPG_VERIFY_VERBOSE;

if (format->format)
Expand Down
17 changes: 17 additions & 0 deletions quote.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,23 @@ void perl_quote_buf(struct strbuf *sb, const char *src)
strbuf_addch(sb, sq);
}

void perl_quote_buf_with_len(struct strbuf *sb, const char *src, size_t len)
{
const char sq = '\'';
const char bq = '\\';
const char *c = src;
const char *end = src + len;

strbuf_addch(sb, sq);
while (c != end) {
if (*c == sq || *c == bq)
strbuf_addch(sb, bq);
strbuf_addch(sb, *c);
c++;
}
strbuf_addch(sb, sq);
}

void python_quote_buf(struct strbuf *sb, const char *src)
{
const char sq = '\'';
Expand Down
1 change: 1 addition & 0 deletions quote.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne

/* quoting as a string literal for other languages */
void perl_quote_buf(struct strbuf *sb, const char *src);
void perl_quote_buf_with_len(struct strbuf *sb, const char *src, size_t len);
void python_quote_buf(struct strbuf *sb, const char *src);
void tcl_quote_buf(struct strbuf *sb, const char *src);
void basic_regex_quote_buf(struct strbuf *sb, const char *src);
Expand Down
Loading

0 comments on commit bda891e

Please sign in to comment.