From: Karthik Nayak Date: Tue, 28 Jul 2015 06:56:26 GMT Subject: [RFC/PATCH 01/11] ref-filter: add "%(objectname:size=X)" option Message-ID: <1438066594-5620-1-git-send-email-Karthik.188@gmail.com> In-Reply-To: From: Karthik Nayak Add support for %(objectname:size=X) where X is a number. This will print the first X characters of an objectname. The minimum value for X is 5. Hence any value lesser than 5 will default to 5 characters. Mentored-by: Christian Couder Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak --- ref-filter.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ref-filter.c b/ref-filter.c index 0a34924..4c5e3f8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -196,6 +196,8 @@ static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned lo static int grab_objectname(const char *name, const unsigned char *sha1, struct atom_value *v) { + const char *p; + if (!strcmp(name, "objectname")) { char *s = xmalloc(41); strcpy(s, sha1_to_hex(sha1)); @@ -206,6 +208,13 @@ static int grab_objectname(const char *name, const unsigned char *sha1, v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); return 1; } + if (skip_prefix(name, "objectname:size=", &p)) { + unsigned int size = atoi(p); + if (size < 5) + size = 5; + v->s = xstrdup(find_unique_abbrev(sha1, size)); + return 1; + } return 0; } -- 2.4.6