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 From patchwork Thu Nov 22 23:05:22 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: 10694927 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 8C1601926 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 7C4272C1A6 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ECF62C1D6; 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 F30792C1A6 for ; Thu, 22 Nov 2018 23:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438942AbeKWJry (ORCPT ); Fri, 23 Nov 2018 04:47:54 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38424 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392523AbeKWJry (ORCPT ); Fri, 23 Nov 2018 04:47:54 -0500 Received: by mail-wr1-f65.google.com with SMTP id v13so7167726wrw.5 for ; Thu, 22 Nov 2018 15:06:14 -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=Rjnnj9TRwqeyN5UUhaUTnY9uBMV8NNt3+VQkPm2ty4w=; b=czxhzeZhJZWkk/kbMzKFkueZ+hL13UuJ2m4Y0Ew0I2J/QzCVeUsm/8ijrPO1Z8JdnT ixC9aZoOWp1uF4OCnwcpWvI4+KBqllWSCK060BKHLvvZKihcw2wBNhn3TGQg1MZXx+u1 H77037zpjXotcf8iXGmf+XTKyS2tSv4GP6JmvHtLlXUc5s1zVCmRUkSFkDPRD+eZpF4L 8mlLdFOV4dvFGMDUkXPt09f2Sz5b56E/SsFDyqO0AhCgmpMlXnp220lFIHAXtFy188pr DhxprI8WSMwJdqRRitaw1gz7g+LOAVeSKVGRujbdydQ3Do4Qb9c5+oTswjZQda5Ka0KN 5dpw== 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=Rjnnj9TRwqeyN5UUhaUTnY9uBMV8NNt3+VQkPm2ty4w=; b=ubn4Bl51fk7I+tA/cjYX80cygx5nMhiMMLd4LYi26wQaLZY3ftVPVE7CJeKtdpZEaV i1OEN827UWTAIBjNtdnOMN79HCFY98y1Rjwk8clsMqHYwPZ87BU/MgFBznLCcFwEhwM7 YR9Ai3tXj7506XJBaOA2H1dQlru8WjLjxLh3MLaAIIungidRNgfJNqA4PatNAN4fRmzH rZqcDhplqA56PgWhH8NgTvMdN5rbASFUq1Iex2a4qsSTWYFAOuNGhD4cJv8LyvxzMURg 98mqUn9mD/TqFOrXz2TDz4Oud7LbLF4O/hR+5CldgJim433f/UPQBGC3EIuA7TiFSjwM xcrg== X-Gm-Message-State: AA+aEWb8C+OdDG/hqpmGUHnHkDR8oueYMwD878CUJXpwcfBmLNzyDYI5 XRHgHf4jCOHxomy1MRR4IIZMNbC2 X-Google-Smtp-Source: AFSGD/X3TKSAgHAe24LIPLsGOlr4iX9IyYcaFhKR2V4HbwymzI9R1NyecBLikKRhCbPWXoxAsNksgA== X-Received: by 2002:adf:ef0d:: with SMTP id e13mr11331541wro.29.1542927973371; Thu, 22 Nov 2018 15:06:13 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:12 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 02/22] strbuf.c: add `strbuf_join_argv()` Date: Fri, 23 Nov 2018 01:05:22 +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 Implement `strbuf_join_argv()` to join arguments into a strbuf. Signed-off-by: Paul-Sebastian Ungureanu --- strbuf.c | 15 +++++++++++++++ strbuf.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/strbuf.c b/strbuf.c index f6a6cf78b9..82e90f1dfe 100644 --- a/strbuf.c +++ b/strbuf.c @@ -268,6 +268,21 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) strbuf_setlen(sb, sb->len + sb2->len); } +const char *strbuf_join_argv(struct strbuf *buf, + int argc, const char **argv, char delim) +{ + if (!argc) + return buf->buf; + + strbuf_addstr(buf, *argv); + while (--argc) { + strbuf_addch(buf, delim); + strbuf_addstr(buf, *(++argv)); + } + + return buf->buf; +} + void strbuf_addchars(struct strbuf *sb, int c, size_t n) { strbuf_grow(sb, n); diff --git a/strbuf.h b/strbuf.h index fc40873b65..be02150df3 100644 --- a/strbuf.h +++ b/strbuf.h @@ -288,6 +288,13 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) */ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2); +/** + * Join the arguments into a buffer. `delim` is put between every + * two arguments. + */ +const char *strbuf_join_argv(struct strbuf *buf, int argc, + const char **argv, char delim); + /** * This function can be used to expand a format string containing * placeholders. To that end, it parses the string and calls the specified From patchwork Thu Nov 22 23:05:23 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: 10694931 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 B48DB18F0 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 A315A2C1BB for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94E6C2C1D6; 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 204912C1BB for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439012AbeKWJrz (ORCPT ); Fri, 23 Nov 2018 04:47:55 -0500 Received: from mail-wm1-f41.google.com ([209.85.128.41]:33529 "EHLO mail-wm1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407865AbeKWJrz (ORCPT ); Fri, 23 Nov 2018 04:47:55 -0500 Received: by mail-wm1-f41.google.com with SMTP id 79so10466135wmo.0 for ; Thu, 22 Nov 2018 15:06:15 -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=Lp+nls5cK1oTcQpKaKojqHRpT4EgXFuw040N/kyzjtQ=; b=lvyNAjbsSkSMy4vl0a22A7lHh1Nxg/diTG2gWAL0OqQFqKJqOJ1IWL8VRkw+56iJWN W+hPUoNQUbbhYkQB2cl1Dny5XCweKH6M9+f0jsTOGfkDoNclu4nftBNBWhH9qnamnIJg L5E62YJfilgXnO5uHFXpGPsJPMRXY2q2Ic9aWI4B5FOfW9t93R2fh3FQ6XyjCQjOROup sWAOLmCn+slIUepd3zq8yAKjLtqYXoJRP/MEXPjMhWNGprGcURjUJOAjpdO6uCZGXJhG wNUa40Lfx015niYK1YFsbKchP5dJBzpKX+JtIIDiqOP21Z6NnAJoWpvM1zBO/S9gfAz3 9UMg== 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=Lp+nls5cK1oTcQpKaKojqHRpT4EgXFuw040N/kyzjtQ=; b=f2ryQi1wMbn7goOLgSZ6gr6lt8Rm3jsaf+yx5I3WYyA1oNm3TP6iHIuWQbh4syhfnQ 9y/M80kfTs9PrmnmXZnrKWWa3/g25fj6WcS0taMJYKwUZgoKZGFjky05sSoghyu99T7E md/l/6yVgqSMlmUvRYYycEJur8VGzW0jndl2MoTGEnC3CWjvlor8Uv8t31aGhjhKzafk y5veyFv8SOvPq1TnTt89lfhcKOdqyh4Uw7LPmSsE6nx/N2+cRGpWO4gJTRTfyTSQoN8r v84vwtBDPsH4SRa4YbzgixKCfp3WD1sI0cDAm22B6NbqoQQJwXlSErgjBbwSUUebVmDt C96g== X-Gm-Message-State: AGRZ1gLESblAL4bDAD10DS2uChZjwqkZRxKgOQLZmMTittQfjJQmMpVL aofiSgcFKsYEIZ+wG+TiG10uo03x X-Google-Smtp-Source: AJdET5ejfk42WJkK4VW9bS1njcKMDv1VEFQH+3WS4/WYLwl6ADWV2qmtQv77UgX8fmsAwsvPlJhybw== X-Received: by 2002:a1c:87cc:: with SMTP id j195mr11224761wmd.2.1542927974436; Thu, 22 Nov 2018 15:06:14 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:13 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 03/22] strbuf.c: add `strbuf_insertf()` and `strbuf_vinsertf()` Date: Fri, 23 Nov 2018 01:05:23 +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 Implement `strbuf_insertf()` and `strbuf_vinsertf()` to insert data using a printf format string. Original-idea-by: Johannes Schindelin Signed-off-by: Paul-Sebastian Ungureanu --- strbuf.c | 36 ++++++++++++++++++++++++++++++++++++ strbuf.h | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/strbuf.c b/strbuf.c index 82e90f1dfe..bfbbdadbf3 100644 --- a/strbuf.c +++ b/strbuf.c @@ -249,6 +249,42 @@ void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) strbuf_splice(sb, pos, 0, data, len); } +void strbuf_vinsertf(struct strbuf *sb, size_t pos, const char *fmt, va_list ap) +{ + int len, len2; + char save; + va_list cp; + + if (pos > sb->len) + die("`pos' is too far after the end of the buffer"); + va_copy(cp, ap); + len = vsnprintf(sb->buf + sb->len, 0, fmt, cp); + va_end(cp); + if (len < 0) + BUG("your vsnprintf is broken (returned %d)", len); + if (!len) + return; /* nothing to do */ + if (unsigned_add_overflows(sb->len, len)) + die("you want to use way too much memory"); + strbuf_grow(sb, len); + memmove(sb->buf + pos + len, sb->buf + pos, sb->len - pos); + /* vsnprintf() will append a NUL, overwriting one of our characters */ + save = sb->buf[pos + len]; + len2 = vsnprintf(sb->buf + pos, sb->alloc - sb->len, fmt, ap); + sb->buf[pos + len] = save; + if (len2 != len) + BUG("your vsnprintf is broken (returns inconsistent lengths)"); + strbuf_setlen(sb, sb->len + len); +} + +void strbuf_insertf(struct strbuf *sb, size_t pos, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + strbuf_vinsertf(sb, pos, fmt, ap); + va_end(ap); +} + void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) { strbuf_splice(sb, pos, len, "", 0); diff --git a/strbuf.h b/strbuf.h index be02150df3..8f8fe01e68 100644 --- a/strbuf.h +++ b/strbuf.h @@ -244,6 +244,15 @@ void strbuf_addchars(struct strbuf *sb, int c, size_t n); */ void strbuf_insert(struct strbuf *sb, size_t pos, const void *, size_t); +/** + * Insert data to the given position of the buffer giving a printf format + * string. The contents will be shifted, not overwritten. + */ +void strbuf_vinsertf(struct strbuf *sb, size_t pos, const char *fmt, + va_list ap); + +void strbuf_insertf(struct strbuf *sb, size_t pos, const char *fmt, ...); + /** * Remove given amount of data from a given position of the buffer. */ From patchwork Thu Nov 22 23:05:24 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: 10694929 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 C3D5B417B 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 B3A552C1BE for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5C3C2C1A2; 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 44CD92C1A2 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439018AbeKWJr6 (ORCPT ); Fri, 23 Nov 2018 04:47:58 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55323 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438981AbeKWJr4 (ORCPT ); Fri, 23 Nov 2018 04:47:56 -0500 Received: by mail-wm1-f65.google.com with SMTP id y139so10252590wmc.5 for ; Thu, 22 Nov 2018 15:06:16 -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=5pilT/NU1GdURabZb9gUW0Wr4+xXmntPeWH+1+87L8Y=; b=rdYRRr9ymbryOgM5teZoGloQpqUgAzobCUMN9ZTAIDDqUFUZNtz+t1LOufVrFusEUN 0FnfWaU9fcism0fXOEb9P0R+CeizF8RzjInTC3XYalu5wLK1iz+S6ee0lJxGtCb/rcMr 2qVATbx04dKrMTzNgL3xlqwsaWcevtxD3lGAiw2kj7AYFZK4a8te8PSuixSdixoespVj kQ/ae06oicuzF//rcavs4mzsgZvcXUOBwkljHLvEJuIrODQ2Hq8JNMYgQTm7fJPOjJfz UmqzkcmHlkyE0tn8D2bmtHX56JlzDH5miF8x/Y/OXwjCP0rt+ZgVlKHBAXc6JW/lKMxb XqcQ== 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=5pilT/NU1GdURabZb9gUW0Wr4+xXmntPeWH+1+87L8Y=; b=iLHu2U08PsFkQpbbhvwge493jQAbiHJb52cqDnOz4olI0Amqb2ZPjBXs521V/h35lc b1BqcBzDAzTeWeUs0NN3fZw8xfvk3YouIE1NrogPqaZCkT0lAm3DBN8CKRNzdFG49ElI Q5bTH0ezm5xSrNNO6netkBhJtLWoEkSheuszlDuKhJiuuv/WMo0DfJtHTR+PrxSd+Mgp RhF7p1Kl0W4YVrZCnUjH2Sri4EKacz1dOzIHszruZsjG80/i2aFH7XQUhbvdP5QLrql+ 6G+wXYh/8UMC4wMlE/c541O6RJtx012J+VONajuytS1HWQcmiSUffekF6aYGzrozlB2l 3eLg== X-Gm-Message-State: AGRZ1gJ+a2gUDBXYElEd1nxxwvDPcodhgAQqy4dOTMIHYqqq7/Qkx59U 67TlBhysyRkkytFY41yGx9FZXA/6 X-Google-Smtp-Source: AJdET5e9cii04jkW+tsVXBCLOxobrP5enhKAuUjcNk/Zavc/5WPJkLtLpl27spqsXSt/mmrC7mWcUQ== X-Received: by 2002:a1c:45:: with SMTP id 66-v6mr10901013wma.89.1542927975446; Thu, 22 Nov 2018 15:06:15 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:14 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 04/22] stash: improve option parsing test coverage Date: Fri, 23 Nov 2018 01:05:24 +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 From: Joel Teichroeb In preparation for converting the stash command incrementally to a builtin command, this patch improves test coverage of the option parsing. Both for having too many parameters, or too few. Signed-off-by: Joel Teichroeb Signed-off-by: Paul-Sebastian Ungureanu --- t/t3903-stash.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index cd216655b9..4f8aa56021 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -444,6 +444,36 @@ test_expect_failure 'stash file to directory' ' test foo = "$(cat file/file)" ' +test_expect_success 'giving too many ref arguments does not modify files' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + echo foo >file2 && + git stash && + echo bar >file2 && + git stash && + test-tool chmtime =123456789 file2 && + for type in apply pop "branch stash-branch" + do + test_must_fail git stash $type stash@{0} stash@{1} 2>err && + test_i18ngrep "Too many revisions" err && + test 123456789 = $(test-tool chmtime -g file2) || return 1 + done +' + +test_expect_success 'drop: too many arguments errors out (does nothing)' ' + git stash list >expect && + test_must_fail git stash drop stash@{0} stash@{1} 2>err && + test_i18ngrep "Too many revisions" err && + git stash list >actual && + test_cmp expect actual +' + +test_expect_success 'show: too many arguments errors out (does nothing)' ' + test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out && + test_i18ngrep "Too many revisions" err && + test_must_be_empty out +' + test_expect_success 'stash create - no changes' ' git stash clear && test_when_finished "git reset --hard HEAD" && @@ -479,6 +509,11 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' ' test $(git ls-files --modified | wc -l) -eq 1 ' +test_expect_success 'stash branch complains with no arguments' ' + test_must_fail git stash branch 2>err && + test_i18ngrep "No branch name specified" err +' + test_expect_success 'stash show format defaults to --stat' ' git stash clear && test_when_finished "git reset --hard HEAD" && From patchwork Thu Nov 22 23:05:25 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: 10694941 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 EDD3314BD for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE8842C19A for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D343E2C1BE; Thu, 22 Nov 2018 23:06:30 +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 666042C19A for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439020AbeKWJr7 (ORCPT ); Fri, 23 Nov 2018 04:47:59 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:32851 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439013AbeKWJr6 (ORCPT ); Fri, 23 Nov 2018 04:47:58 -0500 Received: by mail-wm1-f65.google.com with SMTP id 79so10466175wmo.0 for ; Thu, 22 Nov 2018 15:06:17 -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=7IwLyEiVNgHsVpd7nleD2lClFGx3fHtkemRezojKKM8=; b=JYL52DBJtHcIVQOBrGZntoz4GIBTAvAB/FtTgsIBY2EX93jCYBES8K6ejk8ki9MWrl dLVJvGrgQJjyyY4DqPlwmfsrmZfouGx/6cxkSxAOIga/Wj3xI/ukJFrgEZ2/Ag9njKum /cBn6oNCVTNsCUb7umOG7GG3Bib/PtWkK1rLNEk55cSYdEF2eZa95dJqZ3IDDT/nZats CjqHwmvVaURMpCsPkyIN9m8ZggD7LHszV1AWUYhb12Tem3jfI0wWjwVMcu/HM7WX6aTk xGhgR4Mk724i2Cv7Z3VvhI5BMt+F8A2Os9/i2r6H+MKfkJftQWPF6+eUnCztIHeTj3DS dtbQ== 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=7IwLyEiVNgHsVpd7nleD2lClFGx3fHtkemRezojKKM8=; b=Don/PQ2jpWwIb/qCwxRdpbAQ5Xxowy9duTpLFIm4SHmMKjdzCrAODENgNo+g5GpdpP c9Fjpj/bS4FL7MiDuEoSUoM6thdAunGYzAtp7rO9U1BEeYCn0zQxING5/SCaU4LKZbUt REbMhxONF70i9x1aMPqEe1FBBEA5G8r+nxD0vL+h7r/1MYuKNS1PD6Z62W5ZMz+NJ2bh ryG6jSWW3PTC7YckiO3Zg7LR29Gv02Coj8GwBlV7PZsVGfNxuhZ1vOF5wNh+g2Dns4XQ Ke1/hzu1YbUXQKNqjcmXwTX5B0Tq1SDWhjfGjJZVJlzQAA0gvv3C3ZPK8QK8pvYTs+72 9YzQ== X-Gm-Message-State: AGRZ1gJNZjO0eY5yxumCK8XU8Se6HYGllXIf7TmMD/c3HSYjkaamDoAc liZAY2Kh1adXdGSI6Ko1CusLnj14 X-Google-Smtp-Source: AJdET5f+RP4LnD8v5r1iv2nSruEY9FFOR7isK1PYs7bhz/m9JgeJ9jenPZ928rEDeRcBiHYKBL36aw== X-Received: by 2002:a1c:9a46:: with SMTP id c67mr10743521wme.21.1542927976526; Thu, 22 Nov 2018 15:06:16 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:15 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 05/22] t3903: modernize style Date: Fri, 23 Nov 2018 01:05:25 +0200 Message-Id: <7784ea24aa1ada5c5cbd9407a16c870b06a43d6c.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Remove whitespaces after redirection operators and wrap long lines. Signed-off-by: Paul-Sebastian Ungureanu --- t/t3903-stash.sh | 120 ++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 4f8aa56021..098a387a82 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -8,22 +8,22 @@ test_description='Test git stash' . ./test-lib.sh test_expect_success 'stash some dirty working directory' ' - echo 1 > file && + echo 1 >file && git add file && echo unrelated >other-file && git add other-file && test_tick && git commit -m initial && - echo 2 > file && + echo 2 >file && git add file && - echo 3 > file && + echo 3 >file && test_tick && git stash && git diff-files --quiet && git diff-index --cached --quiet HEAD ' -cat > expect << EOF +cat >expect < output && + git diff stash^2..stash >output && test_cmp expect output ' @@ -74,7 +74,7 @@ test_expect_success 'apply stashed changes' ' test_expect_success 'apply stashed changes (including index)' ' git reset --hard HEAD^ && - echo 6 > other-file && + echo 6 >other-file && git add other-file && test_tick && git commit -m other-file && @@ -99,12 +99,12 @@ test_expect_success 'stash drop complains of extra options' ' test_expect_success 'drop top stash' ' git reset --hard && - git stash list > stashlist1 && - echo 7 > file && + git stash list >expected && + echo 7 >file && git stash && git stash drop && - git stash list > stashlist2 && - test_cmp stashlist1 stashlist2 && + git stash list >actual && + test_cmp expected actual && git stash apply && test 3 = $(cat file) && test 1 = $(git show :file) && @@ -113,9 +113,9 @@ test_expect_success 'drop top stash' ' test_expect_success 'drop middle stash' ' git reset --hard && - echo 8 > file && + echo 8 >file && git stash && - echo 9 > file && + echo 9 >file && git stash && git stash drop stash@{1} && test 2 = $(git stash list | wc -l) && @@ -160,7 +160,7 @@ test_expect_success 'stash pop' ' test 0 = $(git stash list | wc -l) ' -cat > expect << EOF +cat >expect < expect1 << EOF +cat >expect1 < expect2 << EOF +cat >expect2 < file && + echo foo >file && git commit file -m first && - echo bar > file && - echo bar2 > file2 && + echo bar >file && + echo bar2 >file2 && git add file2 && git stash && - echo baz > file && + echo baz >file && git commit file -m second && git stash branch stashbranch && test refs/heads/stashbranch = $(git symbolic-ref HEAD) && test $(git rev-parse HEAD) = $(git rev-parse master^) && - git diff --cached > output && + git diff --cached >output && test_cmp expect output && - git diff > output && + git diff >output && test_cmp expect1 output && git add file && git commit -m alternate\ second && - git diff master..stashbranch > output && + git diff master..stashbranch >output && test_cmp output expect2 && test 0 = $(git stash list | wc -l) ' test_expect_success 'apply -q is quiet' ' - echo foo > file && + echo foo >file && git stash && - git stash apply -q > output.out 2>&1 && + git stash apply -q >output.out 2>&1 && test_must_be_empty output.out ' test_expect_success 'save -q is quiet' ' - git stash save --quiet > output.out 2>&1 && + git stash save --quiet >output.out 2>&1 && test_must_be_empty output.out ' test_expect_success 'pop -q is quiet' ' - git stash pop -q > output.out 2>&1 && + git stash pop -q >output.out 2>&1 && test_must_be_empty output.out ' test_expect_success 'pop -q --index works and is quiet' ' - echo foo > file && + echo foo >file && git add file && git stash save --quiet && - git stash pop -q --index > output.out 2>&1 && + git stash pop -q --index >output.out 2>&1 && test foo = "$(git show :file)" && test_must_be_empty output.out ' test_expect_success 'drop -q is quiet' ' git stash && - git stash drop -q > output.out 2>&1 && + git stash drop -q >output.out 2>&1 && test_must_be_empty output.out ' test_expect_success 'stash -k' ' - echo bar3 > file && - echo bar4 > file2 && + echo bar3 >file && + echo bar4 >file2 && git add file2 && git stash -k && test bar,bar4 = $(cat file),$(cat file2) ' test_expect_success 'stash --no-keep-index' ' - echo bar33 > file && - echo bar44 > file2 && + echo bar33 >file && + echo bar44 >file2 && git add file2 && git stash --no-keep-index && test bar,bar2 = $(cat file),$(cat file2) ' test_expect_success 'stash --invalid-option' ' - echo bar5 > file && - echo bar6 > file2 && + echo bar5 >file && + echo bar6 >file2 && git add file2 && test_must_fail git stash --invalid-option && test_must_fail git stash save --invalid-option && @@ -486,11 +486,12 @@ test_expect_success 'stash branch - no stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && STASH_ID=$(git stash create) && git reset --hard && git stash branch stash-branch ${STASH_ID} && - test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && + test_when_finished "git reset --hard HEAD && git checkout master && + git branch -D stash-branch" && test $(git ls-files --modified | wc -l) -eq 1 ' @@ -498,14 +499,15 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && git stash && test_when_finished "git stash drop" && - echo bar >> file && + echo bar >>file && STASH_ID=$(git stash create) && git reset --hard && git stash branch stash-branch ${STASH_ID} && - test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && + test_when_finished "git reset --hard HEAD && git checkout master && + git branch -D stash-branch" && test $(git ls-files --modified | wc -l) -eq 1 ' @@ -518,10 +520,10 @@ test_expect_success 'stash show format defaults to --stat' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && git stash && test_when_finished "git stash drop" && - echo bar >> file && + echo bar >>file && STASH_ID=$(git stash create) && git reset --hard && cat >expected <<-EOF && @@ -536,10 +538,10 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && git stash && test_when_finished "git stash drop" && - echo bar >> file && + echo bar >>file && STASH_ID=$(git stash create) && git reset --hard && echo "1 0 file" >expected && @@ -551,10 +553,10 @@ test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && git stash && test_when_finished "git stash drop" && - echo bar >> file && + echo bar >>file && STASH_ID=$(git stash create) && git reset --hard && cat >expected <<-EOF && @@ -574,7 +576,7 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && STASH_ID=$(git stash create) && git reset --hard && echo "1 0 file" >expected && @@ -586,7 +588,7 @@ test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && - echo foo >> file && + echo foo >>file && STASH_ID=$(git stash create) && git reset --hard && cat >expected <<-EOF && @@ -606,9 +608,9 @@ test_expect_success 'stash drop - fail early if specified stash is not a stash r git stash clear && test_when_finished "git reset --hard HEAD && git stash clear" && git reset --hard && - echo foo > file && + echo foo >file && git stash && - echo bar > file && + echo bar >file && git stash && test_must_fail git stash drop $(git rev-parse stash@{0}) && git stash pop && @@ -620,9 +622,9 @@ test_expect_success 'stash pop - fail early if specified stash is not a stash re git stash clear && test_when_finished "git reset --hard HEAD && git stash clear" && git reset --hard && - echo foo > file && + echo foo >file && git stash && - echo bar > file && + echo bar >file && git stash && test_must_fail git stash pop $(git rev-parse stash@{0}) && git stash pop && @@ -632,8 +634,8 @@ test_expect_success 'stash pop - fail early if specified stash is not a stash re test_expect_success 'ref with non-existent reflog' ' git stash clear && - echo bar5 > file && - echo bar6 > file2 && + echo bar5 >file && + echo bar6 >file2 && git add file2 && git stash && test_must_fail git rev-parse --quiet --verify does-not-exist && @@ -653,8 +655,8 @@ test_expect_success 'ref with non-existent reflog' ' test_expect_success 'invalid ref of the form stash@{n}, n >= N' ' git stash clear && test_must_fail git stash drop stash@{0} && - echo bar5 > file && - echo bar6 > file2 && + echo bar5 >file && + echo bar6 >file2 && git add file2 && git stash && test_must_fail git stash drop stash@{1} && @@ -724,7 +726,7 @@ test_expect_success 'stash apply shows status same as git status (relative to cu test_i18ncmp expect actual ' -cat > expect << EOF +cat >expect < HEAD && + echo file-not-a-ref >HEAD && git add HEAD && test_tick && git stash && git diff-files --quiet && git diff-index --cached --quiet HEAD && test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" && - git diff stash^..stash > output && + git diff stash^..stash >output && test_cmp expect output ' From patchwork Thu Nov 22 23:05:26 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: 10694935 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 424BC1926 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 309652C200 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 252C92C1E1; Thu, 22 Nov 2018 23:06:30 +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 B0A172C1A6 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439029AbeKWJsB (ORCPT ); Fri, 23 Nov 2018 04:48:01 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39613 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439014AbeKWJr7 (ORCPT ); Fri, 23 Nov 2018 04:47:59 -0500 Received: by mail-wm1-f65.google.com with SMTP id u13-v6so10458229wmc.4 for ; Thu, 22 Nov 2018 15:06:18 -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=I6sHroP/Z9s8Jcx/x7oZS3PQP23KJlBVV1glp/wJeZs=; b=ODwBXnJQjPa6GY8crZ/CWRlvvC8C4dIRpYvsC+xBVdOfuKZrpy7YAhc9B416w+AcUo 4Xrat/fp0cpwtn8lJHXwWtTIFZwiKKm+ApHMbbkw4Y4YRH2tAczKwmgfPoPNRk3y5pe3 wTIpawPNXWdwaD3GLo+597meOFVWfk+MU6ZX486qhs4EoRjhwFcq9YGtkSQ43oYHplCT NSTRmW5hWXku8XUiyeedNgyRF67Km511dJ1A6qxruw1Zu3k2jHAcfPr5hVTQeCrnE0Ce aLeL70EJViEmIvB/b/w0YXX7gc7hzsvgU2WChckyeyszTtPHszVeYRjVPvnmAVe/G+sg NO8g== 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=I6sHroP/Z9s8Jcx/x7oZS3PQP23KJlBVV1glp/wJeZs=; b=Za8kZ5Zus5e98nuUiWUVxPpEl4Us/+UHmt+8qqjWBxzIxiAeTt1PI1k2Tbk3/XLJhJ GbvONo+4vJGW5dDQlyUroafd/ZoJnCJSjsw9gHnwBlI7FuyEL/z5UxUJnObeHi2IOJ4o mAxjM+HqoMjbQMCX/U/uYO61jEI/NxoyouL5roaBDGl++EwzdZidQ97zq6XkjIUZzF/i +nKLAqiAi/S4aVZ3Nd+kffthBKlg4IOxzlebjNwekObYuoB+DmV/kzUOxBSWMfT3dWNn 2ktAQEpUIaWcFwdNx/0RI3kLLywTo0tR1OkXkvOV51NKMsE9lPeXEka69iQ0J4kb2+5J S17g== X-Gm-Message-State: AA+aEWaOVJXzNwxJFTFQqFGfM7fzfpLrkp/MPYpluVXyRybeDNLbT2le 70yB/Z+m+53rZW1nrO+tncIRPCZP X-Google-Smtp-Source: AJdET5dqNm9+VbcKfKM7/bfQ7WhkJLOkOV4Z/T6SLZQh5qdl1ZKcIZrEdw+8IRoxzQVQ9787at6Z7g== X-Received: by 2002:a1c:cb4c:: with SMTP id b73mr12236932wmg.69.1542927977455; Thu, 22 Nov 2018 15:06:17 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:16 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 06/22] stash: rename test cases to be more descriptive Date: Fri, 23 Nov 2018 01:05:26 +0200 Message-Id: <52becd09368bec7e24df4d837f2687012f12f190.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Rename some test cases' labels to be more descriptive and under 80 characters per line. Signed-off-by: Paul-Sebastian Ungureanu --- t/t3903-stash.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 098a387a82..8b09a3d6cc 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -604,7 +604,7 @@ test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' test_cmp expected actual ' -test_expect_success 'stash drop - fail early if specified stash is not a stash reference' ' +test_expect_success 'drop: fail early if specified stash is not a stash ref' ' git stash clear && test_when_finished "git reset --hard HEAD && git stash clear" && git reset --hard && @@ -618,7 +618,7 @@ test_expect_success 'stash drop - fail early if specified stash is not a stash r git reset --hard HEAD ' -test_expect_success 'stash pop - fail early if specified stash is not a stash reference' ' +test_expect_success 'pop: fail early if specified stash is not a stash ref' ' git stash clear && test_when_finished "git reset --hard HEAD && git stash clear" && git reset --hard && @@ -682,7 +682,7 @@ test_expect_success 'invalid ref of the form "n", n >= N' ' git stash drop ' -test_expect_success 'stash branch should not drop the stash if the branch exists' ' +test_expect_success 'branch: do not drop the stash if the branch exists' ' git stash clear && echo foo >file && git add file && @@ -693,7 +693,7 @@ test_expect_success 'stash branch should not drop the stash if the branch exists git rev-parse stash@{0} -- ' -test_expect_success 'stash branch should not drop the stash if the apply fails' ' +test_expect_success 'branch: should not drop the stash if the apply fails' ' git stash clear && git reset HEAD~1 --hard && echo foo >file && @@ -707,7 +707,7 @@ test_expect_success 'stash branch should not drop the stash if the apply fails' git rev-parse stash@{0} -- ' -test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' +test_expect_success 'apply: show same status as git status (relative to ./)' ' git stash clear && echo 1 >subdir/subfile1 && echo 2 >subdir/subfile2 && @@ -1048,7 +1048,7 @@ test_expect_success 'stash push -p with pathspec shows no changes only once' ' test_i18ncmp expect actual ' -test_expect_success 'stash push with pathspec shows no changes when there are none' ' +test_expect_success 'push : show no changes when there are none' ' >foo && git add foo && git commit -m "tmp" && @@ -1058,7 +1058,7 @@ test_expect_success 'stash push with pathspec shows no changes when there are no test_i18ncmp expect actual ' -test_expect_success 'stash push with pathspec not in the repository errors out' ' +test_expect_success 'push: not in the repository errors out' ' >untracked && test_must_fail git stash push untracked && test_path_is_file untracked From patchwork Thu Nov 22 23:05:27 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: 10694933 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 11C1B1932 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02EBD2C1D6 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBE9F2C1BE; 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 86D892C1E1 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439023AbeKWJr7 (ORCPT ); Fri, 23 Nov 2018 04:47:59 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:32855 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439015AbeKWJr7 (ORCPT ); Fri, 23 Nov 2018 04:47:59 -0500 Received: by mail-wm1-f67.google.com with SMTP id 79so10466215wmo.0 for ; Thu, 22 Nov 2018 15:06:19 -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=TGn7OHoV1E2uOEwZYOatdNV1UspxvvVTuBJneQzAoTM=; b=S6tcEPeGXXk0DxuoK3KpnhEslc16qdIu90Ngt9s6UQ/OF2XOioNqjg3q17W3zGz9+s 8YDax+p7yJO/3b2zgA5fpw0K3fO3g/ndiiv2LDqpJ9Biuy1e14IEYwll15usDNHlkW0+ cVne45L/uDusKeImeJGGTo2rZJtkzY08Cm5ynMvm7AZ8E8jpZ4tqVIhkxXqTj1G99RIT tMVJmjBvT2Xo8xqeJZuYp8KoMnvvZFdbPJ60X5d/vElPyIrRArp+DV61+LBekwV5di+O HgznMg+Cx46W7WzKmacAeT4SIyI26CGiakL0+IpJlVftz3n0++5pMUNznHFXDi5sg5r/ Y8/Q== 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=TGn7OHoV1E2uOEwZYOatdNV1UspxvvVTuBJneQzAoTM=; b=MGi3JWD4HgjFJpmsSIrMvi6vRZ4IhtOwiZhlA7i2FVxQyTQkDmizy4XBhvoln6ltoS dzFxWzNAyPlLrIyJ9jUQwlyiNLPqXC4y5aw9F7B8JKOaHV6jT86iKYMSmpUFLcbEkCfb Mp7SzO2bqMXbX4IsAadfZbZaZoZGEkX1/xLWSpIXa8uvqReBIMXBc3neHx/7sL4HcMTm yeiKwbYUAa0fwiwzKe3nhUWdBchaXvkTjLfAMoxttlFTlBAjOju8VwoJBPjCXkC/ghmF qFeHW76nAsmRqbLPLsvYxaFtijPuIHvcwgWWy7WMxvSvaotB1D/O3HuSYn4yzRtVE++t HxLQ== X-Gm-Message-State: AGRZ1gJFr1rphlx03klaqJGbdoRre5JQuf27llWsodxojbvJ29JQw8bo c8PBhY+KxrhvYs88XpxpKRXbe+FF X-Google-Smtp-Source: AJdET5e1ZHger6dsXfBHr9aG4by4udP/N3M+VsRb8mNFO+mEfbqfXWswzw/utIaEcO8mxtnzrsaCtg== X-Received: by 2002:a1c:6283:: with SMTP id w125-v6mr11983357wmb.117.1542927978381; Thu, 22 Nov 2018 15:06:18 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:17 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 07/22] stash: add tests for `git stash show` config Date: Fri, 23 Nov 2018 01:05:27 +0200 Message-Id: <1b0d546c452872d45d8fc9e648855ef5c17eb7fb.1542925164.git.ungureanupaulsebastian@gmail.com> 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 This commit introduces tests for `git stash show` config. It tests all the cases where `stash.showStat` and `stash.showPatch` are unset or set to true / false. Signed-off-by: Paul-Sebastian Ungureanu --- t/t3907-stash-show-config.sh | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 t/t3907-stash-show-config.sh diff --git a/t/t3907-stash-show-config.sh b/t/t3907-stash-show-config.sh new file mode 100755 index 0000000000..10914bba7b --- /dev/null +++ b/t/t3907-stash-show-config.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +test_description='Test git stash show configuration.' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit file +' + +# takes three parameters: +# 1. the stash.showStat value (or "") +# 2. the stash.showPatch value (or "") +# 3. the diff options of the expected output (or nothing for no output) +test_stat_and_patch () { + if test "" = "$1" + then + test_unconfig stash.showStat + else + test_config stash.showStat "$1" + fi && + + if test "" = "$2" + then + test_unconfig stash.showPatch + else + test_config stash.showPatch "$2" + fi && + + shift 2 && + echo 2 >file.t && + if test $# != 0 + then + git diff "$@" >expect + fi && + git stash && + git stash show >actual && + + if test $# = 0 + then + test_must_be_empty actual + else + test_cmp expect actual + fi +} + +test_expect_success 'showStat unset showPatch unset' ' + test_stat_and_patch "" "" --stat +' + +test_expect_success 'showStat unset showPatch false' ' + test_stat_and_patch "" false --stat +' + +test_expect_success 'showStat unset showPatch true' ' + test_stat_and_patch "" true --stat -p +' + +test_expect_success 'showStat false showPatch unset' ' + test_stat_and_patch false "" +' + +test_expect_success 'showStat false showPatch false' ' + test_stat_and_patch false false +' + +test_expect_success 'showStat false showPatch true' ' + test_stat_and_patch false true -p +' + +test_expect_success 'showStat true showPatch unset' ' + test_stat_and_patch true "" --stat +' + +test_expect_success 'showStat true showPatch false' ' + test_stat_and_patch true false --stat +' + +test_expect_success 'showStat true showPatch true' ' + test_stat_and_patch true true --stat -p +' + +test_done From patchwork Thu Nov 22 23:05:28 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: 10694947 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 D3CE614BD for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C56F72C19A for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA5E22C1BB; Thu, 22 Nov 2018 23:06:31 +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 D12902C1A2 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439026AbeKWJsB (ORCPT ); Fri, 23 Nov 2018 04:48:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34195 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439013AbeKWJsA (ORCPT ); Fri, 23 Nov 2018 04:48:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so6435205wmd.1 for ; Thu, 22 Nov 2018 15:06:20 -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=TOL1w0BjCkT9kGjHI9tWKDJF2SRfghtPQI9KHJZm1iE=; b=THPMQ8tmArQwusydQHneaQXrhVJHE8CMNm9ZgdbXBvmhYmcgUlakkMvY4ka332+Rgf Rhf2vy71paVjmdCtjPzx9r7bqJYdu3fL9pGcidAtBeD2oNQakeA6+1ic2zAJevM2i9Ck nDo4vtcx0ycf8NA3EYQ3kTZs6ZhV/NQ95UwmUHHuzL49Q9/tga34x2X7d0/CKlhGbK3A D7YkOpI/XV2Nf4S7RaO9efwTJRpi8kJtMoOuLFmMy9x6NMkBJXqs1z09fZxAoRm1r74i 59BlfEPALL3ntLiuGDP9RlWGD5p2cZ9uh/5e2WLfldobwoqfb1FiFu8z+S4UStDdR1rJ f8Fg== 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=TOL1w0BjCkT9kGjHI9tWKDJF2SRfghtPQI9KHJZm1iE=; b=EQ6Ids526TLq9t6kYLBE4fOni2QA0S5nNVi8iLIHQf3p+KD3dGoEog9cEhrq3EW77n nBqCI+6lqvc9iCwhZnczmmhr0+TINo1kTS/BgQOanky6YPvn2gMvjdhGlJB8tHgmtw3u bIj3zvb+wYfXiY4ST74HZYqIrbepNWsVTHhjCgc8D36Fw8+JWBKwOUWV8piuj7hnxc3L FQ/VW5ueg0N96ehK36z2rWk2LbhR/9qJdc43uV/vdG9A8aEOTjitkKGllRo1aVRSkfZZ 0RUKiGyquMNu2KS1iIsSsKMW0jL7NufHFpCXiZEdEmwV/hcWmn+VjMOnk3g591chXmHf asLQ== X-Gm-Message-State: AA+aEWbDOnc/z1TANNW3MsZ7N2NJuBhKyjAog9+UWQthST5ZxmaRhTiB WKEJACjwO0VH0Xh72FDc2MCt/gBh X-Google-Smtp-Source: AFSGD/UYskqImvVcKOPMoKqaP1hzwTuIcrDV7Ym0Iyy1gUoqg5NtAOAUKiM/fEHrL7Ag6fb5SbgA9A== X-Received: by 2002:a1c:8b42:: with SMTP id n63mr10946512wmd.38.1542927979470; Thu, 22 Nov 2018 15:06:19 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:18 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 08/22] stash: mention options in `show` synopsis Date: Fri, 23 Nov 2018 01:05:28 +0200 Message-Id: <4af795c07883b1e103a8999f4cbe32bd2db0cead.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Mention in the documentation, that `show` accepts any option known to `git diff`. Signed-off-by: Paul-Sebastian Ungureanu --- Documentation/git-stash.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 7ef8c47911..e31ea7d303 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git stash' list [] -'git stash' show [] +'git stash' show [] [] 'git stash' drop [-q|--quiet] [] 'git stash' ( pop | apply ) [--index] [-q|--quiet] [] 'git stash' branch [] @@ -106,7 +106,7 @@ stash@{1}: On master: 9cc0589... Add git-stash The command takes options applicable to the 'git log' command to control what is shown and how. See linkgit:git-log[1]. -show []:: +show [] []:: Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first From patchwork Thu Nov 22 23:05:29 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: 10694943 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 5A49C1734 for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4920C2C1A6 for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E0582C1BE; Thu, 22 Nov 2018 23:06:31 +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 F22B12C1BB for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439035AbeKWJsD (ORCPT ); Fri, 23 Nov 2018 04:48:03 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44745 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439015AbeKWJsC (ORCPT ); Fri, 23 Nov 2018 04:48:02 -0500 Received: by mail-wr1-f65.google.com with SMTP id z5so6337905wrt.11 for ; Thu, 22 Nov 2018 15:06:21 -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=QuYAiuj2nG23JjQxzSra5mxgAnh8ZZ39Gg5+gNyIoeA=; b=tr03q+ZeciZynWu6eOwX8K48NVWKEhIwM/iHu0GUayVLZw7S1PCUuk+9mIeTOGBeRm huE8GPBKwTco7z4stnxKRxDR9H5fBMfltHCx6s2FT7ymg/jeCfh/TuOFPNyZZFAnkgSF 82I3oNQzF3N+KWQaP8yVz4UAkcdJbmn8sWWjZHYw0houVoQiWdEXBblKG09mvo/SeKw7 DxZzkfZue8Owt0OdKNZd/Fzyf9TIBpzHq68SCfojnthIPfbBSXBk7XlQO6zpJA2cCxWb A0bfV5xj3DKWDB7bxs7BI90OKfWyA7fPTAoUcVsQPROFDJ4na8omAg0FaHObOIIscu3w Vstw== 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=QuYAiuj2nG23JjQxzSra5mxgAnh8ZZ39Gg5+gNyIoeA=; b=TPsytDesVx+sjWSUIpyFvoOIlWgSpPPpGjTdK8I7Frp4Ng5gbTontgJBkbDUAxI5XJ KT/b58rbTmAIGx1iHvU+Lx5vsR3RxhXead/fUe0LNzh1249pIHfPii9FybeFhoCq3mE5 ff9pd2B9nyocHh6vc8xChqtH/WNagJV7ISSdIcnD5vWiyjESO2m5/ejQRZALq5460I3u 0q0ith3S58q7AVl4I5PHsC/2Ge3bhrLVo/Bs96pmZkX+EbfU1m7vgPYWD7C9TC3Lm3LP PBI7F3eWtgTk+/pZap/8GLKkENQ0R8y/TVMwIw+gQn9EjSVYkGQ8MuDZBPeo2R3MrydQ 9oyQ== X-Gm-Message-State: AA+aEWYyrski0iHJpmD8wwrLnSWMj2M+lmN7AUKxlHPaKuimNxWgSZ6z l5l8txt0vfnQHYobvMm2p/+j2DPT X-Google-Smtp-Source: AFSGD/W3vGtdZyVKoVhhQYxMLw592Xsj/RTRIMGq+XOoaYAqXP7IntY5nngQbjpzMZPZW4iRk2JzZQ== X-Received: by 2002:a5d:66c1:: with SMTP id k1mr11187715wrw.132.1542927980816; Thu, 22 Nov 2018 15:06:20 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:20 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 09/22] stash: convert apply to builtin Date: Fri, 23 Nov 2018 01:05:29 +0200 Message-Id: <95eb58bf26aaadc418a30e488e5847b1843f3290.1542925164.git.ungureanupaulsebastian@gmail.com> 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 From: Joel Teichroeb Add a builtin helper for performing stash commands. Converting all at once proved hard to review, so starting with just apply lets conversion get started without the other commands being finished. The helper is being implemented as a drop in replacement for stash so that when it is complete it can simply be renamed and the shell script deleted. Delete the contents of the apply_stash shell function and replace it with a call to stash--helper apply until pop is also converted. Signed-off-by: Joel Teichroeb Signed-off-by: Paul-Sebastian Ungureanu --- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/stash--helper.c | 452 ++++++++++++++++++++++++++++++++++++++++ git-stash.sh | 78 +------ git.c | 1 + 6 files changed, 463 insertions(+), 71 deletions(-) create mode 100644 builtin/stash--helper.c diff --git a/.gitignore b/.gitignore index 0d77ea5894..6ecab90ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -162,6 +162,7 @@ /git-show-ref /git-stage /git-stash +/git-stash--helper /git-status /git-stripspace /git-submodule diff --git a/Makefile b/Makefile index bbfbb4292d..aa83545e94 100644 --- a/Makefile +++ b/Makefile @@ -1115,6 +1115,7 @@ BUILTIN_OBJS += builtin/shortlog.o BUILTIN_OBJS += builtin/show-branch.o BUILTIN_OBJS += builtin/show-index.o BUILTIN_OBJS += builtin/show-ref.o +BUILTIN_OBJS += builtin/stash--helper.o BUILTIN_OBJS += builtin/stripspace.o BUILTIN_OBJS += builtin/submodule--helper.o BUILTIN_OBJS += builtin/symbolic-ref.o diff --git a/builtin.h b/builtin.h index 6538932e99..ff4460aff7 100644 --- a/builtin.h +++ b/builtin.h @@ -225,6 +225,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix); extern int cmd_show_branch(int argc, const char **argv, const char *prefix); extern int cmd_show_index(int argc, const char **argv, const char *prefix); extern int cmd_status(int argc, const char **argv, const char *prefix); +extern int cmd_stash__helper(int argc, const char **argv, const char *prefix); extern int cmd_stripspace(int argc, const char **argv, const char *prefix); extern int cmd_submodule__helper(int argc, const char **argv, const char *prefix); extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c new file mode 100644 index 0000000000..997b1c0ecf --- /dev/null +++ b/builtin/stash--helper.c @@ -0,0 +1,452 @@ +#include "builtin.h" +#include "config.h" +#include "parse-options.h" +#include "refs.h" +#include "lockfile.h" +#include "cache-tree.h" +#include "unpack-trees.h" +#include "merge-recursive.h" +#include "argv-array.h" +#include "run-command.h" +#include "dir.h" +#include "rerere.h" + +static const char * const git_stash_helper_usage[] = { + N_("git stash--helper apply [--index] [-q|--quiet] []"), + NULL +}; + +static const char * const git_stash_helper_apply_usage[] = { + N_("git stash--helper apply [--index] [-q|--quiet] []"), + NULL +}; + +static const char *ref_stash = "refs/stash"; +static struct strbuf stash_index_path = STRBUF_INIT; + +/* + * w_commit is set to the commit containing the working tree + * b_commit is set to the base commit + * i_commit is set to the commit containing the index tree + * u_commit is set to the commit containing the untracked files tree + * w_tree is set to the working tree + * b_tree is set to the base tree + * i_tree is set to the index tree + * u_tree is set to the untracked files tree + */ + +struct stash_info { + struct object_id w_commit; + struct object_id b_commit; + struct object_id i_commit; + struct object_id u_commit; + struct object_id w_tree; + struct object_id b_tree; + struct object_id i_tree; + struct object_id u_tree; + struct strbuf revision; + int is_stash_ref; + int has_u; +}; + +static void free_stash_info(struct stash_info *info) +{ + strbuf_release(&info->revision); +} + +static void assert_stash_like(struct stash_info *info, const char *revision) +{ + if (get_oidf(&info->b_commit, "%s^1", revision) || + get_oidf(&info->w_tree, "%s:", revision) || + get_oidf(&info->b_tree, "%s^1:", revision) || + get_oidf(&info->i_tree, "%s^2:", revision)) + die(_("'%s' is not a stash-like commit"), revision); +} + +static int get_stash_info(struct stash_info *info, int argc, const char **argv) +{ + int ret; + char *end_of_rev; + char *expanded_ref; + const char *revision; + const char *commit = NULL; + struct object_id dummy; + struct strbuf symbolic = STRBUF_INIT; + + if (argc > 1) { + int i; + struct strbuf refs_msg = STRBUF_INIT; + + for (i = 0; i < argc; i++) + strbuf_addf(&refs_msg, " '%s'", argv[i]); + + fprintf_ln(stderr, _("Too many revisions specified:%s"), + refs_msg.buf); + strbuf_release(&refs_msg); + + return -1; + } + + if (argc == 1) + commit = argv[0]; + + strbuf_init(&info->revision, 0); + if (!commit) { + if (!ref_exists(ref_stash)) { + free_stash_info(info); + fprintf_ln(stderr, _("No stash entries found.")); + return -1; + } + + strbuf_addf(&info->revision, "%s@{0}", ref_stash); + } else if (strspn(commit, "0123456789") == strlen(commit)) { + strbuf_addf(&info->revision, "%s@{%s}", ref_stash, commit); + } else { + strbuf_addstr(&info->revision, commit); + } + + revision = info->revision.buf; + + if (get_oid(revision, &info->w_commit)) { + error(_("%s is not a valid reference"), revision); + free_stash_info(info); + return -1; + } + + assert_stash_like(info, revision); + + info->has_u = !get_oidf(&info->u_tree, "%s^3:", revision); + + end_of_rev = strchrnul(revision, '@'); + strbuf_add(&symbolic, revision, end_of_rev - revision); + + ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref); + strbuf_release(&symbolic); + switch (ret) { + case 0: /* Not found, but valid ref */ + info->is_stash_ref = 0; + break; + case 1: + info->is_stash_ref = !strcmp(expanded_ref, ref_stash); + break; + default: /* Invalid or ambiguous */ + free_stash_info(info); + } + + free(expanded_ref); + return !(ret == 0 || ret == 1); +} + +static int reset_tree(struct object_id *i_tree, int update, int reset) +{ + int nr_trees = 1; + struct unpack_trees_options opts; + struct tree_desc t[MAX_UNPACK_TREES]; + struct tree *tree; + struct lock_file lock_file = LOCK_INIT; + + read_cache_preload(NULL); + if (refresh_cache(REFRESH_QUIET)) + return -1; + + hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + + memset(&opts, 0, sizeof(opts)); + + tree = parse_tree_indirect(i_tree); + if (parse_tree(tree)) + return -1; + + init_tree_desc(t, tree->buffer, tree->size); + + opts.head_idx = 1; + opts.src_index = &the_index; + opts.dst_index = &the_index; + opts.merge = 1; + opts.reset = reset; + opts.update = update; + opts.fn = oneway_merge; + + if (unpack_trees(nr_trees, t, &opts)) + return -1; + + if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) + return error(_("unable to write new index file")); + + return 0; +} + +static int diff_tree_binary(struct strbuf *out, struct object_id *w_commit) +{ + struct child_process cp = CHILD_PROCESS_INIT; + const char *w_commit_hex = oid_to_hex(w_commit); + + /* + * Diff-tree would not be very hard to replace with a native function, + * however it should be done together with apply_cached. + */ + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "diff-tree", "--binary", NULL); + argv_array_pushf(&cp.args, "%s^2^..%s^2", w_commit_hex, w_commit_hex); + + return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); +} + +static int apply_cached(struct strbuf *out) +{ + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * Apply currently only reads either from stdin or a file, thus + * apply_all_patches would have to be updated to optionally take a + * buffer. + */ + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "apply", "--cached", NULL); + return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); +} + +static int reset_head(void) +{ + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * Reset is overall quite simple, however there is no current public + * API for resetting. + */ + cp.git_cmd = 1; + argv_array_push(&cp.args, "reset"); + + return run_command(&cp); +} + +static int get_newly_staged(struct strbuf *out, struct object_id *c_tree) +{ + struct child_process cp = CHILD_PROCESS_INIT; + const char *c_tree_hex = oid_to_hex(c_tree); + + /* + * diff-index is very similar to diff-tree above, and should be + * converted together with update_index. + */ + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "diff-index", "--cached", "--name-only", + "--diff-filter=A", NULL); + argv_array_push(&cp.args, c_tree_hex); + return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); +} + +static int update_index(struct strbuf *out) +{ + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * Update-index is very complicated and may need to have a public + * function exposed in order to remove this forking. + */ + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "update-index", "--add", "--stdin", NULL); + return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); +} + +static int restore_untracked(struct object_id *u_tree) +{ + int res; + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * We need to run restore files from a given index, but without + * affecting the current index, so we use GIT_INDEX_FILE with + * run_command to fork processes that will not interfere. + */ + cp.git_cmd = 1; + argv_array_push(&cp.args, "read-tree"); + argv_array_push(&cp.args, oid_to_hex(u_tree)); + argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (run_command(&cp)) { + remove_path(stash_index_path.buf); + return -1; + } + + child_process_init(&cp); + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "checkout-index", "--all", NULL); + argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + + res = run_command(&cp); + remove_path(stash_index_path.buf); + return res; +} + +static int do_apply_stash(const char *prefix, struct stash_info *info, + int index, int quiet) +{ + int ret; + int has_index = index; + struct merge_options o; + struct object_id c_tree; + struct object_id index_tree; + struct commit *result; + const struct object_id *bases[1]; + + read_cache_preload(NULL); + if (refresh_cache(REFRESH_QUIET)) + return -1; + + if (write_cache_as_tree(&c_tree, 0, NULL) || reset_tree(&c_tree, 0, 0)) + return error(_("cannot apply a stash in the middle of a merge")); + + if (index) { + if (oideq(&info->b_tree, &info->i_tree) || + oideq(&c_tree, &info->i_tree)) { + has_index = 0; + } else { + struct strbuf out = STRBUF_INIT; + + if (diff_tree_binary(&out, &info->w_commit)) { + strbuf_release(&out); + return error(_("could not generate diff %s^!."), + oid_to_hex(&info->w_commit)); + } + + ret = apply_cached(&out); + strbuf_release(&out); + if (ret) + return error(_("conflicts in index." + "Try without --index.")); + + discard_cache(); + read_cache(); + if (write_cache_as_tree(&index_tree, 0, NULL)) + return error(_("could not save index tree")); + + reset_head(); + } + } + + if (info->has_u && restore_untracked(&info->u_tree)) + return error(_("could not restore untracked files from stash")); + + init_merge_options(&o); + + o.branch1 = "Updated upstream"; + o.branch2 = "Stashed changes"; + + if (oideq(&info->b_tree, &c_tree)) + o.branch1 = "Version stash was based on"; + + if (quiet) + o.verbosity = 0; + + if (o.verbosity >= 3) + printf_ln(_("Merging %s with %s"), o.branch1, o.branch2); + + bases[0] = &info->b_tree; + + ret = merge_recursive_generic(&o, &c_tree, &info->w_tree, 1, bases, + &result); + if (ret) { + rerere(0); + + if (index) + fprintf_ln(stderr, _("Index was not unstashed.")); + + return ret; + } + + if (has_index) { + if (reset_tree(&index_tree, 0, 0)) + return -1; + } else { + struct strbuf out = STRBUF_INIT; + + if (get_newly_staged(&out, &c_tree)) { + strbuf_release(&out); + return -1; + } + + if (reset_tree(&c_tree, 0, 1)) { + strbuf_release(&out); + return -1; + } + + ret = update_index(&out); + strbuf_release(&out); + if (ret) + return -1; + + discard_cache(); + } + + if (quiet) { + if (refresh_cache(REFRESH_QUIET)) + warning("could not refresh index"); + } else { + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * Status is quite simple and could be replaced with calls to + * wt_status in the future, but it adds complexities which may + * require more tests. + */ + cp.git_cmd = 1; + cp.dir = prefix; + argv_array_push(&cp.args, "status"); + run_command(&cp); + } + + return 0; +} + +static int apply_stash(int argc, const char **argv, const char *prefix) +{ + int ret; + int quiet = 0; + int index = 0; + struct stash_info info; + struct option options[] = { + OPT__QUIET(&quiet, N_("be quiet, only report errors")), + OPT_BOOL(0, "index", &index, + N_("attempt to recreate the index")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_apply_usage, 0); + + if (get_stash_info(&info, argc, argv)) + return -1; + + ret = do_apply_stash(prefix, &info, index, quiet); + free_stash_info(&info); + return ret; +} + +int cmd_stash__helper(int argc, const char **argv, const char *prefix) +{ + pid_t pid = getpid(); + const char *index_file; + + struct option options[] = { + OPT_END() + }; + + git_config(git_default_config, NULL); + + argc = parse_options(argc, argv, prefix, options, git_stash_helper_usage, + PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + + index_file = get_index_file(); + strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file, + (uintmax_t)pid); + + if (argc < 1) + usage_with_options(git_stash_helper_usage, options); + if (!strcmp(argv[0], "apply")) + return !!apply_stash(argc, argv, prefix); + + usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), + git_stash_helper_usage, options); +} diff --git a/git-stash.sh b/git-stash.sh index 94793c1a91..809b1c2d1d 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -566,76 +566,11 @@ assert_stash_ref() { } apply_stash () { - - assert_stash_like "$@" - - git update-index -q --refresh || die "$(gettext "unable to refresh index")" - - # current index state - c_tree=$(git write-tree) || - die "$(gettext "Cannot apply a stash in the middle of a merge")" - - unstashed_index_tree= - if test -n "$INDEX_OPTION" && test "$b_tree" != "$i_tree" && - test "$c_tree" != "$i_tree" - then - git diff-tree --binary $s^2^..$s^2 | git apply --cached - test $? -ne 0 && - die "$(gettext "Conflicts in index. Try without --index.")" - unstashed_index_tree=$(git write-tree) || - die "$(gettext "Could not save index tree")" - git reset - fi - - if test -n "$u_tree" - then - GIT_INDEX_FILE="$TMPindex" git read-tree "$u_tree" && - GIT_INDEX_FILE="$TMPindex" git checkout-index --all && - rm -f "$TMPindex" || - die "$(gettext "Could not restore untracked files from stash entry")" - fi - - eval " - GITHEAD_$w_tree='Stashed changes' && - GITHEAD_$c_tree='Updated upstream' && - GITHEAD_$b_tree='Version stash was based on' && - export GITHEAD_$w_tree GITHEAD_$c_tree GITHEAD_$b_tree - " - - if test -n "$GIT_QUIET" - then - GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY - fi - if git merge-recursive $b_tree -- $c_tree $w_tree - then - # No conflict - if test -n "$unstashed_index_tree" - then - git read-tree "$unstashed_index_tree" - else - a="$TMP-added" && - git diff-index --cached --name-only --diff-filter=A $c_tree >"$a" && - git read-tree --reset $c_tree && - git update-index --add --stdin <"$a" || - die "$(gettext "Cannot unstage modified files")" - rm -f "$a" - fi - squelch= - if test -n "$GIT_QUIET" - then - squelch='>/dev/null 2>&1' - fi - (cd "$START_DIR" && eval "git status $squelch") || : - else - # Merge conflict; keep the exit status from merge-recursive - status=$? - git rerere - if test -n "$INDEX_OPTION" - then - gettextln "Index was not unstashed." >&2 - fi - exit $status - fi + cd "$START_DIR" + git stash--helper apply "$@" + res=$? + cd_to_toplevel + return $res } pop_stash() { @@ -713,7 +648,8 @@ push) ;; apply) shift - apply_stash "$@" + cd "$START_DIR" + git stash--helper apply "$@" ;; clear) shift diff --git a/git.c b/git.c index 2f604a41ea..76ee02802e 100644 --- a/git.c +++ b/git.c @@ -554,6 +554,7 @@ static struct cmd_struct commands[] = { { "show-index", cmd_show_index }, { "show-ref", cmd_show_ref, RUN_SETUP }, { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, + { "stash--helper", cmd_stash__helper, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, From patchwork Thu Nov 22 23:05:30 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: 10694939 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 CC32C18F0 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA3322C1A6 for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEEA02C200; Thu, 22 Nov 2018 23:06:30 +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 29E0D2C1BE for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439032AbeKWJsD (ORCPT ); Fri, 23 Nov 2018 04:48:03 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40495 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439027AbeKWJsC (ORCPT ); Fri, 23 Nov 2018 04:48:02 -0500 Received: by mail-wr1-f65.google.com with SMTP id p4so10637889wrt.7 for ; Thu, 22 Nov 2018 15:06:22 -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=N5TS0jbvGTt6NrT69hdfYrqtl0L0Sv8q77P3ZmvsVJI=; b=ojleKSBXkpPRXmHHlsQKdGo4xT15AkCsHLH1POiHv6OxqU0VE00Xr8W0iLSZN74H+7 9nd8Z5asp1qr0R96bBsQqQPOWiTTOJtgxLy+tnTFRC+f8OzmtwUO/S2iLLyik1WhQpdH 3ar89Da/Fqsv0pTtZ/qF1cqlh7b3GrU9q2trVe5MvG7k3H/TJqBJrlBsT8LlGJV29Ena X1BoIi6+ErK5OkIpZg5E5DjlsHWozY07MS4FKUpbSSH6FGmkDa2uWHOtxvOu7Glk9u2v SWUdVOkLuF6uTis6jqOboDQTWmr9wbAYRgYrZkjUenZPp2N8S6fYnjGSrDBz2SAF/9Ey Qatg== 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=N5TS0jbvGTt6NrT69hdfYrqtl0L0Sv8q77P3ZmvsVJI=; b=TrkoJOau+Oc3PvJAWaw44o6nN6IdeoE45iDCq0gGd4+15F9mj6JnFZq1IAWI2bFFNU A6ub9tAE/pTc3XqU4lH64PX4KZGg2jeIx8OiHVJdmw1YBrjN9F5gX/ujOUlBdx4eGZFP TaBUe+xOBqeSt+hPntdaiOP3s8tZ7iWLv2/qWOB669N7MZVBFupF0lt26h8XZIfABhzO wRSOOlOFCo8R5oIHSYLR+670/mdgoOVuLEJSXnqfdk/uZC4uvoFc6DZlz+npy0kKP020 ELcbsuzIxTQfAe70XnwTYqF6bNBUEAKAyTW7fMRCxQ6nZm4qZtko8UUUpxzBnWuQsSta kgrg== X-Gm-Message-State: AA+aEWatoS1cVIeg61FxR3qMQXymqmnjG7L0FiI81xZO2ndnciWzuTc3 WUVVHK2Sm6SLR0nGh+znqMOSC9Xp X-Google-Smtp-Source: AFSGD/VnerFz8ckts/8qDU7DMhYoojH6efxbVnQEvlXXP9cLYfj//tFoNnNHd9kpRUJG+BrL7kJ3Dw== X-Received: by 2002:adf:a50c:: with SMTP id i12mr10974067wrb.220.1542927981910; Thu, 22 Nov 2018 15:06:21 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:21 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 10/22] stash: convert drop and clear to builtin Date: Fri, 23 Nov 2018 01:05:30 +0200 Message-Id: <22ae2b44fc9c32f36050e5189f65307d66f31f96.1542925164.git.ungureanupaulsebastian@gmail.com> 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 From: Joel Teichroeb Add the drop and clear commands to the builtin helper. These two are each simple, but are being added together as they are quite related. We have to unfortunately keep the drop and clear functions in the shell script as functions are called with parameters internally that are not valid when the commands are called externally. Once pop is converted they can both be removed. Signed-off-by: Joel Teichroeb Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 117 ++++++++++++++++++++++++++++++++++++++++ git-stash.sh | 4 +- 2 files changed, 119 insertions(+), 2 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 997b1c0ecf..07b8ec5bcb 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -12,7 +12,14 @@ #include "rerere.h" static const char * const git_stash_helper_usage[] = { + N_("git stash--helper drop [-q|--quiet] []"), N_("git stash--helper apply [--index] [-q|--quiet] []"), + N_("git stash--helper clear"), + NULL +}; + +static const char * const git_stash_helper_drop_usage[] = { + N_("git stash--helper drop [-q|--quiet] []"), NULL }; @@ -21,6 +28,11 @@ static const char * const git_stash_helper_apply_usage[] = { NULL }; +static const char * const git_stash_helper_clear_usage[] = { + N_("git stash--helper clear"), + NULL +}; + static const char *ref_stash = "refs/stash"; static struct strbuf stash_index_path = STRBUF_INIT; @@ -137,6 +149,32 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv) return !(ret == 0 || ret == 1); } +static int do_clear_stash(void) +{ + struct object_id obj; + if (get_oid(ref_stash, &obj)) + return 0; + + return delete_ref(NULL, ref_stash, &obj, 0); +} + +static int clear_stash(int argc, const char **argv, const char *prefix) +{ + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_clear_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + + if (argc) + return error(_("git stash clear with parameters is " + "unimplemented")); + + return do_clear_stash(); +} + static int reset_tree(struct object_id *i_tree, int update, int reset) { int nr_trees = 1; @@ -424,6 +462,81 @@ static int apply_stash(int argc, const char **argv, const char *prefix) return ret; } +static int do_drop_stash(const char *prefix, struct stash_info *info, int quiet) +{ + int ret; + struct child_process cp_reflog = CHILD_PROCESS_INIT; + struct child_process cp = CHILD_PROCESS_INIT; + + /* + * reflog does not provide a simple function for deleting refs. One will + * need to be added to avoid implementing too much reflog code here + */ + + cp_reflog.git_cmd = 1; + argv_array_pushl(&cp_reflog.args, "reflog", "delete", "--updateref", + "--rewrite", NULL); + argv_array_push(&cp_reflog.args, info->revision.buf); + ret = run_command(&cp_reflog); + if (!ret) { + if (!quiet) + printf_ln(_("Dropped %s (%s)"), info->revision.buf, + oid_to_hex(&info->w_commit)); + } else { + return error(_("%s: Could not drop stash entry"), + info->revision.buf); + } + + /* + * This could easily be replaced by get_oid, but currently it will throw + * a fatal error when a reflog is empty, which we can not recover from. + */ + cp.git_cmd = 1; + /* Even though --quiet is specified, rev-parse still outputs the hash */ + cp.no_stdout = 1; + argv_array_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL); + argv_array_pushf(&cp.args, "%s@{0}", ref_stash); + ret = run_command(&cp); + + /* do_clear_stash if we just dropped the last stash entry */ + if (ret) + do_clear_stash(); + + return 0; +} + +static void assert_stash_ref(struct stash_info *info) +{ + if (!info->is_stash_ref) { + free_stash_info(info); + error(_("'%s' is not a stash reference"), info->revision.buf); + exit(128); + } +} + +static int drop_stash(int argc, const char **argv, const char *prefix) +{ + int ret; + int quiet = 0; + struct stash_info info; + struct option options[] = { + OPT__QUIET(&quiet, N_("be quiet, only report errors")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_drop_usage, 0); + + if (get_stash_info(&info, argc, argv)) + return -1; + + assert_stash_ref(&info); + + ret = do_drop_stash(prefix, &info, quiet); + free_stash_info(&info); + return ret; +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -446,6 +559,10 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) usage_with_options(git_stash_helper_usage, options); if (!strcmp(argv[0], "apply")) return !!apply_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "clear")) + return !!clear_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "drop")) + return !!drop_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index 809b1c2d1d..a99d5dc9e5 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -653,7 +653,7 @@ apply) ;; clear) shift - clear_stash "$@" + git stash--helper clear "$@" ;; create) shift @@ -665,7 +665,7 @@ store) ;; drop) shift - drop_stash "$@" + git stash--helper drop "$@" ;; pop) shift From patchwork Thu Nov 22 23:05:31 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: 10694967 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 283E714BD for ; Thu, 22 Nov 2018 23:06:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F0D2BC3D for ; Thu, 22 Nov 2018 23:06:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B4702C1A2; Thu, 22 Nov 2018 23:06:41 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 4AFB22BC3D for ; Thu, 22 Nov 2018 23:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439038AbeKWJsE (ORCPT ); Fri, 23 Nov 2018 04:48:04 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35271 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439014AbeKWJsD (ORCPT ); Fri, 23 Nov 2018 04:48:03 -0500 Received: by mail-wr1-f66.google.com with SMTP id 96so10660197wrb.2 for ; Thu, 22 Nov 2018 15:06:23 -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=ylwq10VyjIh8YISTHsyTBa06v1wDd70LuXQpDj21lIg=; b=He6/MTRf5CpMzMEMz/yjxaxoVTw7BV3JlIZSQ4neawlhHAUzv+0zn88nky5+7Dd2Um zjeMNKZQGE2x9uZluWb9p5IFetogc9qQD3yUzB29EfFRK9dpLmQWS95se1kJGRFxumTZ UXxBEaY2ypYJ6F0Rkr63f/AN1zhf2nXwNehOf+KHSSqQRJm/Q1bK2AeflM0TCzab8MDK rgD9r5MkYY5mqH14ayd+heiK9BqAacGzVMm3y97kq9qqPTac2mnm4r1isbPBcU3jo11+ D/jA6HcM8jKhWjAjS30M8hwtg0n/269R2fUHa/Q0xGEja4Mp7uPBcZ095KlHrnsEYQVd CcEQ== 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=ylwq10VyjIh8YISTHsyTBa06v1wDd70LuXQpDj21lIg=; b=ZrRPTMIHKiwvDnAgxC47b6MHmVo1v33TlpBFIHc6hSnHbsc1wxpqsm4GUZ8JXOWAGO zmZlM2riQmEx6nwkk5XBdNOXNCofTDAxP8E3vzw6LWftHSIagEubGpbozVOtENyrED7w EUZoo5+nskYWS9O/H1BpCzF0C1W0nq03yO2FnCDLXeLt504BPIOKJIeHiwO/46ydieM1 w/lPIp+OcdIcItcMX173t/A1J/9AwcbAAvZTiFh/iIF9IaoRRtrE3/SG8yrPnvJYXUKf ukwav5x3qr4U8y5DO9Fr63/anL4Zy16dwE+r4ODhWVAMB9qnPzuMz7Nb/iwmKp1ZwV8h Cl/Q== X-Gm-Message-State: AA+aEWa/JHfBXbYd6aTSOJr3vQRqYLLsesz62mlGSsxReOEQJUwB8QWb pWEIg5V5t4GyUw07UvRAp/04ciNu X-Google-Smtp-Source: AFSGD/WfotBi8aZ0ooJv8k1iqnYUbKBOm0wc194eVUIWsANjj5X58+aSNJENu3H8JbvYqKp2Uo+CWw== X-Received: by 2002:adf:9786:: with SMTP id s6mr11433586wrb.283.1542927982872; Thu, 22 Nov 2018 15:06:22 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:22 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 11/22] stash: convert branch to builtin Date: Fri, 23 Nov 2018 01:05:31 +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 From: Joel Teichroeb Add stash branch to the helper and delete the apply_to_branch function from the shell script. Checkout does not currently provide a function for checking out a branch as cmd_checkout does a large amount of sanity checks first that we require here. Signed-off-by: Joel Teichroeb Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 46 +++++++++++++++++++++++++++++++++++++++++ git-stash.sh | 17 ++------------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 07b8ec5bcb..68b65165e4 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -14,6 +14,7 @@ static const char * const git_stash_helper_usage[] = { N_("git stash--helper drop [-q|--quiet] []"), N_("git stash--helper apply [--index] [-q|--quiet] []"), + N_("git stash--helper branch []"), N_("git stash--helper clear"), NULL }; @@ -28,6 +29,11 @@ static const char * const git_stash_helper_apply_usage[] = { NULL }; +static const char * const git_stash_helper_branch_usage[] = { + N_("git stash--helper branch []"), + NULL +}; + static const char * const git_stash_helper_clear_usage[] = { N_("git stash--helper clear"), NULL @@ -537,6 +543,44 @@ static int drop_stash(int argc, const char **argv, const char *prefix) return ret; } +static int branch_stash(int argc, const char **argv, const char *prefix) +{ + int ret; + const char *branch = NULL; + struct stash_info info; + struct child_process cp = CHILD_PROCESS_INIT; + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_branch_usage, 0); + + if (!argc) { + fprintf_ln(stderr, _("No branch name specified")); + return -1; + } + + branch = argv[0]; + + if (get_stash_info(&info, argc - 1, argv + 1)) + return -1; + + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "checkout", "-b", NULL); + argv_array_push(&cp.args, branch); + argv_array_push(&cp.args, oid_to_hex(&info.b_commit)); + ret = run_command(&cp); + if (!ret) + ret = do_apply_stash(prefix, &info, 1, 0); + if (!ret && info.is_stash_ref) + ret = do_drop_stash(prefix, &info, 0); + + free_stash_info(&info); + + return ret; +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -563,6 +607,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!clear_stash(argc, argv, prefix); else if (!strcmp(argv[0], "drop")) return !!drop_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "branch")) + return !!branch_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index a99d5dc9e5..29d9f44255 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -598,20 +598,6 @@ drop_stash () { clear_stash } -apply_to_branch () { - test -n "$1" || die "$(gettext "No branch name specified")" - branch=$1 - shift 1 - - set -- --index "$@" - assert_stash_like "$@" - - git checkout -b $branch $REV^ && - apply_stash "$@" && { - test -z "$IS_STASH_REF" || drop_stash "$@" - } -} - test "$1" = "-p" && set "push" "$@" PARSE_CACHE='--not-parsed' @@ -673,7 +659,8 @@ pop) ;; branch) shift - apply_to_branch "$@" + cd "$START_DIR" + git stash--helper branch "$@" ;; *) case $# in From patchwork Thu Nov 22 23:05:32 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: 10694951 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 928BA1926 for ; Thu, 22 Nov 2018 23:06:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81DCE2C19A for ; Thu, 22 Nov 2018 23:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 768032C1A6; Thu, 22 Nov 2018 23:06:32 +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 03E942C19A for ; Thu, 22 Nov 2018 23:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439049AbeKWJsJ (ORCPT ); Fri, 23 Nov 2018 04:48:09 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42592 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439027AbeKWJsF (ORCPT ); Fri, 23 Nov 2018 04:48:05 -0500 Received: by mail-wr1-f68.google.com with SMTP id q18so10625361wrx.9 for ; Thu, 22 Nov 2018 15:06:24 -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=IbiZMxZ1VO+oq3PPG9CYoeHdONpyxtiR/dJlfWGOFuM=; b=T4K3az4t82i0Ac2r+BxmC0hPMQj4h+RNciDIZX0gor0KXnFbblv8jxEcp28kxkNQiS YBGqY4YwrbcgdnKxIM4/f6jemcAxYDRkP+r9cXmwruS7GqJxCkl0LhaoYBAG5NvFX3OB 2ga0ssI9j6TolYHG74/Il5lVNbmaUyEyMeLSxohqxzfVLvcoL1yYxeI0C91MedUe5YH8 E3Gphyn0zq/P4JqxmexXCAeNVmgEJ3ru0blPM6JTbt/ucKus+CGe1Yo4J07zIaxc4/XD H3jxLsPyZJ5dSMZ5K3/veTZZQte97YjUS3VLtQtDwfsaHp+zEEH5m4drQCMS6Kv/Tuqf eoAg== 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=IbiZMxZ1VO+oq3PPG9CYoeHdONpyxtiR/dJlfWGOFuM=; b=pPM59FU0tdGfKTaVLCtfSfbDFkdd0PgHw392hcJ58ctpdl73Y7corZIyO9BH9Fy0XB RRvwHmETOJ+9lL75qQKLQc5wROjrlvPWf7StZ07GGS29MgKPQZpO2/8ZT7aTFZIaarXn dMY7O/vnDeujKZCzxqkOI4757YC+fCzZoWnaYXNfmMKSUokY4E0Iw6sVczA4XShKyaKK E7qr72BVRri+fuplVveMoe+mDmpgSPALcB300QlUCe06tyKrZQB432Imr0KUJJT5FMt0 pmj+MS8z0ywzm2522GXvPnp80UCZvz77/Jy/sBQv9RZvxIZH+CdezSe7F34Cy2GjC5+d Xuvw== X-Gm-Message-State: AA+aEWZ/ccWu5sqarP27l84C269Vj6xEzDppUQhQVLzefE662CRYvIEO GGNQ8vaoU+TEPBvxSBbfAF2J+yAO X-Google-Smtp-Source: AFSGD/XagGVspv3Y1vK1v62rjPkuhT8DmNrTrTf+OuIUiVKqyIC9nQ1T8kYQsfZ782hg2/YZqgfKWg== X-Received: by 2002:adf:9c8a:: with SMTP id d10mr11189396wre.244.1542927983982; Thu, 22 Nov 2018 15:06:23 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:23 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 12/22] stash: convert pop to builtin Date: Fri, 23 Nov 2018 01:05:32 +0200 Message-Id: <3fef00c4cb29a9096eefd0ee1512b58a5b658ccc.1542925164.git.ungureanupaulsebastian@gmail.com> 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 From: Joel Teichroeb Add stash pop to the helper and delete the pop_stash, drop_stash, assert_stash_ref functions from the shell script now that they are no longer needed. Signed-off-by: Joel Teichroeb Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 39 +++++++++++++++++++++++++++++++++- git-stash.sh | 47 ++--------------------------------------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 68b65165e4..d7ff78784b 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -13,7 +13,7 @@ static const char * const git_stash_helper_usage[] = { N_("git stash--helper drop [-q|--quiet] []"), - N_("git stash--helper apply [--index] [-q|--quiet] []"), + N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] []"), N_("git stash--helper branch []"), N_("git stash--helper clear"), NULL @@ -24,6 +24,11 @@ static const char * const git_stash_helper_drop_usage[] = { NULL }; +static const char * const git_stash_helper_pop_usage[] = { + N_("git stash--helper pop [--index] [-q|--quiet] []"), + NULL +}; + static const char * const git_stash_helper_apply_usage[] = { N_("git stash--helper apply [--index] [-q|--quiet] []"), NULL @@ -543,6 +548,36 @@ static int drop_stash(int argc, const char **argv, const char *prefix) return ret; } +static int pop_stash(int argc, const char **argv, const char *prefix) +{ + int ret; + int index = 0; + int quiet = 0; + struct stash_info info; + struct option options[] = { + OPT__QUIET(&quiet, N_("be quiet, only report errors")), + OPT_BOOL(0, "index", &index, + N_("attempt to recreate the index")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_pop_usage, 0); + + if (get_stash_info(&info, argc, argv)) + return -1; + + assert_stash_ref(&info); + if ((ret = do_apply_stash(prefix, &info, index, quiet))) + printf_ln(_("The stash entry is kept in case " + "you need it again.")); + else + ret = do_drop_stash(prefix, &info, quiet); + + free_stash_info(&info); + return ret; +} + static int branch_stash(int argc, const char **argv, const char *prefix) { int ret; @@ -607,6 +642,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!clear_stash(argc, argv, prefix); else if (!strcmp(argv[0], "drop")) return !!drop_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "pop")) + return !!pop_stash(argc, argv, prefix); else if (!strcmp(argv[0], "branch")) return !!branch_stash(argc, argv, prefix); diff --git a/git-stash.sh b/git-stash.sh index 29d9f44255..8f2640fe90 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -554,50 +554,6 @@ assert_stash_like() { } } -is_stash_ref() { - is_stash_like "$@" && test -n "$IS_STASH_REF" -} - -assert_stash_ref() { - is_stash_ref "$@" || { - args="$*" - die "$(eval_gettext "'\$args' is not a stash reference")" - } -} - -apply_stash () { - cd "$START_DIR" - git stash--helper apply "$@" - res=$? - cd_to_toplevel - return $res -} - -pop_stash() { - assert_stash_ref "$@" - - if apply_stash "$@" - then - drop_stash "$@" - else - status=$? - say "$(gettext "The stash entry is kept in case you need it again.")" - exit $status - fi -} - -drop_stash () { - assert_stash_ref "$@" - - git reflog delete --updateref --rewrite "${REV}" && - say "$(eval_gettext "Dropped \${REV} (\$s)")" || - die "$(eval_gettext "\${REV}: Could not drop stash entry")" - - # clear_stash if we just dropped the last stash entry - git rev-parse --verify --quiet "$ref_stash@{0}" >/dev/null || - clear_stash -} - test "$1" = "-p" && set "push" "$@" PARSE_CACHE='--not-parsed' @@ -655,7 +611,8 @@ drop) ;; pop) shift - pop_stash "$@" + cd "$START_DIR" + git stash--helper pop "$@" ;; branch) shift From patchwork Thu Nov 22 23:05:33 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: 10694949 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 431371734 for ; Thu, 22 Nov 2018 23:06:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 337192C1A2 for ; Thu, 22 Nov 2018 23:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 274F72C1BB; Thu, 22 Nov 2018 23:06:32 +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 BA0DB2C1A6 for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439047AbeKWJsJ (ORCPT ); Fri, 23 Nov 2018 04:48:09 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43995 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439014AbeKWJsG (ORCPT ); Fri, 23 Nov 2018 04:48:06 -0500 Received: by mail-wr1-f65.google.com with SMTP id r10so10620348wrs.10 for ; Thu, 22 Nov 2018 15:06:26 -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=qCWPKzE8TtH9y9sepdaj2YEhS43ZgOckmtKp8mNKDkY=; b=JlwCDokBh4nxla0/FSVFCKbQG7rCM450kYOYqhRHHUUpDCOCQN28AWzupvqczQapVo oQs5ODNg0GWIQ2eGFB+quxB5AwOXhQJWF95J77eIwQb345MUWkUdFMWPT+mz3QiFGCCU cB4+Dgo1RNziavHwCg/eejEjAYmwRefz5I+zblD1nJSwjI0fJo4KkRTf+ck5qBginkPY quOcLtn+HV2oM61qvsFE2976eghKJlE9T6D7Az3joerEcgbg3vK72wIz3q3OcjulEGEm VHpo4jfYtrwRFkqUvFdtw0UJ6FlLJopJs9+WlMqm97K3SCsN/XAQvGdG+qOVBK9g5S5o vNpA== 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=qCWPKzE8TtH9y9sepdaj2YEhS43ZgOckmtKp8mNKDkY=; b=GKscAp+tjaa3x7dBsyTMYxnxRtv1KBu0OfAMkkTqpiv4EW/17NzOp8A6qmnBMxhgAs b6uUO6XypZ/zOf79/IHUf/HSO6TIiwjjB58DgEFqKJ5XOqbRQ2cCMKl39GKKnEVcKx4u uiXbIinCvz+xbMfNavRRNtyKKXjWpeAxWCTsF+HPgoD9XU4xJODR2B3MUMwTr7P8FZmn R7f0lnH5RwOH2CRzkp7JVEXhBscU9HxODFf6gAhWrQ82erweaUpIz50avaZoipMecwYb oSxCKa9wq68Y8L5hmmaJEM7tX3gzfWVWOb3A1HS0ZqAEYi2Ufs2/kLapJtR9gdhECxDi E/LQ== X-Gm-Message-State: AA+aEWbNI97WdblGbsfqhPhQoReRmDgWnMdcOwAB0SluSKXIYgxW2oTH 0jpSve0yNqPULhyhxxfheIjvpdcQ X-Google-Smtp-Source: AFSGD/W9BqV2v83OSy7UF09lzYfBoHSaFIxlCqEHPn/OTGwDou8E4VGuC8QM2H3S68xksWPP+I+wng== X-Received: by 2002:adf:ee4e:: with SMTP id w14mr12262622wro.112.1542927985034; Thu, 22 Nov 2018 15:06:25 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:24 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 13/22] stash: convert list to builtin Date: Fri, 23 Nov 2018 01:05:33 +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 Add stash list to the helper and delete the list_stash function from the shell script. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 31 +++++++++++++++++++++++++++++++ git-stash.sh | 7 +------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index d7ff78784b..d66a4589a5 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -12,6 +12,7 @@ #include "rerere.h" static const char * const git_stash_helper_usage[] = { + N_("git stash--helper list []"), N_("git stash--helper drop [-q|--quiet] []"), N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] []"), N_("git stash--helper branch []"), @@ -19,6 +20,11 @@ static const char * const git_stash_helper_usage[] = { NULL }; +static const char * const git_stash_helper_list_usage[] = { + N_("git stash--helper list []"), + NULL +}; + static const char * const git_stash_helper_drop_usage[] = { N_("git stash--helper drop [-q|--quiet] []"), NULL @@ -616,6 +622,29 @@ static int branch_stash(int argc, const char **argv, const char *prefix) return ret; } +static int list_stash(int argc, const char **argv, const char *prefix) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_list_usage, + PARSE_OPT_KEEP_UNKNOWN); + + if (!ref_exists(ref_stash)) + return 0; + + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g", + "--first-parent", "-m", NULL); + argv_array_pushv(&cp.args, argv); + argv_array_push(&cp.args, ref_stash); + argv_array_push(&cp.args, "--"); + return run_command(&cp); +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -646,6 +675,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!pop_stash(argc, argv, prefix); else if (!strcmp(argv[0], "branch")) return !!branch_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "list")) + return !!list_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index 8f2640fe90..6052441aa2 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -382,11 +382,6 @@ have_stash () { git rev-parse --verify --quiet $ref_stash >/dev/null } -list_stash () { - have_stash || return 0 - git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash -- -} - show_stash () { ALLOW_UNKNOWN_FLAGS=t assert_stash_like "$@" @@ -574,7 +569,7 @@ test -n "$seen_non_option" || set "push" "$@" case "$1" in list) shift - list_stash "$@" + git stash--helper list "$@" ;; show) shift From patchwork Thu Nov 22 23:05:34 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: 10694969 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 874B71734 for ; Thu, 22 Nov 2018 23:06:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75A3D2BC3D for ; Thu, 22 Nov 2018 23:06:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 678BE2C1A2; Thu, 22 Nov 2018 23:06:44 +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 987452BC3D for ; Thu, 22 Nov 2018 23:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439045AbeKWJsJ (ORCPT ); Fri, 23 Nov 2018 04:48:09 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34401 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439015AbeKWJsH (ORCPT ); Fri, 23 Nov 2018 04:48:07 -0500 Received: by mail-wr1-f65.google.com with SMTP id j2so10660505wrw.1 for ; Thu, 22 Nov 2018 15:06:26 -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=BLrcBN8nCLZ3dL8s/i19Eq4ny00vWmFxreuQEA/H/SU=; b=sUA3NQCFQxBOWcBc1b+a66WNRNGWORScr3UqZPGN/7S3qiuu/Dt4y4wFrNHvV9NQwY jdDQkClvOjd+ZqhoMbrpzy0J+b+uQ86FwLD4TYTCB69Agv3Ab4R4pFi2bj3V0ZOZ0Pjg Fc+GmwZRk1ymjFz/l4vsqypnTubdhOPHNUk+gTNBLVrX5JEEgMp564xMmyqNPcTOo31n FkECV4o3WwB8tl94XLd+h/Bc1nKiKlKy0r6yD6VVtyXXNS5n45dCNZ6eO46FO8Q50mEO IPN23r5Jf6bhQ1n8nIJXAHG2ZrMk5qgAmR7jmdcMJlT2wYsgPShUvUHrObeo9uisNyfw OiKg== 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=BLrcBN8nCLZ3dL8s/i19Eq4ny00vWmFxreuQEA/H/SU=; b=ileMHXjGFmDoL0pX3RkDlVPTEEByQhCBiTjB7CuyFU2IeCePvVuMsJMzIVQGZQd90c CYAPakYgbvGTzg13+tomKBAlAawTn6So3bSTNlEanxnQwgvJJST8awq9ycR/h03FyqTH T7H+rLl3orgELEXQGMGNC/QwkV01S/nyKySOHpRNqJxUSUYZS6woGC5l8fMxgI9ekgm8 VS9LzCncP0MdT8B8Y0sRmgqssjs4oHgNh854Fjd9goEVawCnoT/MPrERVed8CGs8eZWI VL4Bp4GQxUzQljX+wN/B8IMaqW0RYyaMTqUiZGkiJkX5QoG6n1tEZMBIXkyykFJ2kRD3 VWBg== X-Gm-Message-State: AA+aEWba5ac0i7+mXo6CFyDs4A17Y9yr8mvObSRMcR7qnZ9mO8Ae43xG dD5T2JAFmIwgWtKKoiFKiE/8s96l X-Google-Smtp-Source: AFSGD/V5LaWzF5MAks65EE9QAEAGG3iPWS9OKNpy94j1xBuGfGE9AKu/zZivMM++bW3DMD9CorZ1cw== X-Received: by 2002:a5d:4c8a:: with SMTP id z10mr7583444wrs.75.1542927985868; Thu, 22 Nov 2018 15:06:25 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:25 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 14/22] stash: convert show to builtin Date: Fri, 23 Nov 2018 01:05:34 +0200 Message-Id: <3e141cf7471ea0db65a5308105d549cd59388a6a.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Add stash show to the helper and delete the show_stash, have_stash, assert_stash_like, is_stash_like and parse_flags_and_rev functions from the shell script now that they are no longer needed. In shell version, although `git stash show` accepts `--index` and `--quiet` options, it ignores them. In C, both options are passed further to `git diff`. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 87 ++++++++++++++++++++++++++ git-stash.sh | 132 +--------------------------------------- 2 files changed, 88 insertions(+), 131 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index d66a4589a5..36651f745a 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -10,9 +10,12 @@ #include "run-command.h" #include "dir.h" #include "rerere.h" +#include "revision.h" +#include "log-tree.h" static const char * const git_stash_helper_usage[] = { N_("git stash--helper list []"), + N_("git stash--helper show [] []"), N_("git stash--helper drop [-q|--quiet] []"), N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] []"), N_("git stash--helper branch []"), @@ -25,6 +28,11 @@ static const char * const git_stash_helper_list_usage[] = { NULL }; +static const char * const git_stash_helper_show_usage[] = { + N_("git stash--helper show [] []"), + NULL +}; + static const char * const git_stash_helper_drop_usage[] = { N_("git stash--helper drop [-q|--quiet] []"), NULL @@ -645,6 +653,83 @@ static int list_stash(int argc, const char **argv, const char *prefix) return run_command(&cp); } +static int show_stat = 1; +static int show_patch; + +static int git_stash_config(const char *var, const char *value, void *cb) +{ + if (!strcmp(var, "stash.showstat")) { + show_stat = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "stash.showpatch")) { + show_patch = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); +} + +static int show_stash(int argc, const char **argv, const char *prefix) +{ + int i; + int opts = 0; + int ret = 0; + struct stash_info info; + struct rev_info rev; + struct argv_array stash_args = ARGV_ARRAY_INIT; + struct option options[] = { + OPT_END() + }; + + init_diff_ui_defaults(); + git_config(git_diff_ui_config, NULL); + init_revisions(&rev, prefix); + + for (i = 1; i < argc; i++) { + if (argv[i][0] != '-') + argv_array_push(&stash_args, argv[i]); + else + opts++; + } + + ret = get_stash_info(&info, stash_args.argc, stash_args.argv); + argv_array_clear(&stash_args); + if (ret) + return -1; + + /* + * The config settings are applied only if there are not passed + * any options. + */ + if (!opts) { + git_config(git_stash_config, NULL); + if (show_stat) + rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT; + + if (show_patch) + rev.diffopt.output_format |= DIFF_FORMAT_PATCH; + + if (!show_stat && !show_patch) { + free_stash_info(&info); + return 0; + } + } + + argc = setup_revisions(argc, argv, &rev, NULL); + if (argc > 1) { + free_stash_info(&info); + usage_with_options(git_stash_helper_show_usage, options); + } + + rev.diffopt.flags.recursive = 1; + setup_diff_pager(&rev.diffopt); + diff_tree_oid(&info.b_commit, &info.w_commit, "", &rev.diffopt); + log_tree_diff_flush(&rev); + + free_stash_info(&info); + return diff_result_code(&rev.diffopt, 0); +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -677,6 +762,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!branch_stash(argc, argv, prefix); else if (!strcmp(argv[0], "list")) return !!list_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "show")) + return !!show_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index 6052441aa2..0d05cbc1e5 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -378,35 +378,6 @@ save_stash () { fi } -have_stash () { - git rev-parse --verify --quiet $ref_stash >/dev/null -} - -show_stash () { - ALLOW_UNKNOWN_FLAGS=t - assert_stash_like "$@" - - if test -z "$FLAGS" - then - if test "$(git config --bool stash.showStat || echo true)" = "true" - then - FLAGS=--stat - fi - - if test "$(git config --bool stash.showPatch || echo false)" = "true" - then - FLAGS=${FLAGS}${FLAGS:+ }-p - fi - - if test -z "$FLAGS" - then - return 0 - fi - fi - - git diff ${FLAGS} $b_commit $w_commit -} - show_help () { exec git help stash exit 1 @@ -448,107 +419,6 @@ show_help () { # * unknown flags were set and ALLOW_UNKNOWN_FLAGS is not "t" # -parse_flags_and_rev() -{ - test "$PARSE_CACHE" = "$*" && return 0 # optimisation - PARSE_CACHE="$*" - - IS_STASH_LIKE= - IS_STASH_REF= - INDEX_OPTION= - s= - w_commit= - b_commit= - i_commit= - u_commit= - w_tree= - b_tree= - i_tree= - u_tree= - - FLAGS= - REV= - for opt - do - case "$opt" in - -q|--quiet) - GIT_QUIET=-t - ;; - --index) - INDEX_OPTION=--index - ;; - --help) - show_help - ;; - -*) - test "$ALLOW_UNKNOWN_FLAGS" = t || - die "$(eval_gettext "unknown option: \$opt")" - FLAGS="${FLAGS}${FLAGS:+ }$opt" - ;; - *) - REV="${REV}${REV:+ }'$opt'" - ;; - esac - done - - eval set -- $REV - - case $# in - 0) - have_stash || die "$(gettext "No stash entries found.")" - set -- ${ref_stash}@{0} - ;; - 1) - : - ;; - *) - die "$(eval_gettext "Too many revisions specified: \$REV")" - ;; - esac - - case "$1" in - *[!0-9]*) - : - ;; - *) - set -- "${ref_stash}@{$1}" - ;; - esac - - REV=$(git rev-parse --symbolic --verify --quiet "$1") || { - reference="$1" - die "$(eval_gettext "\$reference is not a valid reference")" - } - - i_commit=$(git rev-parse --verify --quiet "$REV^2") && - set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) && - s=$1 && - w_commit=$1 && - b_commit=$2 && - w_tree=$3 && - b_tree=$4 && - i_tree=$5 && - IS_STASH_LIKE=t && - test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" && - IS_STASH_REF=t - - u_commit=$(git rev-parse --verify --quiet "$REV^3") && - u_tree=$(git rev-parse "$REV^3:" 2>/dev/null) -} - -is_stash_like() -{ - parse_flags_and_rev "$@" - test -n "$IS_STASH_LIKE" -} - -assert_stash_like() { - is_stash_like "$@" || { - args="$*" - die "$(eval_gettext "'\$args' is not a stash-like commit")" - } -} - test "$1" = "-p" && set "push" "$@" PARSE_CACHE='--not-parsed' @@ -573,7 +443,7 @@ list) ;; show) shift - show_stash "$@" + git stash--helper show "$@" ;; save) shift From patchwork Thu Nov 22 23:05:35 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: 10694945 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 9CBDD1926 for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 893962C19A for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D9FC2C1BB; Thu, 22 Nov 2018 23:06:31 +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 03DD02C19A for ; Thu, 22 Nov 2018 23:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439042AbeKWJsI (ORCPT ); Fri, 23 Nov 2018 04:48:08 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46383 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439039AbeKWJsI (ORCPT ); Fri, 23 Nov 2018 04:48:08 -0500 Received: by mail-wr1-f68.google.com with SMTP id l9so10627705wrt.13 for ; Thu, 22 Nov 2018 15:06:27 -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=y2T5Uayc6MnUVYzv8m/7ncE4zXMb4iU1dcWdyH0zOgI=; b=uVn7mYb4XBgKHcI14K1QxPc0M5WLO32w4hLc8ThVG90JACDoAGOhl3ezr+v5r/6kq0 CHA3S5bNyYsJmEs4FNhqlLJISLyLPD3A8xNIgipmJEVEvx0UTma45gC/PPnEpkmqCO64 2ETSk4nSEH7LhLO+QrdBTxwdUJGmUdnEDocYf20hGnScyR378BTJG1BtLLyL7aQNlACt 97JF8GBXpvPF7VSeN8ttj1GrpjPNPpWiE4+z7bLMast9hlM7Tt1o6lmSadxXfr0arJ8/ VoBe0l8dLLZHyVCVC6lkTAKSTxY0zry/MCy5XFmkO+nLiaMBKKrsrX/h7swkiw5pucQm nHtA== 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=y2T5Uayc6MnUVYzv8m/7ncE4zXMb4iU1dcWdyH0zOgI=; b=DX5JT3e8NQQXwaZQS4G3yrOMFVknTNxG3O2Sj5JOaCZXwmOHrbwi0fIaGCTeR7lMV0 CTzDFht5P/zzsV+SR3JUg1T73V7u95o4RAb4pEl3Z3qM1Gxc2R+SyQnEfIf0R7U+v5ZS K/FEGLpH1zUSmtX0J6R/A6dfRZEMaPDEdtd0oiEREOyt/iLlnuFNVpGKFOw+p/riW/1I zM6VMqhRP4baAGA+5F12iUL1qkE2wq1aVjCHF5U1uUFXlhruHC7bH/Bfoft17wmYHHsR qfPD/TJOwQY9x91WsJs1RoikQhAko2dSf/oOWl7rvKDjg5n52j6Minw3Kal6EbU+pV8L DTlA== X-Gm-Message-State: AA+aEWZqhonekQyhflr8r4d5KgHwQ5J/BkVfYshg78hPHiFPIZaCJe9/ 3jIbqPsXKPhqvdKDf6XF4y2hhO4L X-Google-Smtp-Source: AFSGD/VkcySMBfeVnJ7+xXPeub0qxrPrHkKwGwa/5zWqYBxFF2Oq3XWGT2Xn+OHVnL7a61MsopkG5Q== X-Received: by 2002:adf:8b8e:: with SMTP id o14-v6mr7795607wra.81.1542927986925; Thu, 22 Nov 2018 15:06:26 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:26 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 15/22] stash: convert store to builtin Date: Fri, 23 Nov 2018 01:05:35 +0200 Message-Id: <44347155280b80aa50599ba81fcadf9a25039fc5.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Add stash store to the helper and delete the store_stash function from the shell script. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 62 +++++++++++++++++++++++++++++++++++++++++ git-stash.sh | 43 ++-------------------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 36651f745a..5dc6c068d7 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -58,6 +58,11 @@ static const char * const git_stash_helper_clear_usage[] = { NULL }; +static const char * const git_stash_helper_store_usage[] = { + N_("git stash--helper store [-m|--message ] [-q|--quiet] "), + NULL +}; + static const char *ref_stash = "refs/stash"; static struct strbuf stash_index_path = STRBUF_INIT; @@ -730,6 +735,61 @@ static int show_stash(int argc, const char **argv, const char *prefix) return diff_result_code(&rev.diffopt, 0); } +static int do_store_stash(const struct object_id *w_commit, const char *stash_msg, + int quiet) +{ + if (!stash_msg) + stash_msg = "Created via \"git stash store\"."; + + if (update_ref(stash_msg, ref_stash, w_commit, NULL, + REF_FORCE_CREATE_REFLOG, + quiet ? UPDATE_REFS_QUIET_ON_ERR : + UPDATE_REFS_MSG_ON_ERR)) { + if (!quiet) { + fprintf_ln(stderr, _("Cannot update %s with %s"), + ref_stash, oid_to_hex(w_commit)); + } + return -1; + } + + return 0; +} + +static int store_stash(int argc, const char **argv, const char *prefix) +{ + int quiet = 0; + const char *stash_msg = NULL; + struct object_id obj; + struct object_context dummy; + struct option options[] = { + OPT__QUIET(&quiet, N_("be quiet")), + OPT_STRING('m', "message", &stash_msg, "message", + N_("stash message")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_store_usage, + PARSE_OPT_KEEP_UNKNOWN); + + if (argc != 1) { + if (!quiet) + fprintf_ln(stderr, _("\"git stash store\" requires one " + " argument")); + return -1; + } + + if (get_oid_with_context(argv[0], quiet ? GET_OID_QUIETLY : 0, &obj, + &dummy)) { + if (!quiet) + fprintf_ln(stderr, _("Cannot update %s with %s"), + ref_stash, argv[0]); + return -1; + } + + return do_store_stash(&obj, stash_msg, quiet); +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -764,6 +824,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!list_stash(argc, argv, prefix); else if (!strcmp(argv[0], "show")) return !!show_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "store")) + return !!store_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index 0d05cbc1e5..5739c51527 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -191,45 +191,6 @@ create_stash () { die "$(gettext "Cannot record working tree state")" } -store_stash () { - while test $# != 0 - do - case "$1" in - -m|--message) - shift - stash_msg="$1" - ;; - -m*) - stash_msg=${1#-m} - ;; - --message=*) - stash_msg=${1#--message=} - ;; - -q|--quiet) - quiet=t - ;; - *) - break - ;; - esac - shift - done - test $# = 1 || - die "$(eval_gettext "\"$dashless store\" requires one argument")" - - w_commit="$1" - if test -z "$stash_msg" - then - stash_msg="Created via \"git stash store\"." - fi - - git update-ref --create-reflog -m "$stash_msg" $ref_stash $w_commit - ret=$? - test $ret != 0 && test -z "$quiet" && - die "$(eval_gettext "Cannot update \$ref_stash with \$w_commit")" - return $ret -} - push_stash () { keep_index= patch_mode= @@ -308,7 +269,7 @@ push_stash () { clear_stash || die "$(gettext "Cannot initialize stash")" create_stash -m "$stash_msg" -u "$untracked" -- "$@" - store_stash -m "$stash_msg" -q $w_commit || + git stash--helper store -m "$stash_msg" -q $w_commit || die "$(gettext "Cannot save the current status")" say "$(eval_gettext "Saved working directory and index state \$stash_msg")" @@ -468,7 +429,7 @@ create) ;; store) shift - store_stash "$@" + git stash--helper store "$@" ;; drop) shift From patchwork Thu Nov 22 23:05:36 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: 10694953 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 617271734 for ; Thu, 22 Nov 2018 23:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D5AD2C19A for ; Thu, 22 Nov 2018 23:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 411FA2C1BB; Thu, 22 Nov 2018 23:06:35 +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 22BE42C19A for ; Thu, 22 Nov 2018 23:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439053AbeKWJsL (ORCPT ); Fri, 23 Nov 2018 04:48:11 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53288 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733045AbeKWJsK (ORCPT ); Fri, 23 Nov 2018 04:48:10 -0500 Received: by mail-wm1-f66.google.com with SMTP id y1so7068165wmi.3 for ; Thu, 22 Nov 2018 15:06:29 -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=xidGMAiBkStUVRrwKSJti5wzqb81Lq+PNftpicY7Tws=; b=rFwOXkErL1MOHOLQykJiqktOSDxcKHuoXnYPh0oURRhGxlayPdOPeA0qzKh9w2dhnE MZypQh0GD4sn5+n1rFekg8jDvUO468rnKGR+QwzvPjzLtuUfJORwM4lI6umvAFpw4bAN J3I4cRk+fPkQ9FGp3SWs1dohvwZa4dntVV4HHaOtPMmHQ31/jyCq2LoFby/R0L06CsuI bIslEcspkzQopfAvMu5ivOuK5/o8M3MDM0ZWay8OG5juM6LUgQbqhqdqMZx0qLjridsq 0ri4ju0LM4Jv6iochHMN6RA5/k78tyyuQcFMPD6HBdIhws+7VPjJjg7voKTdlwggMHkE r/6g== 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=xidGMAiBkStUVRrwKSJti5wzqb81Lq+PNftpicY7Tws=; b=TlowKFMc9jA9Zi7R0LpttnzFw4ysM9KRJjw6zJjD9N+poSUc03e8wtLASRyt/Wfo04 4SdSjQEEWmmhpVdT085WL322Ygbyd84eKUj483fSlXskKWea4h3nm/QR25IJMhGOmMKu koLo7V8dOs4suwlhI4OqQIq0KN+HxBlaF2rLlkpzN138f0LPUEbIJ+9igdxhlivsfdVU f1MztF8VHR3VJ+ufwCTrKvTOYKDTgLJJa35SQ3chp+7AsywMhbSCC2QuIgcjLNoiSSNG W8UxY7KBkdMHZvGlPWxrLakrxnFpmDhP0fry9f0Iaqf4IPC2+XmmtGtw2yr+DBJb0cZU hp4A== X-Gm-Message-State: AA+aEWZAZ+2Wzet6Likem795mRpO9lIz8dSJ0kDfHMn5R4Fb7V5cx1gS os44auRzlRSzD3GLlkeYbkF+2CvD X-Google-Smtp-Source: AFSGD/U+b4ozKWPhPSs58wwzHyZ6gxvROxCSb96zmMokGOp5HO6OXozP9uQGr02/UDyKD7qopHzTSw== X-Received: by 2002:a1c:2007:: with SMTP id g7mr7624152wmg.79.1542927987953; Thu, 22 Nov 2018 15:06:27 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:27 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 16/22] stash: convert create to builtin Date: Fri, 23 Nov 2018 01:05:36 +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 Add stash create to the helper. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 451 +++++++++++++++++++++++++++++++++++++++- git-stash.sh | 2 +- 2 files changed, 451 insertions(+), 2 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 5dc6c068d7..cd769d87b3 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -12,6 +12,9 @@ #include "rerere.h" #include "revision.h" #include "log-tree.h" +#include "diffcore.h" + +#define INCLUDE_ALL_FILES 2 static const char * const git_stash_helper_usage[] = { N_("git stash--helper list []"), @@ -63,6 +66,11 @@ static const char * const git_stash_helper_store_usage[] = { NULL }; +static const char * const git_stash_helper_create_usage[] = { + N_("git stash--helper create []"), + NULL +}; + static const char *ref_stash = "refs/stash"; static struct strbuf stash_index_path = STRBUF_INIT; @@ -288,6 +296,24 @@ static int reset_head(void) return run_command(&cp); } +static void add_diff_to_buf(struct diff_queue_struct *q, + struct diff_options *options, + void *data) +{ + int i; + + for (i = 0; i < q->nr; i++) { + strbuf_addstr(data, q->queue[i]->one->path); + + /* + * The reason we add "0" at the end of this strbuf + * is because we will pass the output further to + * "git update-index -z ...". + */ + strbuf_addch(data, '\0'); + } +} + static int get_newly_staged(struct strbuf *out, struct object_id *c_tree) { struct child_process cp = CHILD_PROCESS_INIT; @@ -790,6 +816,427 @@ static int store_stash(int argc, const char **argv, const char *prefix) return do_store_stash(&obj, stash_msg, quiet); } +static void add_pathspecs(struct argv_array *args, + struct pathspec ps) { + int i; + + for (i = 0; i < ps.nr; i++) + argv_array_push(args, ps.items[i].match); +} + +/* + * `untracked_files` will be filled with the names of untracked files. + * The return value is: + * + * = 0 if there are not any untracked files + * > 0 if there are untracked files + */ +static int get_untracked_files(struct pathspec ps, int include_untracked, + struct strbuf *untracked_files) +{ + int i; + int max_len; + int found = 0; + char *seen; + struct dir_struct dir; + + memset(&dir, 0, sizeof(dir)); + if (include_untracked != INCLUDE_ALL_FILES) + setup_standard_excludes(&dir); + + seen = xcalloc(ps.nr, 1); + + max_len = fill_directory(&dir, the_repository->index, &ps); + for (i = 0; i < dir.nr; i++) { + struct dir_entry *ent = dir.entries[i]; + if (dir_path_match(&the_index, ent, &ps, max_len, seen)) { + found++; + strbuf_addstr(untracked_files, ent->name); + /* NUL-terminate: will be fed to update-index -z */ + strbuf_addch(untracked_files, 0); + } + free(ent); + } + + free(seen); + free(dir.entries); + free(dir.ignored); + clear_directory(&dir); + return found; +} + +/* + * The return value of `check_changes()` can be: + * + * < 0 if there was an error + * = 0 if there are no changes. + * > 0 if there are changes. + */ +static int check_changes(struct pathspec ps, int include_untracked) +{ + int result; + struct rev_info rev; + struct object_id dummy; + struct strbuf out = STRBUF_INIT; + + /* No initial commit. */ + if (get_oid("HEAD", &dummy)) + return -1; + + if (read_cache() < 0) + return -1; + + init_revisions(&rev, NULL); + rev.prune_data = ps; + + rev.diffopt.flags.quick = 1; + rev.diffopt.flags.ignore_submodules = 1; + rev.abbrev = 0; + + add_head_to_pending(&rev); + diff_setup_done(&rev.diffopt); + + result = run_diff_index(&rev, 1); + if (diff_result_code(&rev.diffopt, result)) + return 1; + + object_array_clear(&rev.pending); + result = run_diff_files(&rev, 0); + if (diff_result_code(&rev.diffopt, result)) + return 1; + + if (include_untracked && get_untracked_files(ps, include_untracked, + &out)) { + strbuf_release(&out); + return 1; + } + + strbuf_release(&out); + return 0; +} + +static int save_untracked_files(struct stash_info *info, struct strbuf *msg, + struct strbuf files) +{ + int ret = 0; + struct strbuf untracked_msg = STRBUF_INIT; + struct strbuf out = STRBUF_INIT; + struct child_process cp_upd_index = CHILD_PROCESS_INIT; + struct child_process cp_write_tree = CHILD_PROCESS_INIT; + + cp_upd_index.git_cmd = 1; + argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", + "--remove", "--stdin", NULL); + argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + + strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf); + if (pipe_command(&cp_upd_index, files.buf, files.len, NULL, 0, + NULL, 0)) { + ret = -1; + goto done; + } + + cp_write_tree.git_cmd = 1; + argv_array_push(&cp_write_tree.args, "write-tree"); + argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + ret = -1; + goto done; + } + get_oid_hex(out.buf, &info->u_tree); + + if (commit_tree(untracked_msg.buf, untracked_msg.len, + &info->u_tree, NULL, &info->u_commit, NULL, NULL)) { + ret = -1; + goto done; + } + +done: + strbuf_release(&untracked_msg); + strbuf_release(&out); + remove_path(stash_index_path.buf); + return ret; +} + +static int stash_patch(struct stash_info *info, struct pathspec ps, + struct strbuf *out_patch) +{ + int ret = 0; + struct strbuf out = STRBUF_INIT; + struct child_process cp_read_tree = CHILD_PROCESS_INIT; + struct child_process cp_add_i = CHILD_PROCESS_INIT; + struct child_process cp_write_tree = CHILD_PROCESS_INIT; + struct child_process cp_diff_tree = CHILD_PROCESS_INIT; + + remove_path(stash_index_path.buf); + + cp_read_tree.git_cmd = 1; + argv_array_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL); + argv_array_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (run_command(&cp_read_tree)) { + ret = -1; + goto done; + } + + /* Find out what the user wants. */ + cp_add_i.git_cmd = 1; + argv_array_pushl(&cp_add_i.args, "add--interactive", "--patch=stash", + "--", NULL); + add_pathspecs(&cp_add_i.args, ps); + argv_array_pushf(&cp_add_i.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (run_command(&cp_add_i)) { + ret = -1; + goto done; + } + + /* State of the working tree. */ + cp_write_tree.git_cmd = 1; + argv_array_push(&cp_write_tree.args, "write-tree"); + argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + ret = -1; + goto done; + } + + get_oid_hex(out.buf, &info->w_tree); + + cp_diff_tree.git_cmd = 1; + argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "HEAD", + oid_to_hex(&info->w_tree), "--", NULL); + if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) { + ret = -1; + goto done; + } + + if (!out_patch->len) { + fprintf_ln(stderr, _("No changes selected")); + ret = 1; + } + +done: + strbuf_release(&out); + remove_path(stash_index_path.buf); + return ret; +} + +static int stash_working_tree(struct stash_info *info, struct pathspec ps) +{ + int ret = 0; + struct rev_info rev; + struct child_process cp_upd_index = CHILD_PROCESS_INIT; + struct child_process cp_write_tree = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + struct strbuf diff_output = STRBUF_INIT; + + set_alternate_index_output(stash_index_path.buf); + if (reset_tree(&info->i_tree, 0, 0)) { + ret = -1; + goto done; + } + set_alternate_index_output(NULL); + + init_revisions(&rev, NULL); + rev.prune_data = ps; + rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; + rev.diffopt.format_callback = add_diff_to_buf; + rev.diffopt.format_callback_data = &diff_output; + + if (read_cache_preload(&rev.diffopt.pathspec) < 0) { + ret = -1; + goto done; + } + + add_pending_object(&rev, parse_object(the_repository, &info->b_commit), + ""); + if (run_diff_index(&rev, 0)) { + ret = -1; + goto done; + } + + cp_upd_index.git_cmd = 1; + argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", + "--remove", "--stdin", NULL); + argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + + if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len, + NULL, 0, NULL, 0)) { + ret = -1; + goto done; + } + + cp_write_tree.git_cmd = 1; + argv_array_push(&cp_write_tree.args, "write-tree"); + argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", + stash_index_path.buf); + if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + ret = -1; + goto done; + } + + get_oid_hex(out.buf, &info->w_tree); + +done: + UNLEAK(rev); + strbuf_release(&out); + object_array_clear(&rev.pending); + strbuf_release(&diff_output); + remove_path(stash_index_path.buf); + return ret; +} + +static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, + int include_untracked, int patch_mode, + struct stash_info *info) +{ + int ret = 0; + int flags = 0; + int untracked_commit_option = 0; + const char *head_short_sha1 = NULL; + const char *branch_ref = NULL; + const char *branch_name = "(no branch)"; + struct commit *head_commit = NULL; + struct commit_list *parents = NULL; + struct strbuf msg = STRBUF_INIT; + struct strbuf commit_tree_label = STRBUF_INIT; + struct strbuf untracked_files = STRBUF_INIT; + struct strbuf patch = STRBUF_INIT; + + read_cache_preload(NULL); + refresh_cache(REFRESH_QUIET); + + if (get_oid("HEAD", &info->b_commit)) { + fprintf_ln(stderr, _("You do not have the initial commit yet")); + ret = -1; + goto done; + } else { + head_commit = lookup_commit(the_repository, &info->b_commit); + } + + if (!check_changes(ps, include_untracked)) { + ret = 1; + goto done; + } + + branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags); + if (flags & REF_ISSYMREF) + branch_name = strrchr(branch_ref, '/') + 1; + head_short_sha1 = find_unique_abbrev(&head_commit->object.oid, + DEFAULT_ABBREV); + strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1); + pp_commit_easy(CMIT_FMT_ONELINE, head_commit, &msg); + + strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf); + commit_list_insert(head_commit, &parents); + if (write_cache_as_tree(&info->i_tree, 0, NULL) || + commit_tree(commit_tree_label.buf, commit_tree_label.len, + &info->i_tree, parents, &info->i_commit, NULL, NULL)) { + fprintf_ln(stderr, _("Cannot save the current index state")); + ret = -1; + goto done; + } + + if (include_untracked && get_untracked_files(ps, include_untracked, + &untracked_files)) { + if (save_untracked_files(info, &msg, untracked_files)) { + fprintf_ln(stderr, _("Cannot save " + "the untracked files")); + ret = -1; + goto done; + } + untracked_commit_option = 1; + } + if (patch_mode) { + ret = stash_patch(info, ps, &patch); + if (ret < 0) { + fprintf_ln(stderr, _("Cannot save the current " + "worktree state")); + goto done; + } else if (ret > 0) { + goto done; + } + } else { + if (stash_working_tree(info, ps)) { + fprintf_ln(stderr, _("Cannot save the current " + "worktree state")); + ret = -1; + goto done; + } + } + + if (!stash_msg_buf->len) + strbuf_addf(stash_msg_buf, "WIP on %s", msg.buf); + else + strbuf_insertf(stash_msg_buf, 0, "On %s: ", branch_name); + + /* + * `parents` will be empty after calling `commit_tree()`, so there is + * no need to call `free_commit_list()` + */ + parents = NULL; + if (untracked_commit_option) + commit_list_insert(lookup_commit(the_repository, + &info->u_commit), + &parents); + commit_list_insert(lookup_commit(the_repository, &info->i_commit), + &parents); + commit_list_insert(head_commit, &parents); + + if (commit_tree(stash_msg_buf->buf, stash_msg_buf->len, &info->w_tree, + parents, &info->w_commit, NULL, NULL)) { + fprintf_ln(stderr, _("Cannot record working tree state")); + ret = -1; + goto done; + } + +done: + strbuf_release(&commit_tree_label); + strbuf_release(&msg); + strbuf_release(&untracked_files); + return ret; +} + +static int create_stash(int argc, const char **argv, const char *prefix) +{ + int include_untracked = 0; + int ret = 0; + const char *stash_msg = NULL; + struct strbuf stash_msg_buf = STRBUF_INIT; + struct stash_info info; + struct pathspec ps; + struct option options[] = { + OPT_BOOL('u', "include-untracked", &include_untracked, + N_("include untracked files in stash")), + OPT_STRING('m', "message", &stash_msg, N_("message"), + N_("stash message")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_create_usage, + 0); + + memset(&ps, 0, sizeof(ps)); + strbuf_addstr(&stash_msg_buf, stash_msg); + ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info); + + if (!ret) + printf_ln("%s", oid_to_hex(&info.w_commit)); + + strbuf_release(&stash_msg_buf); + + /* + * ret can be 1 if there were no changes. In this case, we should + * not error out. + */ + return ret < 0; +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -799,7 +1246,7 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_default_config, NULL); + git_config(git_diff_basic_config, NULL); argc = parse_options(argc, argv, prefix, options, git_stash_helper_usage, PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); @@ -826,6 +1273,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!show_stash(argc, argv, prefix); else if (!strcmp(argv[0], "store")) return !!store_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "create")) + return !!create_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index 5739c51527..ab06e4ffb8 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -425,7 +425,7 @@ clear) ;; create) shift - create_stash -m "$*" && echo "$w_commit" + git stash--helper create --message "$*" ;; store) shift From patchwork Thu Nov 22 23:05:37 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: 10694957 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 580BE14BD for ; Thu, 22 Nov 2018 23:06:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 474E62C19A for ; Thu, 22 Nov 2018 23:06:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BAD12C1A2; Thu, 22 Nov 2018 23:06:36 +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 7D8FB2C1BB for ; Thu, 22 Nov 2018 23:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439059AbeKWJsN (ORCPT ); Fri, 23 Nov 2018 04:48:13 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38665 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439043AbeKWJsL (ORCPT ); Fri, 23 Nov 2018 04:48:11 -0500 Received: by mail-wm1-f68.google.com with SMTP id k198so10475336wmd.3 for ; Thu, 22 Nov 2018 15:06:30 -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=BNkjIsOpc/Shb8SgE/osuYiHJUWU2dDj6u0FzMHbzfg=; b=Fr5qP48wrT7xD4rOOyOXRrO7PBqz8U2uoMYgyjjrHJEhDg5Z3LCxwsnrTgVvXcqFFC VE8QN5OMVKoNO5U0BILOPoMQpzpL0Xb4q9BMdbhRJ01CSTT0xrIqzYWR3g+qfye3J6q3 4SofxK8vS7Jixb/tyAgpt5Wi7doy46NqKYZzvQaTWCKbUjal/cOZY1Kd3QEFyCnYQcdh CfjplJ1W/k9P6skxYiNL9W3cq0lf9FesrHImXjwnA7iP3e1mtKDgHash1RyGwfo0IG3n uxQmZNoXC6NzDfbnPHRyw4lv6m+2Y1kEywc4U723XUF40Xiopq0CwjwilV46G5E85A1e BuDQ== 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=BNkjIsOpc/Shb8SgE/osuYiHJUWU2dDj6u0FzMHbzfg=; b=ODRizqOl8JTrR7aNAI/kDD/8q/9B9eA5Jwolj7PET3u3lCKwJ8XVJljLkxkmenpif3 ZHOn+P+qHnW57xGFVDFY2YvMDs9S4Sr+8j4a+ei4FvzxbiwnLdF8ItC+wzyADGkmW50Q 2QLt0C8GThbYQlAXRGIZgt3KiuAWXPoXEO0yoNf8pHBN+AXh7hwxkBuqVl7v7thExHjJ /0hCfc8iCbi1AjGjayHqgdzluZIyXF0KEIMg5HEaptuu035EAxmlRIr0zgmTDm/Soho3 wWRv77QoPhL1L7eK0S1Y0YdCs/mEUNhlsbxsVLfywBu2nfZy7cx9FGtMYT9Pn8lcrDgR UiwA== X-Gm-Message-State: AA+aEWaM949n+pOh9jKKHYSXm9C/HbPCn4tkoSwPW8TlOBfsSCzg0eH1 qZyQjlins1+KRHiv85T/fcn5VCW4 X-Google-Smtp-Source: AFSGD/UJSLWAdh9vzGdeppxWHdNkmX7cPPFK6Rl/doP6UGex8RFieplbbHXg6sFFZT4mezyRs2Tj6g== X-Received: by 2002:a1c:35c5:: with SMTP id c188-v6mr4105828wma.116.1542927988949; Thu, 22 Nov 2018 15:06:28 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:28 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 17/22] stash: convert push to builtin Date: Fri, 23 Nov 2018 01:05:37 +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 Add stash push to the helper. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 245 +++++++++++++++++++++++++++++++++++++++- git-stash.sh | 6 +- 2 files changed, 245 insertions(+), 6 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index cd769d87b3..8683c662fc 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -23,6 +23,9 @@ static const char * const git_stash_helper_usage[] = { N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] []"), N_("git stash--helper branch []"), N_("git stash--helper clear"), + N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" + " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" + " [--] [...]]"), NULL }; @@ -71,6 +74,13 @@ static const char * const git_stash_helper_create_usage[] = { NULL }; +static const char * const git_stash_helper_push_usage[] = { + N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" + " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" + " [--] [...]]"), + NULL +}; + static const char *ref_stash = "refs/stash"; static struct strbuf stash_index_path = STRBUF_INIT; @@ -1092,7 +1102,7 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, int include_untracked, int patch_mode, - struct stash_info *info) + struct stash_info *info, struct strbuf *patch) { int ret = 0; int flags = 0; @@ -1105,7 +1115,6 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, struct strbuf msg = STRBUF_INIT; struct strbuf commit_tree_label = STRBUF_INIT; struct strbuf untracked_files = STRBUF_INIT; - struct strbuf patch = STRBUF_INIT; read_cache_preload(NULL); refresh_cache(REFRESH_QUIET); @@ -1152,7 +1161,7 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, untracked_commit_option = 1; } if (patch_mode) { - ret = stash_patch(info, ps, &patch); + ret = stash_patch(info, ps, patch); if (ret < 0) { fprintf_ln(stderr, _("Cannot save the current " "worktree state")); @@ -1223,7 +1232,8 @@ static int create_stash(int argc, const char **argv, const char *prefix) memset(&ps, 0, sizeof(ps)); strbuf_addstr(&stash_msg_buf, stash_msg); - ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info); + ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info, + NULL); if (!ret) printf_ln("%s", oid_to_hex(&info.w_commit)); @@ -1237,6 +1247,231 @@ static int create_stash(int argc, const char **argv, const char *prefix) return ret < 0; } +static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, + int keep_index, int patch_mode, int include_untracked) +{ + int ret = 0; + struct stash_info info; + struct strbuf patch = STRBUF_INIT; + struct strbuf stash_msg_buf = STRBUF_INIT; + + if (patch_mode && keep_index == -1) + keep_index = 1; + + if (patch_mode && include_untracked) { + fprintf_ln(stderr, _("Can't use --patch and --include-untracked" + " or --all at the same time")); + ret = -1; + goto done; + } + + read_cache_preload(NULL); + if (!include_untracked && ps.nr) { + int i; + char *ps_matched = xcalloc(ps.nr, 1); + + for (i = 0; i < active_nr; i++) + ce_path_match(&the_index, active_cache[i], &ps, + ps_matched); + + if (report_path_error(ps_matched, &ps, NULL)) { + fprintf_ln(stderr, _("Did you forget to 'git add'?")); + ret = -1; + free(ps_matched); + goto done; + } + free(ps_matched); + } + + if (refresh_cache(REFRESH_QUIET)) { + ret = -1; + goto done; + } + + if (!check_changes(ps, include_untracked)) { + if (!quiet) + printf_ln(_("No local changes to save")); + goto done; + } + + if (!reflog_exists(ref_stash) && do_clear_stash()) { + ret = -1; + fprintf_ln(stderr, _("Cannot initialize stash")); + goto done; + } + + if (stash_msg) + strbuf_addstr(&stash_msg_buf, stash_msg); + if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode, + &info, &patch)) { + ret = -1; + goto done; + } + + if (do_store_stash(&info.w_commit, stash_msg_buf.buf, 1)) { + ret = -1; + fprintf_ln(stderr, _("Cannot save the current status")); + goto done; + } + + printf_ln(_("Saved working directory and index state %s"), + stash_msg_buf.buf); + + if (!patch_mode) { + if (include_untracked && !ps.nr) { + struct child_process cp = CHILD_PROCESS_INIT; + + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "clean", "--force", + "--quiet", "-d", NULL); + if (include_untracked == INCLUDE_ALL_FILES) + argv_array_push(&cp.args, "-x"); + if (run_command(&cp)) { + ret = -1; + goto done; + } + } + if (ps.nr) { + struct child_process cp_add = CHILD_PROCESS_INIT; + struct child_process cp_diff = CHILD_PROCESS_INIT; + struct child_process cp_apply = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + + cp_add.git_cmd = 1; + argv_array_push(&cp_add.args, "add"); + if (!include_untracked) + argv_array_push(&cp_add.args, "-u"); + if (include_untracked == INCLUDE_ALL_FILES) + argv_array_push(&cp_add.args, "--force"); + argv_array_push(&cp_add.args, "--"); + add_pathspecs(&cp_add.args, ps); + if (run_command(&cp_add)) { + ret = -1; + goto done; + } + + cp_diff.git_cmd = 1; + argv_array_pushl(&cp_diff.args, "diff-index", "-p", + "--cached", "--binary", "HEAD", "--", + NULL); + add_pathspecs(&cp_diff.args, ps); + if (pipe_command(&cp_diff, NULL, 0, &out, 0, NULL, 0)) { + ret = -1; + goto done; + } + + cp_apply.git_cmd = 1; + argv_array_pushl(&cp_apply.args, "apply", "--index", + "-R", NULL); + if (pipe_command(&cp_apply, out.buf, out.len, NULL, 0, + NULL, 0)) { + ret = -1; + goto done; + } + } else { + struct child_process cp = CHILD_PROCESS_INIT; + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "reset", "--hard", "-q", + NULL); + if (run_command(&cp)) { + ret = -1; + goto done; + } + } + + if (keep_index == 1 && !is_null_oid(&info.i_tree)) { + struct child_process cp_ls = CHILD_PROCESS_INIT; + struct child_process cp_checkout = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + + if (reset_tree(&info.i_tree, 0, 1)) { + ret = -1; + goto done; + } + + cp_ls.git_cmd = 1; + argv_array_pushl(&cp_ls.args, "ls-files", "-z", + "--modified", "--", NULL); + + add_pathspecs(&cp_ls.args, ps); + if (pipe_command(&cp_ls, NULL, 0, &out, 0, NULL, 0)) { + ret = -1; + goto done; + } + + cp_checkout.git_cmd = 1; + argv_array_pushl(&cp_checkout.args, "checkout-index", + "-z", "--force", "--stdin", NULL); + if (pipe_command(&cp_checkout, out.buf, out.len, NULL, + 0, NULL, 0)) { + ret = -1; + goto done; + } + } + goto done; + } else { + struct child_process cp = CHILD_PROCESS_INIT; + + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "apply", "-R", NULL); + + if (pipe_command(&cp, patch.buf, patch.len, NULL, 0, NULL, 0)) { + fprintf_ln(stderr, _("Cannot remove worktree changes")); + ret = -1; + goto done; + } + + if (keep_index < 1) { + struct child_process cp = CHILD_PROCESS_INIT; + + cp.git_cmd = 1; + argv_array_pushl(&cp.args, "reset", "-q", "--", NULL); + add_pathspecs(&cp.args, ps); + if (run_command(&cp)) { + ret = -1; + goto done; + } + } + goto done; + } + +done: + strbuf_release(&stash_msg_buf); + return ret; +} + +static int push_stash(int argc, const char **argv, const char *prefix) +{ + int keep_index = -1; + int patch_mode = 0; + int include_untracked = 0; + int quiet = 0; + const char *stash_msg = NULL; + struct pathspec ps; + struct option options[] = { + OPT_BOOL('k', "keep-index", &keep_index, + N_("keep index")), + OPT_BOOL('p', "patch", &patch_mode, + N_("stash in patch mode")), + OPT__QUIET(&quiet, N_("quiet mode")), + OPT_BOOL('u', "include-untracked", &include_untracked, + N_("include untracked files in stash")), + OPT_SET_INT('a', "all", &include_untracked, + N_("include ignore files"), 2), + OPT_STRING('m', "message", &stash_msg, N_("message"), + N_("stash message")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_push_usage, + 0); + + parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv); + return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode, + include_untracked); +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -1275,6 +1510,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!store_stash(argc, argv, prefix); else if (!strcmp(argv[0], "create")) return !!create_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "push")) + return !!push_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index ab06e4ffb8..c3146f62ab 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -412,7 +412,8 @@ save) ;; push) shift - push_stash "$@" + cd "$START_DIR" + git stash--helper push "$@" ;; apply) shift @@ -448,7 +449,8 @@ branch) *) case $# in 0) - push_stash && + cd "$START_DIR" + git stash--helper push && say "$(gettext "(To restore them type \"git stash apply\")")" ;; *) From patchwork Thu Nov 22 23:05:38 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: 10694955 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 8E16718F0 for ; Thu, 22 Nov 2018 23:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A8FA2C19A for ; Thu, 22 Nov 2018 23:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F2782C1A6; Thu, 22 Nov 2018 23:06:35 +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 D28FF2C1A2 for ; Thu, 22 Nov 2018 23:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439056AbeKWJsM (ORCPT ); Fri, 23 Nov 2018 04:48:12 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55340 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439027AbeKWJsM (ORCPT ); Fri, 23 Nov 2018 04:48:12 -0500 Received: by mail-wm1-f67.google.com with SMTP id y139so10253017wmc.5 for ; Thu, 22 Nov 2018 15:06:31 -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=2AC++0ou9EX7A29PXkDUmXboZDeZgCwMkAV/qz0V/nw=; b=HiC/AH+nWiMUGkMAwRG2/Y0ajl2emEk8RPwaOjMv4M8ojhhVlpozcq2HnUzWd/AZS2 6AccTymxV9YC4ea7kBQKMj/7SiFW0Zj1YfkKd2CoCyGU88Zl7/4yML7y7V3NiOH5KVUF pYY6F7dskv0QrbDPZeZJrXL8rfs+SY4xlOZ/+dcAFXa6E+KeS++gBi250rIrqhEH32x9 oZAXHb4seN6xceGbu2ugrGkdO/NuL/zu7/CW5VjPTurIN74rfVjKvud5a5f8kSkKIoMr Gom3yx4/nsO+TJVuOVDe2vVNtldirL2crzARz60JVscXpoGudc65+CJpYCbulgPieAcm h/1w== 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=2AC++0ou9EX7A29PXkDUmXboZDeZgCwMkAV/qz0V/nw=; b=gJCUPflT9sPc5Fz/BhNJrVOjxkH9mNKY73hhq1mNB29bOOAavwlLs5Bxpx7ykgzV+N iZ8W0VZq1VEe/AFa3by7QbCnNEPOv10nxIYzqD6FizE480Iv17yC6MTd2WNRwKwSS2Vo LDLuABRFPxcC/wGh7waIDklRtAKKWCSAc3q3pnDl+lpGlXuCClkxVA1Z2KxC/O8wio7j ryyzD+TY4wLYbQ23SySeWRi+z7lyGR9RWR898vsY0u9rSfPbAcN4McQS7in0ScbVTOGK +UJeCO2fY1RTKB6onVy2zKUyD0kTsZWAso4KdbKGd5XBGRxG2X0lQz0gy+l1QnzY64iC dgxA== X-Gm-Message-State: AA+aEWZn0EbStMYTTYUJE/xmiQNc1zU/S2tRyT63MAmmnBl/1Tdp4mA0 aBmPHITbqtVZBisnBjG4Ir27paUP X-Google-Smtp-Source: AJdET5cZk0ydkt2kED6khfri6/g0UxxVkFBzEPs41cknVo2Kl4cO2M/najb2+pTLnMhwaq8UnZlhnw== X-Received: by 2002:a1c:1d85:: with SMTP id d127mr11327224wmd.103.1542927990054; Thu, 22 Nov 2018 15:06:30 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:29 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 18/22] stash: make push -q quiet Date: Fri, 23 Nov 2018 01:05:38 +0200 Message-Id: <78914337d41163aa0ddb8014e9a8a259241f0d7d.1542925164.git.ungureanupaulsebastian@gmail.com> 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 There is a change in behaviour with this commit. When there was no initial commit, the shell version of stash would still display a message. This commit makes `push` to not display any message if `--quiet` or `-q` is specified. Add tests for `--quiet`. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 56 ++++++++++++++++++++++++++--------------- t/t3903-stash.sh | 23 +++++++++++++++++ 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 8683c662fc..0dd5dbade6 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -971,7 +971,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, } static int stash_patch(struct stash_info *info, struct pathspec ps, - struct strbuf *out_patch) + struct strbuf *out_patch, int quiet) { int ret = 0; struct strbuf out = STRBUF_INIT; @@ -1024,7 +1024,8 @@ static int stash_patch(struct stash_info *info, struct pathspec ps, } if (!out_patch->len) { - fprintf_ln(stderr, _("No changes selected")); + if (!quiet) + fprintf_ln(stderr, _("No changes selected")); ret = 1; } @@ -1102,7 +1103,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, int include_untracked, int patch_mode, - struct stash_info *info, struct strbuf *patch) + struct stash_info *info, struct strbuf *patch, + int quiet) { int ret = 0; int flags = 0; @@ -1120,7 +1122,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, refresh_cache(REFRESH_QUIET); if (get_oid("HEAD", &info->b_commit)) { - fprintf_ln(stderr, _("You do not have the initial commit yet")); + if (!quiet) + fprintf_ln(stderr, _("You do not have " + "the initial commit yet")); ret = -1; goto done; } else { @@ -1145,7 +1149,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, if (write_cache_as_tree(&info->i_tree, 0, NULL) || commit_tree(commit_tree_label.buf, commit_tree_label.len, &info->i_tree, parents, &info->i_commit, NULL, NULL)) { - fprintf_ln(stderr, _("Cannot save the current index state")); + if (!quiet) + fprintf_ln(stderr, _("Cannot save the current " + "index state")); ret = -1; goto done; } @@ -1153,26 +1159,29 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, if (include_untracked && get_untracked_files(ps, include_untracked, &untracked_files)) { if (save_untracked_files(info, &msg, untracked_files)) { - fprintf_ln(stderr, _("Cannot save " - "the untracked files")); + if (!quiet) + fprintf_ln(stderr, _("Cannot save " + "the untracked files")); ret = -1; goto done; } untracked_commit_option = 1; } if (patch_mode) { - ret = stash_patch(info, ps, patch); + ret = stash_patch(info, ps, patch, quiet); if (ret < 0) { - fprintf_ln(stderr, _("Cannot save the current " - "worktree state")); + if (!quiet) + fprintf_ln(stderr, _("Cannot save the current " + "worktree state")); goto done; } else if (ret > 0) { goto done; } } else { if (stash_working_tree(info, ps)) { - fprintf_ln(stderr, _("Cannot save the current " - "worktree state")); + if (!quiet) + fprintf_ln(stderr, _("Cannot save the current " + "worktree state")); ret = -1; goto done; } @@ -1198,7 +1207,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, if (commit_tree(stash_msg_buf->buf, stash_msg_buf->len, &info->w_tree, parents, &info->w_commit, NULL, NULL)) { - fprintf_ln(stderr, _("Cannot record working tree state")); + if (!quiet) + fprintf_ln(stderr, _("Cannot record " + "working tree state")); ret = -1; goto done; } @@ -1233,7 +1244,7 @@ static int create_stash(int argc, const char **argv, const char *prefix) memset(&ps, 0, sizeof(ps)); strbuf_addstr(&stash_msg_buf, stash_msg); ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info, - NULL); + NULL, 0); if (!ret) printf_ln("%s", oid_to_hex(&info.w_commit)); @@ -1296,26 +1307,29 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, if (!reflog_exists(ref_stash) && do_clear_stash()) { ret = -1; - fprintf_ln(stderr, _("Cannot initialize stash")); + if (!quiet) + fprintf_ln(stderr, _("Cannot initialize stash")); goto done; } if (stash_msg) strbuf_addstr(&stash_msg_buf, stash_msg); if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode, - &info, &patch)) { + &info, &patch, quiet)) { ret = -1; goto done; } if (do_store_stash(&info.w_commit, stash_msg_buf.buf, 1)) { ret = -1; - fprintf_ln(stderr, _("Cannot save the current status")); + if (!quiet) + fprintf_ln(stderr, _("Cannot save the current status")); goto done; } - printf_ln(_("Saved working directory and index state %s"), - stash_msg_buf.buf); + if (!quiet) + printf_ln(_("Saved working directory and index state %s"), + stash_msg_buf.buf); if (!patch_mode) { if (include_untracked && !ps.nr) { @@ -1416,7 +1430,9 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, argv_array_pushl(&cp.args, "apply", "-R", NULL); if (pipe_command(&cp, patch.buf, patch.len, NULL, 0, NULL, 0)) { - fprintf_ln(stderr, _("Cannot remove worktree changes")); + if (!quiet) + fprintf_ln(stderr, _("Cannot remove " + "worktree changes")); ret = -1; goto done; } diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 8b09a3d6cc..77e0b72035 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1064,6 +1064,29 @@ test_expect_success 'push: not in the repository errors out' ' test_path_is_file untracked ' +test_expect_success 'push: -q is quiet with changes' ' + >foo && + git add foo && + git stash push -q >output 2>&1 && + test_must_be_empty output +' + +test_expect_success 'push: -q is quiet with no changes' ' + git stash push -q >output 2>&1 && + test_must_be_empty output +' + +test_expect_success 'push: -q is quiet even if there is no initial commit' ' + git init foo_dir && + test_when_finished rm -rf foo_dir && + ( + cd foo_dir && + >bar && + test_must_fail git stash push -q >output 2>&1 && + test_must_be_empty output + ) +' + test_expect_success 'untracked files are left in place when -u is not given' ' >file && git add file && From patchwork Thu Nov 22 23:05:39 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: 10694959 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 A9A0D14BD for ; Thu, 22 Nov 2018 23:06:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A3BB2C19A for ; Thu, 22 Nov 2018 23:06:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EA5A2C1BB; Thu, 22 Nov 2018 23:06:37 +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 BF1912C19A for ; Thu, 22 Nov 2018 23:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439062AbeKWJsO (ORCPT ); Fri, 23 Nov 2018 04:48:14 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52506 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439050AbeKWJsM (ORCPT ); Fri, 23 Nov 2018 04:48:12 -0500 Received: by mail-wm1-f65.google.com with SMTP id r11-v6so10280628wmb.2 for ; Thu, 22 Nov 2018 15:06:32 -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=ajQmRTOpnE2dq/Dk3kjvFc4SmP5edDLOhxttqpL4E9w=; b=TuXW4Ctd5lRujivpbUP3C4poFSc0zPwftttkMgkugPVCrE9KguyzdChkbcl+L0h9we mR4ua+4QG78vUOJrNoWlxW3eYaSBiLxW63g4jYruVKHoUgkyonkJ99BaSZCYs3dFVifi NXFUaGhRk7INyYQWaG1CeasT+M1MOIAcqsvo6TTkcvl1qGyxr7/l0smKVDyyIWrTErR1 Wsx52Hvli3CqGi3lHiXA2kA3x2fcoo6hxsaqTj0CpBYa/sYBj/TfyjcJZiGAXbg44jkG U+5UtJbsohj6JhuPEYT24c4vAkpr831dcpgGGeFh4PiNKojwcT3ssGI0R1NU84ZxMulf 2iTg== 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=ajQmRTOpnE2dq/Dk3kjvFc4SmP5edDLOhxttqpL4E9w=; b=PHDr56DATQOSOy6eGcurBCL9rV7S2sjwjc7t3e+kXVDROK4P2gB6VANIG7O8M13H2c kSp0kdrvVyu8JPFNHhrpZnRoaR6fM2YgWMebh6ZrKD3mZ96o9VXwIKvtlSGpcjrcN+M3 t+8M40KAO+zBOoyuk6YdbVqaUh2ByPVxVQ9HDY3iOeHotjh6fkY1t9uSPWsPukOZvv62 dxZqpWI2S9QxvnnRiwdoor6cssXetap9WPVbvplvOSa9iGuKJc7cbqn9R1vTVLZObHet 2xs7kHgObCo4TZwQt4QhAOPRpll5A08/fb0jP+Ib5+qjg5+ETduI5HjkEHPZffToxKaL ej3Q== X-Gm-Message-State: AGRZ1gJJHjFUdzea9eDG1XRZooQCmPCaooU38rbi2CVJElMoXuY+pGyl 7JPtA3+qunCA4BRLb+I4Mb3aMuOw X-Google-Smtp-Source: AJdET5egpogzxiuKDJQVCjkuyiGZLao+19BUF2KWrOD026Gu9/bfRJkFZca1bOnU8pTZsAtdCQMuJA== X-Received: by 2002:a1c:81d3:: with SMTP id c202mr10407640wmd.133.1542927990911; Thu, 22 Nov 2018 15:06:30 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:30 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 19/22] stash: convert save to builtin Date: Fri, 23 Nov 2018 01:05:39 +0200 Message-Id: <4d33f8382f789501d7801ae46bd85e47b9503673.1542925164.git.ungureanupaulsebastian@gmail.com> 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 Add stash save to the helper and delete functions which are no longer needed (`show_help()`, `save_stash()`, `push_stash()`, `create_stash()`, `clear_stash()`, `untracked_files()` and `no_changes()`). Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash--helper.c | 50 +++++++ git-stash.sh | 311 +--------------------------------------- 2 files changed, 52 insertions(+), 309 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 0dd5dbade6..47a0ab6669 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -26,6 +26,8 @@ static const char * const git_stash_helper_usage[] = { N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" " [--] [...]]"), + N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" + " [-u|--include-untracked] [-a|--all] []"), NULL }; @@ -81,6 +83,12 @@ static const char * const git_stash_helper_push_usage[] = { NULL }; +static const char * const git_stash_helper_save_usage[] = { + N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" + " [-u|--include-untracked] [-a|--all] []"), + NULL +}; + static const char *ref_stash = "refs/stash"; static struct strbuf stash_index_path = STRBUF_INIT; @@ -1488,6 +1496,46 @@ static int push_stash(int argc, const char **argv, const char *prefix) include_untracked); } +static int save_stash(int argc, const char **argv, const char *prefix) +{ + int keep_index = -1; + int patch_mode = 0; + int include_untracked = 0; + int quiet = 0; + int ret = 0; + const char *stash_msg = NULL; + struct pathspec ps; + struct strbuf stash_msg_buf = STRBUF_INIT; + struct option options[] = { + OPT_BOOL('k', "keep-index", &keep_index, + N_("keep index")), + OPT_BOOL('p', "patch", &patch_mode, + N_("stash in patch mode")), + OPT__QUIET(&quiet, N_("quiet mode")), + OPT_BOOL('u', "include-untracked", &include_untracked, + N_("include untracked files in stash")), + OPT_SET_INT('a', "all", &include_untracked, + N_("include ignore files"), 2), + OPT_STRING('m', "message", &stash_msg, "message", + N_("stash message")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, + git_stash_helper_save_usage, + PARSE_OPT_KEEP_DASHDASH); + + if (argc) + stash_msg = strbuf_join_argv(&stash_msg_buf, argc, argv, ' '); + + memset(&ps, 0, sizeof(ps)); + ret = do_push_stash(ps, stash_msg, quiet, keep_index, + patch_mode, include_untracked); + + strbuf_release(&stash_msg_buf); + return ret; +} + int cmd_stash__helper(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); @@ -1528,6 +1576,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!create_stash(argc, argv, prefix); else if (!strcmp(argv[0], "push")) return !!push_stash(argc, argv, prefix); + else if (!strcmp(argv[0], "save")) + return !!save_stash(argc, argv, prefix); usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), git_stash_helper_usage, options); diff --git a/git-stash.sh b/git-stash.sh index c3146f62ab..695f1feba3 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -36,314 +36,6 @@ else reset_color= fi -no_changes () { - git diff-index --quiet --cached HEAD --ignore-submodules -- "$@" && - git diff-files --quiet --ignore-submodules -- "$@" && - (test -z "$untracked" || test -z "$(untracked_files "$@")") -} - -untracked_files () { - if test "$1" = "-z" - then - shift - z=-z - else - z= - fi - excl_opt=--exclude-standard - test "$untracked" = "all" && excl_opt= - git ls-files -o $z $excl_opt -- "$@" -} - -clear_stash () { - if test $# != 0 - then - die "$(gettext "git stash clear with parameters is unimplemented")" - fi - if current=$(git rev-parse --verify --quiet $ref_stash) - then - git update-ref -d $ref_stash $current - fi -} - -create_stash () { - stash_msg= - untracked= - while test $# != 0 - do - case "$1" in - -m|--message) - shift - stash_msg=${1?"BUG: create_stash () -m requires an argument"} - ;; - -m*) - stash_msg=${1#-m} - ;; - --message=*) - stash_msg=${1#--message=} - ;; - -u|--include-untracked) - shift - untracked=${1?"BUG: create_stash () -u requires an argument"} - ;; - --) - shift - break - ;; - esac - shift - done - - git update-index -q --refresh - if no_changes "$@" - then - exit 0 - fi - - # state of the base commit - if b_commit=$(git rev-parse --verify HEAD) - then - head=$(git rev-list --oneline -n 1 HEAD --) - else - die "$(gettext "You do not have the initial commit yet")" - fi - - if branch=$(git symbolic-ref -q HEAD) - then - branch=${branch#refs/heads/} - else - branch='(no branch)' - fi - msg=$(printf '%s: %s' "$branch" "$head") - - # state of the index - i_tree=$(git write-tree) && - i_commit=$(printf 'index on %s\n' "$msg" | - git commit-tree $i_tree -p $b_commit) || - die "$(gettext "Cannot save the current index state")" - - if test -n "$untracked" - then - # Untracked files are stored by themselves in a parentless commit, for - # ease of unpacking later. - u_commit=$( - untracked_files -z "$@" | ( - GIT_INDEX_FILE="$TMPindex" && - export GIT_INDEX_FILE && - rm -f "$TMPindex" && - git update-index -z --add --remove --stdin && - u_tree=$(git write-tree) && - printf 'untracked files on %s\n' "$msg" | git commit-tree $u_tree && - rm -f "$TMPindex" - ) ) || die "$(gettext "Cannot save the untracked files")" - - untracked_commit_option="-p $u_commit"; - else - untracked_commit_option= - fi - - if test -z "$patch_mode" - then - - # state of the working tree - w_tree=$( ( - git read-tree --index-output="$TMPindex" -m $i_tree && - GIT_INDEX_FILE="$TMPindex" && - export GIT_INDEX_FILE && - git diff-index --name-only -z HEAD -- "$@" >"$TMP-stagenames" && - git update-index -z --add --remove --stdin <"$TMP-stagenames" && - git write-tree && - rm -f "$TMPindex" - ) ) || - die "$(gettext "Cannot save the current worktree state")" - - else - - rm -f "$TMP-index" && - GIT_INDEX_FILE="$TMP-index" git read-tree HEAD && - - # find out what the user wants - GIT_INDEX_FILE="$TMP-index" \ - git add--interactive --patch=stash -- "$@" && - - # state of the working tree - w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) || - die "$(gettext "Cannot save the current worktree state")" - - git diff-tree -p HEAD $w_tree -- >"$TMP-patch" && - test -s "$TMP-patch" || - die "$(gettext "No changes selected")" - - rm -f "$TMP-index" || - die "$(gettext "Cannot remove temporary index (can't happen)")" - - fi - - # create the stash - if test -z "$stash_msg" - then - stash_msg=$(printf 'WIP on %s' "$msg") - else - stash_msg=$(printf 'On %s: %s' "$branch" "$stash_msg") - fi - w_commit=$(printf '%s\n' "$stash_msg" | - git commit-tree $w_tree -p $b_commit -p $i_commit $untracked_commit_option) || - die "$(gettext "Cannot record working tree state")" -} - -push_stash () { - keep_index= - patch_mode= - untracked= - stash_msg= - while test $# != 0 - do - case "$1" in - -k|--keep-index) - keep_index=t - ;; - --no-keep-index) - keep_index=n - ;; - -p|--patch) - patch_mode=t - # only default to keep if we don't already have an override - test -z "$keep_index" && keep_index=t - ;; - -q|--quiet) - GIT_QUIET=t - ;; - -u|--include-untracked) - untracked=untracked - ;; - -a|--all) - untracked=all - ;; - -m|--message) - shift - test -z ${1+x} && usage - stash_msg=$1 - ;; - -m*) - stash_msg=${1#-m} - ;; - --message=*) - stash_msg=${1#--message=} - ;; - --help) - show_help - ;; - --) - shift - break - ;; - -*) - option="$1" - eval_gettextln "error: unknown option for 'stash push': \$option" - usage - ;; - *) - break - ;; - esac - shift - done - - eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")" - - if test -n "$patch_mode" && test -n "$untracked" - then - die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")" - fi - - test -n "$untracked" || git ls-files --error-unmatch -- "$@" >/dev/null || exit 1 - - git update-index -q --refresh - if no_changes "$@" - then - say "$(gettext "No local changes to save")" - exit 0 - fi - - git reflog exists $ref_stash || - clear_stash || die "$(gettext "Cannot initialize stash")" - - create_stash -m "$stash_msg" -u "$untracked" -- "$@" - git stash--helper store -m "$stash_msg" -q $w_commit || - die "$(gettext "Cannot save the current status")" - say "$(eval_gettext "Saved working directory and index state \$stash_msg")" - - if test -z "$patch_mode" - then - test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION= - if test -n "$untracked" && test $# = 0 - then - git clean --force --quiet -d $CLEAN_X_OPTION - fi - - if test $# != 0 - then - test -z "$untracked" && UPDATE_OPTION="-u" || UPDATE_OPTION= - test "$untracked" = "all" && FORCE_OPTION="--force" || FORCE_OPTION= - git add $UPDATE_OPTION $FORCE_OPTION -- "$@" - git diff-index -p --cached --binary HEAD -- "$@" | - git apply --index -R - else - git reset --hard -q - fi - - if test "$keep_index" = "t" && test -n "$i_tree" - then - git read-tree --reset $i_tree - git ls-files -z --modified -- "$@" | - git checkout-index -z --force --stdin - fi - else - git apply -R < "$TMP-patch" || - die "$(gettext "Cannot remove worktree changes")" - - if test "$keep_index" != "t" - then - git reset -q -- "$@" - fi - fi -} - -save_stash () { - push_options= - while test $# != 0 - do - case "$1" in - --) - shift - break - ;; - -*) - # pass all options through to push_stash - push_options="$push_options $1" - ;; - *) - break - ;; - esac - shift - done - - stash_msg="$*" - - if test -z "$stash_msg" - then - push_stash $push_options - else - push_stash $push_options -m "$stash_msg" - fi -} - -show_help () { - exec git help stash - exit 1 -} - # # Parses the remaining options looking for flags and # at most one revision defaulting to ${ref_stash}@{0} @@ -408,7 +100,8 @@ show) ;; save) shift - save_stash "$@" + cd "$START_DIR" + git stash--helper save "$@" ;; push) shift From patchwork Thu Nov 22 23:05:40 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: 10694961 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 B35E314BD for ; Thu, 22 Nov 2018 23:06:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2D5F2C19A for ; Thu, 22 Nov 2018 23:06:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9739B2C1BB; Thu, 22 Nov 2018 23:06:38 +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 5D4482C1A2 for ; Thu, 22 Nov 2018 23:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439066AbeKWJsP (ORCPT ); Fri, 23 Nov 2018 04:48:15 -0500 Received: from mail-wm1-f54.google.com ([209.85.128.54]:35673 "EHLO mail-wm1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733045AbeKWJsO (ORCPT ); Fri, 23 Nov 2018 04:48:14 -0500 Received: by mail-wm1-f54.google.com with SMTP id c126so10407437wmh.0 for ; Thu, 22 Nov 2018 15:06:33 -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=umncKMPQ85JnLsw+/FDedY3P3Aj5k3DEHF5LC52J7Zg=; b=d/0lRyyjqwpal+S7u0WL0ny15gECQb3y3VLWBdMWfKrAVz+kyNjGhnUJGSFSwTmC0/ S6D/QG8FIFE2ibU9/zDiZi5dk1aTh14rDYl6t2dc4knps3j2QH8eoml87z7n5wsdmTJ+ d2Mk3NFvsEdjsg9sGTjgF8KnrBAroBGcI8T7+5JYOXHHf8uomUtP72kgYXF7uGGeu9xj XJ2FTdj02Ns/qItHYmxRsO13W8TnWqbsHoTfq9jpLlQzxYFNutWgODbKbPFNCuLeapdT ilx7/vkrR/bcNKbzw5GIm23iGtHI5B+3OlXG9XvJau+N+vmVDASVcAOGIUxnXsQcVTY4 3fZg== 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=umncKMPQ85JnLsw+/FDedY3P3Aj5k3DEHF5LC52J7Zg=; b=GlUATq+r6EsQbnhVVxQEnkA45oEnhMSWiwz+PeTmiZGMk7DVSBNMVqXnJh/Qaqt3ML YGdJLYN034GCbMjiOFBIDfZt+uPd9mMiUhq4XzQQmVrUREB5SUozzHzd9d4qRbJobEJY QbILNgC7G4jhqEMxUFkEFBGpdAnOShfZZql6gV+ug5hqPL8GICQrud6BTom4rppWh3U7 JK2oDuOA8fVSn0qfPY02Z4HcjhyURmnfgueU6aI5QXraCHodAV25FAypyTDwob1tD9ti K/OpLIJnlRHQKRcZcv1WHE0F/VLUX7hg/+anp9aME7NOpfS0y/Hfq6T5xjkJq+WLYRRH 3SNw== X-Gm-Message-State: AA+aEWZwXeUXeMVb0XbHThlf1FlV/cYctxqHKowpRuYv+3HJz1E7/V52 /2d1pIzaKd3x/FSs2h6ZDoh1cQYL X-Google-Smtp-Source: AFSGD/UEdDSjqMw7ekAYCn5S8Em+IfTU6paybutra/ONmAjGsrjR3bumAq0WhtxvQnOxVEhQn1uCAQ== X-Received: by 2002:a1c:e1d5:: with SMTP id y204mr11237200wmg.65.1542927991921; Thu, 22 Nov 2018 15:06:31 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:31 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 20/22] stash: convert `stash--helper.c` into `stash.c` Date: Fri, 23 Nov 2018 01:05:40 +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 The old shell script `git-stash.sh` was removed and replaced entirely by `builtin/stash.c`. In order to do that, `create` and `push` were adapted to work without `stash.sh`. For example, before this commit, `git stash create` called `git stash--helper create --message "$*"`. If it called `git stash--helper create "$@"`, then some of these changes wouldn't have been necessary. This commit also removes the word `helper` since now stash is called directly and not by a shell script. Signed-off-by: Paul-Sebastian Ungureanu --- .gitignore | 1 - Makefile | 3 +- builtin.h | 2 +- builtin/{stash--helper.c => stash.c} | 157 +++++++++++++++------------ git-stash.sh | 153 -------------------------- git.c | 2 +- 6 files changed, 92 insertions(+), 226 deletions(-) rename builtin/{stash--helper.c => stash.c} (91%) delete mode 100755 git-stash.sh diff --git a/.gitignore b/.gitignore index 6ecab90ab2..0d77ea5894 100644 --- a/.gitignore +++ b/.gitignore @@ -162,7 +162,6 @@ /git-show-ref /git-stage /git-stash -/git-stash--helper /git-status /git-stripspace /git-submodule diff --git a/Makefile b/Makefile index aa83545e94..450936fcaf 100644 --- a/Makefile +++ b/Makefile @@ -619,7 +619,6 @@ SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-legacy-rebase.sh SCRIPT_SH += git-remote-testgit.sh SCRIPT_SH += git-request-pull.sh -SCRIPT_SH += git-stash.sh SCRIPT_SH += git-submodule.sh SCRIPT_SH += git-web--browse.sh @@ -1115,7 +1114,7 @@ BUILTIN_OBJS += builtin/shortlog.o BUILTIN_OBJS += builtin/show-branch.o BUILTIN_OBJS += builtin/show-index.o BUILTIN_OBJS += builtin/show-ref.o -BUILTIN_OBJS += builtin/stash--helper.o +BUILTIN_OBJS += builtin/stash.o BUILTIN_OBJS += builtin/stripspace.o BUILTIN_OBJS += builtin/submodule--helper.o BUILTIN_OBJS += builtin/symbolic-ref.o diff --git a/builtin.h b/builtin.h index ff4460aff7..b78ab6e30b 100644 --- a/builtin.h +++ b/builtin.h @@ -225,7 +225,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix); extern int cmd_show_branch(int argc, const char **argv, const char *prefix); extern int cmd_show_index(int argc, const char **argv, const char *prefix); extern int cmd_status(int argc, const char **argv, const char *prefix); -extern int cmd_stash__helper(int argc, const char **argv, const char *prefix); +extern int cmd_stash(int argc, const char **argv, const char *prefix); extern int cmd_stripspace(int argc, const char **argv, const char *prefix); extern int cmd_submodule__helper(int argc, const char **argv, const char *prefix); extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); diff --git a/builtin/stash--helper.c b/builtin/stash.c similarity index 91% rename from builtin/stash--helper.c rename to builtin/stash.c index 47a0ab6669..c76a1936d5 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash.c @@ -16,75 +16,70 @@ #define INCLUDE_ALL_FILES 2 -static const char * const git_stash_helper_usage[] = { - N_("git stash--helper list []"), - N_("git stash--helper show [] []"), - N_("git stash--helper drop [-q|--quiet] []"), - N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] []"), - N_("git stash--helper branch []"), - N_("git stash--helper clear"), - N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" +static const char * const git_stash_usage[] = { + N_("git stash list []"), + N_("git stash show [] []"), + N_("git stash drop [-q|--quiet] []"), + N_("git stash ( pop | apply ) [--index] [-q|--quiet] []"), + N_("git stash branch []"), + N_("git stash clear"), + N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" " [--] [...]]"), - N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" + N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] []"), NULL }; -static const char * const git_stash_helper_list_usage[] = { - N_("git stash--helper list []"), +static const char * const git_stash_list_usage[] = { + N_("git stash list []"), NULL }; -static const char * const git_stash_helper_show_usage[] = { - N_("git stash--helper show [] []"), +static const char * const git_stash_show_usage[] = { + N_("git stash show [] []"), NULL }; -static const char * const git_stash_helper_drop_usage[] = { - N_("git stash--helper drop [-q|--quiet] []"), +static const char * const git_stash_drop_usage[] = { + N_("git stash drop [-q|--quiet] []"), NULL }; -static const char * const git_stash_helper_pop_usage[] = { - N_("git stash--helper pop [--index] [-q|--quiet] []"), +static const char * const git_stash_pop_usage[] = { + N_("git stash pop [--index] [-q|--quiet] []"), NULL }; -static const char * const git_stash_helper_apply_usage[] = { - N_("git stash--helper apply [--index] [-q|--quiet] []"), +static const char * const git_stash_apply_usage[] = { + N_("git stash apply [--index] [-q|--quiet] []"), NULL }; -static const char * const git_stash_helper_branch_usage[] = { - N_("git stash--helper branch []"), +static const char * const git_stash_branch_usage[] = { + N_("git stash branch []"), NULL }; -static const char * const git_stash_helper_clear_usage[] = { - N_("git stash--helper clear"), +static const char * const git_stash_clear_usage[] = { + N_("git stash clear"), NULL }; -static const char * const git_stash_helper_store_usage[] = { - N_("git stash--helper store [-m|--message ] [-q|--quiet] "), +static const char * const git_stash_store_usage[] = { + N_("git stash store [-m|--message ] [-q|--quiet] "), NULL }; -static const char * const git_stash_helper_create_usage[] = { - N_("git stash--helper create []"), - NULL -}; - -static const char * const git_stash_helper_push_usage[] = { - N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" +static const char * const git_stash_push_usage[] = { + N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" " [--] [...]]"), NULL }; -static const char * const git_stash_helper_save_usage[] = { - N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" +static const char * const git_stash_save_usage[] = { + N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] []"), NULL }; @@ -221,7 +216,7 @@ static int clear_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_clear_usage, + git_stash_clear_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc) @@ -526,7 +521,7 @@ static int apply_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_apply_usage, 0); + git_stash_apply_usage, 0); if (get_stash_info(&info, argc, argv)) return -1; @@ -599,7 +594,7 @@ static int drop_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_drop_usage, 0); + git_stash_drop_usage, 0); if (get_stash_info(&info, argc, argv)) return -1; @@ -625,7 +620,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_pop_usage, 0); + git_stash_pop_usage, 0); if (get_stash_info(&info, argc, argv)) return -1; @@ -652,7 +647,7 @@ static int branch_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_branch_usage, 0); + git_stash_branch_usage, 0); if (!argc) { fprintf_ln(stderr, _("No branch name specified")); @@ -687,7 +682,7 @@ static int list_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_list_usage, + git_stash_list_usage, PARSE_OPT_KEEP_UNKNOWN); if (!ref_exists(ref_stash)) @@ -767,7 +762,7 @@ static int show_stash(int argc, const char **argv, const char *prefix) argc = setup_revisions(argc, argv, &rev, NULL); if (argc > 1) { free_stash_info(&info); - usage_with_options(git_stash_helper_show_usage, options); + usage_with_options(git_stash_show_usage, options); } rev.diffopt.flags.recursive = 1; @@ -813,7 +808,7 @@ static int store_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_store_usage, + git_stash_store_usage, PARSE_OPT_KEEP_UNKNOWN); if (argc != 1) { @@ -1231,28 +1226,16 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, static int create_stash(int argc, const char **argv, const char *prefix) { - int include_untracked = 0; int ret = 0; - const char *stash_msg = NULL; struct strbuf stash_msg_buf = STRBUF_INIT; struct stash_info info; struct pathspec ps; - struct option options[] = { - OPT_BOOL('u', "include-untracked", &include_untracked, - N_("include untracked files in stash")), - OPT_STRING('m', "message", &stash_msg, N_("message"), - N_("stash message")), - OPT_END() - }; - argc = parse_options(argc, argv, prefix, options, - git_stash_helper_create_usage, - 0); + /* Starting with argv[1], since argv[0] is "create" */ + strbuf_join_argv(&stash_msg_buf, argc - 1, ++argv, ' '); memset(&ps, 0, sizeof(ps)); - strbuf_addstr(&stash_msg_buf, stash_msg); - ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info, - NULL, 0); + ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0); if (!ret) printf_ln("%s", oid_to_hex(&info.w_commit)); @@ -1487,9 +1470,10 @@ static int push_stash(int argc, const char **argv, const char *prefix) OPT_END() }; - argc = parse_options(argc, argv, prefix, options, - git_stash_helper_push_usage, - 0); + if (argc) + argc = parse_options(argc, argv, prefix, options, + git_stash_push_usage, + 0); parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv); return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode, @@ -1522,7 +1506,7 @@ static int save_stash(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, - git_stash_helper_save_usage, + git_stash_save_usage, PARSE_OPT_KEEP_DASHDASH); if (argc) @@ -1536,10 +1520,12 @@ static int save_stash(int argc, const char **argv, const char *prefix) return ret; } -int cmd_stash__helper(int argc, const char **argv, const char *prefix) +int cmd_stash(int argc, const char **argv, const char *prefix) { + int i = -1; pid_t pid = getpid(); const char *index_file; + struct argv_array args = ARGV_ARRAY_INIT; struct option options[] = { OPT_END() @@ -1547,16 +1533,16 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) git_config(git_diff_basic_config, NULL); - argc = parse_options(argc, argv, prefix, options, git_stash_helper_usage, + argc = parse_options(argc, argv, prefix, options, git_stash_usage, PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); index_file = get_index_file(); strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file, (uintmax_t)pid); - if (argc < 1) - usage_with_options(git_stash_helper_usage, options); - if (!strcmp(argv[0], "apply")) + if (!argc) + return !!push_stash(0, NULL, prefix); + else if (!strcmp(argv[0], "apply")) return !!apply_stash(argc, argv, prefix); else if (!strcmp(argv[0], "clear")) return !!clear_stash(argc, argv, prefix); @@ -1578,7 +1564,42 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix) return !!push_stash(argc, argv, prefix); else if (!strcmp(argv[0], "save")) return !!save_stash(argc, argv, prefix); + else if (*argv[0] != '-') + usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), + git_stash_usage, options); + + if (strcmp(argv[0], "-p")) { + while (++i < argc && strcmp(argv[i], "--")) { + /* + * `akpqu` is a string which contains all short options, + * except `-m` which is verified separately. + */ + if ((strlen(argv[i]) == 2) && *argv[i] == '-' && + strchr("akpqu", argv[i][1])) + continue; + + if (!strcmp(argv[i], "--all") || + !strcmp(argv[i], "--keep-index") || + !strcmp(argv[i], "--no-keep-index") || + !strcmp(argv[i], "--patch") || + !strcmp(argv[i], "--quiet") || + !strcmp(argv[i], "--include-untracked")) + continue; + + /* + * `-m` and `--message=` are verified separately because + * they need to be immediately followed by a string + * (i.e.`-m"foobar"` or `--message="foobar"`). + */ + if (starts_with(argv[i], "-m") || + starts_with(argv[i], "--message=")) + continue; + + usage_with_options(git_stash_usage, options); + } + } - usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), - git_stash_helper_usage, options); + argv_array_push(&args, "push"); + argv_array_pushv(&args, argv); + return !!push_stash(args.argc, args.argv, prefix); } diff --git a/git-stash.sh b/git-stash.sh deleted file mode 100755 index 695f1feba3..0000000000 --- a/git-stash.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/sh -# Copyright (c) 2007, Nanako Shiraishi - -dashless=$(basename "$0" | sed -e 's/-/ /') -USAGE="list [] - or: $dashless show [] - or: $dashless drop [-q|--quiet] [] - or: $dashless ( pop | apply ) [--index] [-q|--quiet] [] - or: $dashless branch [] - or: $dashless save [--patch] [-k|--[no-]keep-index] [-q|--quiet] - [-u|--include-untracked] [-a|--all] [] - or: $dashless [push [--patch] [-k|--[no-]keep-index] [-q|--quiet] - [-u|--include-untracked] [-a|--all] [-m ] - [-- ...]] - or: $dashless clear" - -SUBDIRECTORY_OK=Yes -OPTIONS_SPEC= -START_DIR=$(pwd) -. git-sh-setup -require_work_tree -prefix=$(git rev-parse --show-prefix) || exit 1 -cd_to_toplevel - -TMP="$GIT_DIR/.git-stash.$$" -TMPindex=${GIT_INDEX_FILE-"$(git rev-parse --git-path index)"}.stash.$$ -trap 'rm -f "$TMP-"* "$TMPindex"' 0 - -ref_stash=refs/stash - -if git config --get-colorbool color.interactive; then - help_color="$(git config --get-color color.interactive.help 'red bold')" - reset_color="$(git config --get-color '' reset)" -else - help_color= - reset_color= -fi - -# -# Parses the remaining options looking for flags and -# at most one revision defaulting to ${ref_stash}@{0} -# if none found. -# -# Derives related tree and commit objects from the -# revision, if one is found. -# -# stash records the work tree, and is a merge between the -# base commit (first parent) and the index tree (second parent). -# -# REV is set to the symbolic version of the specified stash-like commit -# IS_STASH_LIKE is non-blank if ${REV} looks like a stash -# IS_STASH_REF is non-blank if the ${REV} looks like a stash ref -# s is set to the SHA1 of the stash commit -# w_commit is set to the commit containing the working tree -# b_commit is set to the base commit -# i_commit is set to the commit containing the index tree -# u_commit is set to the commit containing the untracked files tree -# w_tree is set to the working tree -# b_tree is set to the base tree -# i_tree is set to the index tree -# u_tree is set to the untracked files tree -# -# GIT_QUIET is set to t if -q is specified -# INDEX_OPTION is set to --index if --index is specified. -# FLAGS is set to the remaining flags (if allowed) -# -# dies if: -# * too many revisions specified -# * no revision is specified and there is no stash stack -# * a revision is specified which cannot be resolve to a SHA1 -# * a non-existent stash reference is specified -# * unknown flags were set and ALLOW_UNKNOWN_FLAGS is not "t" -# - -test "$1" = "-p" && set "push" "$@" - -PARSE_CACHE='--not-parsed' -# The default command is "push" if nothing but options are given -seen_non_option= -for opt -do - case "$opt" in - --) break ;; - -*) ;; - *) seen_non_option=t; break ;; - esac -done - -test -n "$seen_non_option" || set "push" "$@" - -# Main command set -case "$1" in -list) - shift - git stash--helper list "$@" - ;; -show) - shift - git stash--helper show "$@" - ;; -save) - shift - cd "$START_DIR" - git stash--helper save "$@" - ;; -push) - shift - cd "$START_DIR" - git stash--helper push "$@" - ;; -apply) - shift - cd "$START_DIR" - git stash--helper apply "$@" - ;; -clear) - shift - git stash--helper clear "$@" - ;; -create) - shift - git stash--helper create --message "$*" - ;; -store) - shift - git stash--helper store "$@" - ;; -drop) - shift - git stash--helper drop "$@" - ;; -pop) - shift - cd "$START_DIR" - git stash--helper pop "$@" - ;; -branch) - shift - cd "$START_DIR" - git stash--helper branch "$@" - ;; -*) - case $# in - 0) - cd "$START_DIR" - git stash--helper push && - say "$(gettext "(To restore them type \"git stash apply\")")" - ;; - *) - usage - esac - ;; -esac diff --git a/git.c b/git.c index 76ee02802e..49ab91b4ec 100644 --- a/git.c +++ b/git.c @@ -554,7 +554,7 @@ static struct cmd_struct commands[] = { { "show-index", cmd_show_index }, { "show-ref", cmd_show_ref, RUN_SETUP }, { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, - { "stash--helper", cmd_stash__helper, RUN_SETUP | NEED_WORK_TREE }, + { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, From patchwork Thu Nov 22 23:05:41 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: 10694963 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 238111734 for ; Thu, 22 Nov 2018 23:06:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144062C19A for ; Thu, 22 Nov 2018 23:06:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08DD52C1BB; Thu, 22 Nov 2018 23:06:39 +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 7AA882C1A6 for ; Thu, 22 Nov 2018 23:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439064AbeKWJsO (ORCPT ); Fri, 23 Nov 2018 04:48:14 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:32872 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439027AbeKWJsO (ORCPT ); Fri, 23 Nov 2018 04:48:14 -0500 Received: by mail-wm1-f67.google.com with SMTP id 79so10466558wmo.0 for ; Thu, 22 Nov 2018 15:06:33 -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=GKHAkcCph+l6RnTe6mxTpRHnu/mOqNh+0NCmev7+L/Y=; b=lmu4bIZ5ZNlH26Ehrx9x6/S08rgJMNUBJIq7lTwfLLWmO4yGSvxK3uTe9pVqO25eVx PsI3irh1z3VAnhDtChySK2xXIJ5G5jEiG5xzGYv9UzfuTRToTtOKQiaaBpNBE6EI+7Rs dR2dXL/kAna/V9KIycLBG8lHcCFLpqskiTVAX3/C+INSHbOb5AGDuQJ2Tqk9ggSZ/Teq tIBNLFCsdQSQnlQiKHdM5ZTHz3KW2DDyaMQU6cT5ogT6M4C+1DJWo7DSyiFP5bQ8/XGs baZDTTajza9EPkC5PNMyGQEtMDiMMQHMIojDqNkDZuWumjwR2VuOBcvhISUrJf+s+2lz x6aA== 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=GKHAkcCph+l6RnTe6mxTpRHnu/mOqNh+0NCmev7+L/Y=; b=oHCpk6VBSL4r06qN/Go1gHC7EGmVadkW5q2CI9pTa2tLgvIvcX82Fc/k1rfYRjSXPp e2E+xiOzxOgPzKkLVFdYYV5tdRKGWVVscrnyL2uO1MRFzt1nfLCoT08ND1IDoZUKXVEz yf8kqGJpb+nUfLZgHpf/Vx6A4nRSZoJ7UygMCnGc9gKc6d0HNke+ezd8+1y9AdOw0Ii5 X0eZRpz8Xw415J0n/VUi5IppW3w2jgLbNVFley7ThYHcAoYEIOzmEMEa3G5Knce7ZtX9 0q/rShwEKqG/hqN/h1q+T2txhLa1jq7yl0B0FKUZs2+J436p4w92ltPlR86yfHUaGj8D uI1w== X-Gm-Message-State: AA+aEWaMcUo58CQ1mbVNpxqVN/EfCQMMSGqrOw2JkN0xAuLDZ0CJAjtu 7GGRllU/RcRAB86AWFewcIY3kLIY X-Google-Smtp-Source: AFSGD/Wi4nSSjeN9/yn+VSNM+BxIBoo8mt3WebXKH3knbY/j1yjOtUNVpP2Jyw/6gIawXjDn78LvZg== X-Received: by 2002:a1c:150d:: with SMTP id 13mr3725528wmv.104.1542927992838; Thu, 22 Nov 2018 15:06:32 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:32 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 21/22] stash: optimize `get_untracked_files()` and `check_changes()` Date: Fri, 23 Nov 2018 01:05:41 +0200 Message-Id: <7ca8408f1e8c192324ac276ec42559c3343e9eee.1542925164.git.ungureanupaulsebastian@gmail.com> 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 This commits introduces a optimization by avoiding calling the same functions again. For example, `git stash push -u` would call at some points the following functions: * `check_changes()` (inside `do_push_stash()`) * `do_create_stash()`, which calls: `check_changes()` and `get_untracked_files()` Note that `check_changes()` also calls `get_untracked_files()`. So, `check_changes()` is called 2 times and `get_untracked_files()` 3 times. The old function `check_changes()` now consists of two functions: `get_untracked_files()` and `check_changes_tracked_files()`. These are the call chains for `push` and `create`: * `push_stash()` -> `do_push_stash()` -> `do_create_stash()` * `create_stash()` -> `do_create_stash()` To prevent calling the same functions over and over again, `check_changes()` inside `do_create_stash()` is now placed in the caller functions (`create_stash()` and `do_push_stash()`). This way `check_changes()` and `get_untracked files()` are called only one time. https://public-inbox.org/git/20180818223329.GJ11326@hank.intra.tgummerer.com/ Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash.c | 50 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index c76a1936d5..5ad0f443ca 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -879,18 +879,18 @@ static int get_untracked_files(struct pathspec ps, int include_untracked, } /* - * The return value of `check_changes()` can be: + * The return value of `check_changes_tracked_files()` can be: * * < 0 if there was an error * = 0 if there are no changes. * > 0 if there are changes. */ -static int check_changes(struct pathspec ps, int include_untracked) + +static int check_changes_tracked_files(struct pathspec ps) { int result; struct rev_info rev; struct object_id dummy; - struct strbuf out = STRBUF_INIT; /* No initial commit. */ if (get_oid("HEAD", &dummy)) @@ -918,14 +918,26 @@ static int check_changes(struct pathspec ps, int include_untracked) if (diff_result_code(&rev.diffopt, result)) return 1; + return 0; +} + +/* + * The function will fill `untracked_files` with the names of untracked files + * It will return 1 if there were any changes and 0 if there were not. + */ + +static int check_changes(struct pathspec ps, int include_untracked, + struct strbuf *untracked_files) +{ + int ret = 0; + if (check_changes_tracked_files(ps)) + ret = 1; + if (include_untracked && get_untracked_files(ps, include_untracked, - &out)) { - strbuf_release(&out); - return 1; - } + untracked_files)) + ret = 1; - strbuf_release(&out); - return 0; + return ret; } static int save_untracked_files(struct stash_info *info, struct strbuf *msg, @@ -1134,7 +1146,7 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, head_commit = lookup_commit(the_repository, &info->b_commit); } - if (!check_changes(ps, include_untracked)) { + if (!check_changes(ps, include_untracked, &untracked_files)) { ret = 1; goto done; } @@ -1159,8 +1171,7 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf, goto done; } - if (include_untracked && get_untracked_files(ps, include_untracked, - &untracked_files)) { + if (include_untracked) { if (save_untracked_files(info, &msg, untracked_files)) { if (!quiet) fprintf_ln(stderr, _("Cannot save " @@ -1235,18 +1246,14 @@ static int create_stash(int argc, const char **argv, const char *prefix) strbuf_join_argv(&stash_msg_buf, argc - 1, ++argv, ' '); memset(&ps, 0, sizeof(ps)); - ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0); + if (!check_changes_tracked_files(ps)) + return 0; - if (!ret) + if (!(ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0))) printf_ln("%s", oid_to_hex(&info.w_commit)); strbuf_release(&stash_msg_buf); - - /* - * ret can be 1 if there were no changes. In this case, we should - * not error out. - */ - return ret < 0; + return ret; } static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, @@ -1256,6 +1263,7 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, struct stash_info info; struct strbuf patch = STRBUF_INIT; struct strbuf stash_msg_buf = STRBUF_INIT; + struct strbuf untracked_files = STRBUF_INIT; if (patch_mode && keep_index == -1) keep_index = 1; @@ -1290,7 +1298,7 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet, goto done; } - if (!check_changes(ps, include_untracked)) { + if (!check_changes(ps, include_untracked, &untracked_files)) { if (!quiet) printf_ln(_("No local changes to save")); goto done; From patchwork Thu Nov 22 23:05:42 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: 10694965 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 9389514BD for ; Thu, 22 Nov 2018 23:06:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E072C19A for ; Thu, 22 Nov 2018 23:06:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7604F2C1A6; Thu, 22 Nov 2018 23:06:39 +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 F26CF2C1A2 for ; Thu, 22 Nov 2018 23:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439069AbeKWJsQ (ORCPT ); Fri, 23 Nov 2018 04:48:16 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36270 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439043AbeKWJsP (ORCPT ); Fri, 23 Nov 2018 04:48:15 -0500 Received: by mail-wr1-f68.google.com with SMTP id t3so10647839wrr.3 for ; Thu, 22 Nov 2018 15:06:34 -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=RRM/kF8CkCawV5nN7RH6PjozXtvDmWt+KGBM55K3ci0=; b=GJ/Ztn/rkh2hyoh1qSHSOpY5JCD1Kk689IHItC6bX2SfZaQ41I74Hz4h6piA3EoaI1 +OSLAW8U5uzRPX1QEIf5PW0JhBv1ALobi+mq+r0HqUxVotqOux6UxHkK4AGMpHdQCsU8 4qcMF7EakLO7HUCFVkfKXXHiYBbS4AyT46SMMUBKXRrnavxPsttX1+EHVSU/4QWKgqH1 F3FhxyGDnXuiPSnS3JSZMfmoGcYcQ/40tfesXzBwYiGX0hLQpkeKlOVRkPM45D1cY0Py eogX7PgcKGJ2RHz2iuElnI3zOYImytK1GzhRU/SZu6eJQkcnwsrS3RnntUrfCZn1xcjA a2gQ== 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=RRM/kF8CkCawV5nN7RH6PjozXtvDmWt+KGBM55K3ci0=; b=AcaKTUoRCJ4DbpUDZ9vNJCBI5eSDbYr5ehgsiTpSla/CjtvHL2Jvylbi8ddBoIqOGW cZb7JmFaO3UqItCIgYA46lBm9RsJxVuZoT7ocRUGlZRfrBBmrkHnp31EbjXH4bBNwrj0 wUdApbBRAgP7jx7Ydd1Y1JdRU4hAXsz8tMxow0DcR4G0nD8KVcnmzjo4FFnlTFU6LBDg +00PMJxS7Igrld3sHAavkK44h7evP4jXjyiOATqFy93qoKdE9sVHPwyNXGTyaQgxo/83 1OMt1997c+odBxfP/smtS0OTUj1764fxM1ZGh8Z4PAcQXbMZPwGZjh7qvZB0+pWcpZcW ieUg== X-Gm-Message-State: AA+aEWYDBeoV/Sy50+T4B+F4rdPqV80400pof5jihQnHchb41pl2FD+J 0J91Y3hJitcmmpfQu+f676n52MGz X-Google-Smtp-Source: AFSGD/Vx4Cu6S46O7WPVEzhQGJzdA4DOx/32lhYqgPl9515a4kWHJMh4PxAlQ4re3wrjL1EehbuX7A== X-Received: by 2002:adf:b253:: with SMTP id y19mr10395689wra.184.1542927993889; Thu, 22 Nov 2018 15:06:33 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:33 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 22/22] stash: replace all `write-tree` child processes with API calls Date: Fri, 23 Nov 2018 01:05:42 +0200 Message-Id: <0482332a22d527333b1b62a2ed293e6d92acd64e.1542925164.git.ungureanupaulsebastian@gmail.com> 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 This commit replaces spawning `git write-tree` with API calls. Signed-off-by: Paul-Sebastian Ungureanu --- builtin/stash.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index 5ad0f443ca..029e209176 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -945,9 +945,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, { int ret = 0; struct strbuf untracked_msg = STRBUF_INIT; - struct strbuf out = STRBUF_INIT; struct child_process cp_upd_index = CHILD_PROCESS_INIT; - struct child_process cp_write_tree = CHILD_PROCESS_INIT; + struct index_state istate = { NULL }; cp_upd_index.git_cmd = 1; argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", @@ -962,15 +961,11 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, goto done; } - cp_write_tree.git_cmd = 1; - argv_array_push(&cp_write_tree.args, "write-tree"); - argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); - if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + if (write_index_as_tree(&info->u_tree, &istate, stash_index_path.buf, 0, + NULL)) { ret = -1; goto done; } - get_oid_hex(out.buf, &info->u_tree); if (commit_tree(untracked_msg.buf, untracked_msg.len, &info->u_tree, NULL, &info->u_commit, NULL, NULL)) { @@ -979,8 +974,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, } done: + discard_index(&istate); strbuf_release(&untracked_msg); - strbuf_release(&out); remove_path(stash_index_path.buf); return ret; } @@ -989,11 +984,10 @@ static int stash_patch(struct stash_info *info, struct pathspec ps, struct strbuf *out_patch, int quiet) { int ret = 0; - struct strbuf out = STRBUF_INIT; struct child_process cp_read_tree = CHILD_PROCESS_INIT; struct child_process cp_add_i = CHILD_PROCESS_INIT; - struct child_process cp_write_tree = CHILD_PROCESS_INIT; struct child_process cp_diff_tree = CHILD_PROCESS_INIT; + struct index_state istate = { NULL }; remove_path(stash_index_path.buf); @@ -1019,17 +1013,12 @@ static int stash_patch(struct stash_info *info, struct pathspec ps, } /* State of the working tree. */ - cp_write_tree.git_cmd = 1; - argv_array_push(&cp_write_tree.args, "write-tree"); - argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); - if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0, + NULL)) { ret = -1; goto done; } - get_oid_hex(out.buf, &info->w_tree); - cp_diff_tree.git_cmd = 1; argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "HEAD", oid_to_hex(&info->w_tree), "--", NULL); @@ -1045,7 +1034,7 @@ static int stash_patch(struct stash_info *info, struct pathspec ps, } done: - strbuf_release(&out); + discard_index(&istate); remove_path(stash_index_path.buf); return ret; } @@ -1055,9 +1044,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) int ret = 0; struct rev_info rev; struct child_process cp_upd_index = CHILD_PROCESS_INIT; - struct child_process cp_write_tree = CHILD_PROCESS_INIT; - struct strbuf out = STRBUF_INIT; struct strbuf diff_output = STRBUF_INIT; + struct index_state istate = { NULL }; set_alternate_index_output(stash_index_path.buf); if (reset_tree(&info->i_tree, 0, 0)) { @@ -1096,20 +1084,15 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) goto done; } - cp_write_tree.git_cmd = 1; - argv_array_push(&cp_write_tree.args, "write-tree"); - argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); - if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) { + if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0, + NULL)) { ret = -1; goto done; } - get_oid_hex(out.buf, &info->w_tree); - done: + discard_index(&istate); UNLEAK(rev); - strbuf_release(&out); object_array_clear(&rev.pending); strbuf_release(&diff_output); remove_path(stash_index_path.buf);