Skip to content

Commit 33311fa

Browse files
telezhnayagitster
authored andcommitted
ref-filter: add deltabase option
Add new formatting option: deltabase. If the object is stored as a delta on-disk, this expands to the 40-hex sha1 of the delta base object. Otherwise, expands to the null sha1 (40 zeroes). We have same option in cat-file command. Hopefully, in the end I will remove formatting code from cat-file and reuse formatting parts from ref-filter. Signed-off-by: Olga Telezhnaia <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4ee22b commit 33311fa

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ref-filter.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ static int objectsize_atom_parser(const struct ref_format *format, struct used_a
246246
return 0;
247247
}
248248

249+
static int deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom,
250+
const char *arg, struct strbuf *err)
251+
{
252+
if (arg)
253+
return strbuf_addf_ret(err, -1, _("%%(deltabase) does not take arguments"));
254+
if (*atom->name == '*')
255+
oi_deref.info.delta_base_sha1 = oi_deref.delta_base_oid.hash;
256+
else
257+
oi.info.delta_base_sha1 = oi.delta_base_oid.hash;
258+
return 0;
259+
}
260+
249261
static int body_atom_parser(const struct ref_format *format, struct used_atom *atom,
250262
const char *arg, struct strbuf *err)
251263
{
@@ -437,6 +449,7 @@ static struct {
437449
{ "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },
438450
{ "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
439451
{ "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser },
452+
{ "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser },
440453
{ "tree", SOURCE_OBJ },
441454
{ "parent", SOURCE_OBJ },
442455
{ "numparent", SOURCE_OBJ, FIELD_ULONG },
@@ -888,7 +901,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
888901
} else if (!strcmp(name, "objectsize")) {
889902
v->value = oi->size;
890903
v->s = xstrfmt("%lu", oi->size);
891-
}
904+
} else if (!strcmp(name, "deltabase"))
905+
v->s = xstrdup(oid_to_hex(&oi->delta_base_oid));
892906
else if (deref)
893907
grab_objectname(name, &oi->oid, v, &used_atom[i]);
894908
}

0 commit comments

Comments
 (0)