From patchwork Thu Nov 22 23:05:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul-Sebastian Ungureanu X-Patchwork-Id: 10694925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6702A14BD for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 577622C1BE for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EEB32C1E1; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CED652C1A2 for ; Thu, 22 Nov 2018 23:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407864AbeKWJrx (ORCPT ); Fri, 23 Nov 2018 04:47:53 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34187 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392559AbeKWJrx (ORCPT ); Fri, 23 Nov 2018 04:47:53 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so6435064wmd.1 for ; Thu, 22 Nov 2018 15:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gRXteZlaGNdhQmvKsvHbHO5vnsnp6IMoXuH2OBuyVZI=; b=ELaTew56zXhjQOayT55q0kVop7K5FzMgCOxynAm8D/CEeA1pig9QQ55K7YvzrCGpXl EHS6b4TYWgxsnA+miQyYrqAxDVA6uDpYmrXULrfU10FA1bczCOZziggUlUdRHN9Ehlbw OEf823fPq9bQUH+lGyyH1kYwatMmcN8YMdG7GKsiYT7OiY0YARBy1l6W8yRyqwixHyUT sS5mrJY/6gDj5BHhBYpLn9eCAkY8qB+SQAy99nuEtnU9wUzhO+1JTj4v1FfOydBwSwnO 6jZlK82c+V+KsxCJEJ7Yj9kIObp2aHcPRzhsZo4wxX31yv2qqAOH/jCPhbbtHJ7UCYRd jFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gRXteZlaGNdhQmvKsvHbHO5vnsnp6IMoXuH2OBuyVZI=; b=n0EKM/mwJgOM+siEie8FHR9y9vl71r1mC+lL2QgjsXHu4QdsHch18dYcG+1w7EZ1qt lVaVrF0tcSZqP0us+xQk4SNMKD1YsjcwcPMTyFDdbytTPPIkJ8TSVcu//rp1xf4DqquP iRXF7kYmlaNQDs30QU2jnoH8//TPgobPiR/bIKqVU5XvwcgRUJjGvcarN1ZE6bgcVlHe 8Zl+3yQfP3T3mMy12Za962p2oj/OzCaN+A2QXgsGwNJpaKYRHJydGajSxnkmf2s6ynr2 4TEg3Uv0DUpuAlohLDAfDHJB8xI7xpsz3qnhiMfVFA8XfcHRrbxgOChvqlQ60vayg1CR yM7g== X-Gm-Message-State: AA+aEWYPl49vYfuJsHfAAfRBjNlSmd2FR4uKf9y6EvAIjgBsPZeo4eKs 9nK/0KAAL+faublU5NNhSeIFb1lq X-Google-Smtp-Source: AFSGD/V3jn99h9JU0ao9IDoGrbKqw/LOEM5DMGv0fvf3bWO4TzEgXdBBGH2iCevN9jFnYFCoc+MtSA== X-Received: by 2002:a1c:85d2:: with SMTP id h201mr10732290wmd.151.1542927972132; Thu, 22 Nov 2018 15:06:12 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:11 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 01/22] sha1-name.c: add `get_oidf()` which acts like `get_oid()` Date: Fri, 23 Nov 2018 01:05:21 +0200 Message-Id: X-Mailer: git-send-email 2.19.1.878.g0482332a22 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Compared to `get_oid()`, `get_oidf()` has as parameters a pointer to `object_id`, a printf format string and additional arguments. This will help simplify the code in subsequent commits. Original-idea-by: Johannes Schindelin Signed-off-by: Paul-Sebastian Ungureanu --- cache.h | 1 + sha1-name.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cache.h b/cache.h index 8b1ee42ae9..6f1a549489 100644 --- a/cache.h +++ b/cache.h @@ -1334,6 +1334,7 @@ struct object_context { GET_OID_BLOB) extern int get_oid(const char *str, struct object_id *oid); +extern int get_oidf(struct object_id *oid, const char *fmt, ...); extern int get_oid_commit(const char *str, struct object_id *oid); extern int get_oid_committish(const char *str, struct object_id *oid); extern int get_oid_tree(const char *str, struct object_id *oid); diff --git a/sha1-name.c b/sha1-name.c index faa60f69e3..cf0e8a3f85 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1542,6 +1542,25 @@ int get_oid(const char *name, struct object_id *oid) return get_oid_with_context(name, 0, oid, &unused); } +/* + * This returns a non-zero value if the string (built using printf + * format and the given arguments) is not a valid object. + */ +int get_oidf(struct object_id *oid, const char *fmt, ...) +{ + va_list ap; + int ret; + struct strbuf sb = STRBUF_INIT; + + va_start(ap, fmt); + strbuf_vaddf(&sb, fmt, ap); + va_end(ap); + + ret = get_oid(sb.buf, oid); + strbuf_release(&sb); + + return ret; +} /* * Many callers know that the user meant to name a commit-ish by