From patchwork Thu Dec 20 19:44:17 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: 10739461 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 A047B6C2 for ; Thu, 20 Dec 2018 19:44:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F15E28918 for ; Thu, 20 Dec 2018 19:44:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 823F228999; Thu, 20 Dec 2018 19:44:53 +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 211A528918 for ; Thu, 20 Dec 2018 19:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731340AbeLTTov (ORCPT ); Thu, 20 Dec 2018 14:44:51 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36201 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729246AbeLTTov (ORCPT ); Thu, 20 Dec 2018 14:44:51 -0500 Received: by mail-wm1-f68.google.com with SMTP id p6so3506981wmc.1 for ; Thu, 20 Dec 2018 11:44:50 -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=jaSb88dotPeBZdS7GCYPpQb9XgbCmyqG/iQIZacjNcc=; b=SNnaoyVWYtHQpBNz+CYTv60yKChOI9NN6/ZG60l2PfCeAhwS2cul1OEzYsRjs2UgDy Txgostak2RFgAYp70vBXlfczt8MYsiEg8Kfh3Q5VRhiOL5hfH69OiHvXhNqj259gmzYB OaCp63rtt+ikj9vTScEYdawnHOZ++D7ZyLOFlFGPWCWCFIdM6vW/BLPlBSmYscdGGBOy tVzH3njReIMgDMDNgW5pwqDR0jZ6D+/Ugy8FGT16Ytbjt/moXFs/hl1ZZ2nsrynlu8RB DNybQSD8D3YmsUNnbc0P8CkYi+PhGFvZFSbk/RYpqnGsoUVMQDkhV7d5KtAxDVRt769N iemg== 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=jaSb88dotPeBZdS7GCYPpQb9XgbCmyqG/iQIZacjNcc=; b=Ft2m9EFBStYuzFlSZXDInWlFtq95QB/bDoKMXRKVd5D3Q6XgbBxpI6u9tuaozMbeNP SXTAyvUhDTADDbIxbQuquDiXl5HCgbmJJ8SfnOlGcN3YN0QXKxaYAc15X5pNpiYHjYlZ WD1AiZ95LB9uFo3GR0qUiA5O2EQmRLalPIls9zBb2p5Wzd0vuHolWc2u84UbRVlAOgqp aAAYq0GCcnrexBZGUtUcrwikxtZhZJpEedal3Ge2WSp1Ff8yooXxaO3fsw7vWmral93C WS7AVrBIEA2vmsn6wjk2jn469FMhMF0VPsiWu0tXvzWwtiyXlyxV2XZ8GaA/SlRLb7bK EYPA== X-Gm-Message-State: AJcUukevxZVLTJ12f39LwWmWwwTw4QJKDBsE/KbPCEunwcckEQNvAIsb vbOsJeXYAzCN+w3EAJ03obvcUVA97CU= X-Google-Smtp-Source: AFSGD/UWComrxlLCc8f3bMPQKkLEuDyTFwQEpAM/v6zxFN4bID4kmDbLuQ2+Nij1PCOG+FcDP0/Skw== X-Received: by 2002:a7b:c218:: with SMTP id x24mr18714wmi.58.1545335089465; Thu, 20 Dec 2018 11:44:49 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:48 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 01/26] sha1-name.c: add `get_oidf()` which acts like `get_oid()` Date: Thu, 20 Dec 2018 21:44:17 +0200 Message-Id: <6b3308038a727e27930f95b208dd3f2c94085375.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 b7acd81d2e..28ccc97e10 100644 --- a/cache.h +++ b/cache.h @@ -1335,6 +1335,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 b24502811b..9524a09525 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1516,6 +1516,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 Dec 20 19:44:18 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: 10739463 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 5EB0C6C5 for ; Thu, 20 Dec 2018 19:44:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FEAF28918 for ; Thu, 20 Dec 2018 19:44:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 440DF28999; Thu, 20 Dec 2018 19:44:54 +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 0509128918 for ; Thu, 20 Dec 2018 19:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731447AbeLTTox (ORCPT ); Thu, 20 Dec 2018 14:44:53 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45027 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728588AbeLTTow (ORCPT ); Thu, 20 Dec 2018 14:44:52 -0500 Received: by mail-wr1-f68.google.com with SMTP id z5so2964577wrt.11 for ; Thu, 20 Dec 2018 11:44:51 -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=rJOEHrCAzdc21FbUEM3Mgh2sdULnOBQfB42x8DaPRsc=; b=rHn92dl4VJpxsvuotqEL+trda97wyw0rmef/xjgXdkUQGgyiUfNKR7SrCfxNf7z1GN mRdP0kbto3HZPMNRQpKMMg5HAExEgY16RVFM9Gqa48F6PtYUQgCAEKjvJZmClcmfdJoD 6qHMlszvKV5bSwdBbgmsbdPBOSQ/PiDmjKYvT4RCgvpPzT4EmkQh0NKpsekme2KmE1/C BwT8Ys9HYA0qS09xo+J7AdoYqru2a3t8xiMkDz9HEKPEwTP0IVx0k9ZOEzHi9eIIdXEP Q5D/eEEHlKgMOaxJ2cCGVIULwXIaZo5wgdsdiOv9pXbRiAxRyqNFNyo2wsrcfvq2+Bo1 /xeA== 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=rJOEHrCAzdc21FbUEM3Mgh2sdULnOBQfB42x8DaPRsc=; b=V+Z6pbz1PuqStYUe6UbOe1leVYyjgkY1NqVFH0PupIQDecmPNvqSmaUrX/A+VollNe bOfTI4yWJHvz8JwqmHUxjnBGVwfLLv9lmNK6V8cFL4jLAMGwe8gmgg2iwlrnFEjNW1VQ G1ryem42Osopt1Hs+6ioZfIt3FubRvavVONoWJaU6LkNgIt8OZQzgEtMOl3hFTH9irfQ iKhUFSCSn+ke+sj8Zh5tfwfCQEMAy0UdMDe4wkkPE+FLfxcex8o9r24LInUjZFMdOZNn FGD6kljQu+LofCa9ywiyx+T44If6Rj+7S+Ae0V8oCvsqxnBtJD+fK7svl/+B3krSYOnt 5W8g== X-Gm-Message-State: AA+aEWZk2LcSpHgrf3Xq3UmkJlTl+wZLoqTaBhFth2FDym17HOD/cLLo fuMqdqZO2I0GATq0MebjE2aWfEuxaSI= X-Google-Smtp-Source: AFSGD/UV8HGlVHG2DQIwLZa3BrV+zsVRt9Sx8EIlhewLM+iH+pY17k4IHtLuJ+SjiLKk7XU7Qi6dmQ== X-Received: by 2002:a5d:40c1:: with SMTP id b1mr25204091wrq.133.1545335090360; Thu, 20 Dec 2018 11:44:50 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:49 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 02/26] strbuf.c: add `strbuf_join_argv()` Date: Thu, 20 Dec 2018 21:44:18 +0200 Message-Id: <554f15de006f6015390a8e1c6098c8bf2d06c849.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 Dec 20 19:44:19 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: 10739467 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 CC23D6C2 for ; Thu, 20 Dec 2018 19:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B526F288F7 for ; Thu, 20 Dec 2018 19:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E6328949; Thu, 20 Dec 2018 19:44:56 +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 7CABB288F7 for ; Thu, 20 Dec 2018 19:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731601AbeLTToy (ORCPT ); Thu, 20 Dec 2018 14:44:54 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40313 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729246AbeLTTox (ORCPT ); Thu, 20 Dec 2018 14:44:53 -0500 Received: by mail-wm1-f66.google.com with SMTP id f188so3492537wmf.5 for ; Thu, 20 Dec 2018 11:44:52 -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=VMuhPYf1g6Cle4TQSNd2MuM/4W+IRDNRjvR8fSkVbk0=; b=X+Tijb0zg0mctENAFJo6yJqrVOvz81ZyiReDQRX62mvhALLTJsefAK19AfTLcV98S4 TQL4U4VSxYKDfE3eqS3iZgmwgVZRshdJzj+G6HtqsS9ASBSHUjPPenRaXQNgja88nuav b3egscCYrxLd6Ac5lZGvGswHWVZzjbvQe+faKT93Tgnt9URbjMEg6fJsRVPO+ILmp7K3 quvIxpiK31JZASTc2hHIN1SQG6T6zcMevgFznfuBl0cOen2EUoFWMqxg+ctpdDtfxVfj 4l0EkH8yVHej3FoB8geeqQO/9bCcxC4+yegc392DxGpfotC4ukXpYgxvuwJI8L9Fh/vu srOA== 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=VMuhPYf1g6Cle4TQSNd2MuM/4W+IRDNRjvR8fSkVbk0=; b=YwEdSp1N9xSvqaZB3LW2CLaiwP/KsQ/KefFABQ4M6CR8zjbVbE5fYxkJgdRH7TE5b5 kxG+1Q4xwL300kzNTrO0dtUsGA6nSQxXeby0Zmdn/EaJ2LmRghGuCEj7ZxstrFtF/Rn6 ++JMeIrVXwq7d3WVizC9u9NYLAT0fJe7+LGrQNo5YO+aJ4itv4GR5Zx5hj8qnM4xEv5G OUlRLBePF+KinPZXRZsk3wS4E6SzFm0ng1cnEPbHZg2MROYfamiqy6dozv4W3v9OqPCG uGVkeYkxKDgbpmG2I9Zhk7uSYfGtFL/B4bJv4rnXnFSqb6S8z8SFhvseK+8tpejzXayH wvbA== X-Gm-Message-State: AA+aEWYBOzTr9ULQWn07cRO+Xfnd6GTka6LO0wRbJnEwOFzXv3um+47G 7h1QWRYUwC+egz91pmGEnLcjjPxG/Fw= X-Google-Smtp-Source: AFSGD/Xag+7h1MJwI7UCeLmf1YdFbfBxraLfWMNtmVr0toTM+09IAZp0GnizpfHNZs0DzOOfBorbVw== X-Received: by 2002:a1c:544f:: with SMTP id p15mr12672819wmi.37.1545335091303; Thu, 20 Dec 2018 11:44:51 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:50 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 03/26] strbuf.c: add `strbuf_insertf()` and `strbuf_vinsertf()` Date: Thu, 20 Dec 2018 21:44:19 +0200 Message-Id: <2260063a5c93f0cffe68e67f24d191a606ffaab4.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 Dec 20 19:44:20 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: 10739471 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 3F6A36C5 for ; Thu, 20 Dec 2018 19:44:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 301AB288F7 for ; Thu, 20 Dec 2018 19:44:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2439428949; Thu, 20 Dec 2018 19:44:58 +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 C0A3C288F7 for ; Thu, 20 Dec 2018 19:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731789AbeLTTo4 (ORCPT ); Thu, 20 Dec 2018 14:44:56 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41530 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731483AbeLTToy (ORCPT ); Thu, 20 Dec 2018 14:44:54 -0500 Received: by mail-wr1-f67.google.com with SMTP id x10so2968715wrs.8 for ; Thu, 20 Dec 2018 11:44:53 -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=cpXkvhinpIIllAECgcgzKJXzSqbPUUO33RniiCIjngg=; b=ESkt2snjmRwvB7Sf5lLd4WOaZgDZ7qbnlWn8kNRMgJ4bmXRM6Qu3UymMIigsRod3ha rzEtqe+ZLjRIUmSoWm5IM+heZhEcne0nP7tmZXDB4WUp0zARC7n3ouSWCX/Kyx94faxR fjXhmzZrhwm4q0fY2qqgmsZQ0t/+a+DS8z3JIi/o6UHTO/tT0NMuFjZLNIa1+Tvb+uwO fu6ugpwNrHNu+B6CMCp1s7k8VwLbAYCywu//LmskaUkSpwHOh9Flu5OcmSXWpKAKccpE TAFeEGi7T2k+u9gm78edfw3V22Q8T57K9Fv9z8HNeFDB16fYY2QVIXKPZAdGSLxbtsy0 husg== 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=cpXkvhinpIIllAECgcgzKJXzSqbPUUO33RniiCIjngg=; b=tB3XBjeyUtpJLPfkPYzYYXtfj+nxpbBEsWwWDbwK9fSX1rjauR9nVDMMSu8ksif6NN Qz3MYZ9PQYbWD5vrD+MqhjW+F3zThstYDKSa5k1c4ygEMtFJvJEwDQS5pb8rOPJpbt6d +bcW8dqldncXgccwqXChJPoAHfQ4C4KeQMWv0aeSHQt+TgWKrwnZBeZ794jKSg/Ht063 NWrBInmqrKBU93C1u78tSkYj2SwGoSWAW6ErP3pUlH668Bi4azzYzkUJvuGrY3DKtjvI DakPc47DxoBND5irIebYMfUjuTChgqCd6PHXzcqh8PuE6AsT03HLB4dbLqixYVoYaEuX zRpQ== X-Gm-Message-State: AA+aEWYzBC2Ow7b2Krsv/aDwX61QS3WItpgTSMfH6+IBCDc3jEUczISs MwGADif5rU4ohnr3LLJlWIJNTQldmJ8= X-Google-Smtp-Source: AFSGD/UcnGAUTqLa6LvRAs7GxP7g2wJxgG+YNlj+3zEQf/ATHyBC5dIp+irQQX5JD8PjMEf6UWh63w== X-Received: by 2002:a5d:4b01:: with SMTP id v1mr22931184wrq.5.1545335092276; Thu, 20 Dec 2018 11:44:52 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:51 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 04/26] ident: add the ability to provide a "fallback identity" Date: Thu, 20 Dec 2018 21:44:20 +0200 Message-Id: <57a654887e652251ae966ec31b4604dc8222f9c6.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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: Johannes Schindelin In 3bc2111fc2e9 (stash: tolerate missing user identity, 2018-11-18), `git stash` learned to provide a fallback identity for the case that no proper name/email was given (and `git stash` does not really care about a correct identity anyway, but it does want to create a commit object). In preparation for the same functionality in the upcoming built-in version of `git stash`, let's offer the same functionality as an API function. Signed-off-by: Johannes Schindelin --- cache.h | 1 + ident.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cache.h b/cache.h index 28ccc97e10..dd2154bcd3 100644 --- a/cache.h +++ b/cache.h @@ -1493,6 +1493,7 @@ extern const char *git_sequence_editor(void); extern const char *git_pager(int stdout_is_tty); extern int is_terminal_dumb(void); extern int git_ident_config(const char *, const char *, void *); +void prepare_fallback_ident(const char *name, const char *email); extern void reset_ident_date(void); struct ident_split { diff --git a/ident.c b/ident.c index 33bcf40644..bce20e8652 100644 --- a/ident.c +++ b/ident.c @@ -505,6 +505,26 @@ int git_ident_config(const char *var, const char *value, void *data) return 0; } +static void set_env_if(const char *key, const char *value, int *given, int bit) +{ + if ((*given & bit) || getenv(key)) + return; /* nothing to do */ + setenv(key, value, 0); + *given |= bit; +} + +void prepare_fallback_ident(const char *name, const char *email) +{ + set_env_if("GIT_AUTHOR_NAME", name, + &author_ident_explicitly_given, IDENT_NAME_GIVEN); + set_env_if("GIT_AUTHOR_EMAIL", email, + &author_ident_explicitly_given, IDENT_MAIL_GIVEN); + set_env_if("GIT_COMMITTER_NAME", name, + &committer_ident_explicitly_given, IDENT_NAME_GIVEN); + set_env_if("GIT_COMMITTER_EMAIL", email, + &committer_ident_explicitly_given, IDENT_MAIL_GIVEN); +} + static int buf_cmp(const char *a_begin, const char *a_end, const char *b_begin, const char *b_end) { From patchwork Thu Dec 20 19:44: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: 10739469 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 6D0CB17E1 for ; Thu, 20 Dec 2018 19:44:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CD02288F7 for ; Thu, 20 Dec 2018 19:44:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50B1F28949; Thu, 20 Dec 2018 19:44:57 +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 02C69288F7 for ; Thu, 20 Dec 2018 19:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731756AbeLTTo4 (ORCPT ); Thu, 20 Dec 2018 14:44:56 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33335 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728588AbeLTToz (ORCPT ); Thu, 20 Dec 2018 14:44:55 -0500 Received: by mail-wr1-f66.google.com with SMTP id c14so2990777wrr.0 for ; Thu, 20 Dec 2018 11:44:54 -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=nw+Q3Ds1B6FCAU4EdA/Y7hx16jwbNmV5Tq4z4X0gRrk=; b=uMeHFVP3tQ73dQWEshf/wjnbGPbluK/PHe/GFAUIpEGVYvHzsqtAwhoEIfWrJpQUIf 50X5+CDfGaZjDuBUBzmOSOuO60Lpw9v06CrOWIr2nFSSFgt3LBNF4OJP5MSuQk0pXRwO PYHVc/JfeCUwnh2If4DWHnH1sGY716kpuDhSZZbFdBHMCbuEtjtAmZ1CKlMAEpSKjPnD ASIIpYxHbKvJY/JyYpMTuiVhfF78L7B7ACPB6wODYfZqe8d8UqOh2YD586oLy8oJHTRq 6Pi1ajU084xhNbWUnNbqdUlXYHIqSly3WTbWGT/M1l0gW1XZvj8+7ySgyvrnPmrzDEu2 DUQg== 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=nw+Q3Ds1B6FCAU4EdA/Y7hx16jwbNmV5Tq4z4X0gRrk=; b=FlxLoYSGtuXMyURzX19ZfgvWAu00UR4otaT0FrpkH+Mc+hRyW8TlYowwzGfxYTAZ3Q 9/UK4YmIcXEE43vwOJlOFXuPZ0k+vYlum9Guaacvh6TUfsr9pg2mDHk2BX4Qp6VZyhXL G4SmqBbKsodaQKLtfIA6DmwY5iXrI6S6rVfA1rGNfT263NR0OQ3cAED8Jp2/0gdvJgVf U7YLslwwujpGAAlkGwHTBbaKCyPaLdCEdNuX1e1lwlhjxBGwDrGL6gBC+aPx2xc10ndZ VDOZN28odiT+PkdPS+bGPNjY8CMmMYT9ka7rT2Eg6FSJZFbKkgeS1OmBizh23ufXT69v msIQ== X-Gm-Message-State: AA+aEWbjhreNgvuadl6IWsZZcrFPEkC+3zVhvlGOoZwosGXzdhGDOjWy Luz/C4OLNn7r17aNUsNFlHSjaYjl330= X-Google-Smtp-Source: AFSGD/Ut4BMcc65qajhjvHN3TPebh+7CmKXx7GrnUymQb5AkUkdxhf6Prs40havZ+kCu4UiVmncyFw== X-Received: by 2002:adf:c888:: with SMTP id k8mr25593547wrh.6.1545335093124; Thu, 20 Dec 2018 11:44:53 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:52 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 05/26] stash: improve option parsing test coverage Date: Thu, 20 Dec 2018 21:44:21 +0200 Message-Id: <7e3081091a405469e05bd64257fb07eb241b56a6.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 5f8272b6f9..ac55629737 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 Dec 20 19:44: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: 10739473 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 127046C5 for ; Thu, 20 Dec 2018 19:44:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0133E288F7 for ; Thu, 20 Dec 2018 19:44:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E995F28949; Thu, 20 Dec 2018 19:44:58 +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 698AB288F7 for ; Thu, 20 Dec 2018 19:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388194AbeLTTo5 (ORCPT ); Thu, 20 Dec 2018 14:44:57 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51567 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729246AbeLTTo4 (ORCPT ); Thu, 20 Dec 2018 14:44:56 -0500 Received: by mail-wm1-f67.google.com with SMTP id b11so3255020wmj.1 for ; Thu, 20 Dec 2018 11:44:54 -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=RJ6RiLldVGMNSduda7iEEKtcsuEdG0l6aXfimeh+JqE=; b=C4pxBiGOaV5M5nKzTdpVcOpzEug2dnIN8q9LkaoNoOCEa2xiheqOj+gJ58jD+jxAcO oAW4Eu43G2N87a7T3HTVF3WAn1gIQL3eOe9l0Cs6KNjVCaew/R5P7QjevncIMFBRFqjo RSVzX1MvcG9Ti6+GvYSGISANwlpWSDIEyVQvSkc5jvlCUJEgCF/rb6Z9erQ6e3N/BSpf pud7osj0KFOzMc8GmCJbtNJiT6cPThYpFjCZAPe5UTcL+19BOkR0gD0neYaeSsYDuKrI cilx8yDNNOb2F04pKpyJo76HWZc2+/bFPeFdMeZ3o3ZWA7BGNwYSN6z3p/4QnpXKHFQD 2pAA== 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=RJ6RiLldVGMNSduda7iEEKtcsuEdG0l6aXfimeh+JqE=; b=K6DDCsxAhASVZvkZr5VT5HIuvPYVmA8KmtRhd3Ifi2lQauYFaVPJKhdRM6nIF0roRu 7ixGXbCrN/NyY7QXmW9TB10wT7W+91SaI/KAsvkn6vin4/DVEdjy11NV+8Sh9oeHhHGY 8PcvWDFbMUWMn9TzIezJqQdz1p0M+UnigKNrjWuCL1ygZechzEak7qCTqUZDPtLEJA/d fjDCtVL7znrWqBbHhxxUZZhGS4w8aKgatzXnieWZVv4Pvr6U4QdObs/Sughvhx0PGTS9 8Scio9kayCQIrbqmNWLHPSdRhIu+iNSlwBskOU7qZWKksNulIt2v5Tv5E6tav2gCcd7d N88A== X-Gm-Message-State: AA+aEWbyFPCUmI4G2aZ99mI8h7UBqcB7/dt8jWHpT/pGWATZHw5/moZC dMi+MYalfiZOjFZm2fQTI2MQvrCpYOk= X-Google-Smtp-Source: AFSGD/XclRD2j0+PzQliqdVH83zySYhTRj8/3twqkv5Vs51ULZuxcm116oC9KdBQr3WPCUlIko6ZWw== X-Received: by 2002:a1c:87cc:: with SMTP id j195mr26671wmd.2.1545335094034; Thu, 20 Dec 2018 11:44:54 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:53 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 06/26] t3903: modernize style Date: Thu, 20 Dec 2018 21:44:22 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 ac55629737..4e83facf23 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 Dec 20 19:44: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: 10739479 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 98B966C5 for ; Thu, 20 Dec 2018 19:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85CC2288F7 for ; Thu, 20 Dec 2018 19:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7896728949; Thu, 20 Dec 2018 19:45:03 +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 2E591288F7 for ; Thu, 20 Dec 2018 19:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389290AbeLTTpB (ORCPT ); Thu, 20 Dec 2018 14:45:01 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34157 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731612AbeLTTo4 (ORCPT ); Thu, 20 Dec 2018 14:44:56 -0500 Received: by mail-wr1-f68.google.com with SMTP id j2so2994801wrw.1 for ; Thu, 20 Dec 2018 11:44:55 -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=mY7vCVVW5WN+pf2edAMLwHM9d7jaxC038SCALe+ipLM=; b=Mph3szaZr1ptJwq6CqXM89Coc9Q+KaoHSIQ8FXOjSHMxDgQ44uPBKeh3Tll0Bqawjx jfcCgCT4eCjWVAkvd/yLnVxHareV9UOo6xXZjx/GXy8wYSDGda32wVuwE0m3o3aTvvUy DDfW4k8zBUji5SVfseMQ8YEi4bexq02su+4BffCpJpxoWKaTd+/7+vpDQp1De1ldDKby zqSy/i9wBxXvxtcC4nbSXpJiUF9fVEBoSFQoQMs7vqzRUfkHAhGZy1IbGkE3LCIKUlfw WepxYC16FT6p8FttmDmJMWR8f6jj52lUIGAOY8I4Zs3qI6gTazNdJaPJBZl8rP6XOA0Q QzsA== 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=mY7vCVVW5WN+pf2edAMLwHM9d7jaxC038SCALe+ipLM=; b=pNrwRTu6CnSf80CJTSJgUa5MJDIm/j4/gGWzwNodGjcdCSJmH1Y7hCi/iSrwJYv+Z4 GPoUtz/fHu9RHZuIDCWoWzeos0gI3D9MtbE4VM8glMeL4EUiglxk4s9U0p94O1h16ncc +MryiQHqfQzydCKeuBKodtgYQ75cBrbllNt9AeeyyXZC2I86Hk2nvdVHmrhnT38rGhYJ nPk9TLdo0GuPmlaawkmQPQVB1SaAQ24z3AEtGI5lb6PVE2hzM7IhrhvChAfG9fAGZjs4 CaJ8WCKSfy9q7akEqkUntD2Ar8yO8PUH+FDJHNgIVF41Q4F8XpKBOeBGY3UzJ+TZEWPL eLcA== X-Gm-Message-State: AA+aEWbQi2m1EGQRtu0w4Uu6uEHcVJLa8wAEoujPmlsuCFkd4yse5oA5 1ZSpQrJ4H3qAnJR6IvfxgIG9xPdQZFw= X-Google-Smtp-Source: AFSGD/Um2iTDElipUMOLkzfvMUSiOwDw57Wt1Rn3Zyu+bTca+fwdfIGsu6Gt6jSwwiwLl03upj95yw== X-Received: by 2002:adf:e8c1:: with SMTP id k1mr22406882wrn.104.1545335094932; Thu, 20 Dec 2018 11:44:54 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:54 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 07/26] stash: rename test cases to be more descriptive Date: Thu, 20 Dec 2018 21:44:23 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 4e83facf23..98c25a671c 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 Dec 20 19:44: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: 10739475 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 9B5AE6C2 for ; Thu, 20 Dec 2018 19:45:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89E4328949 for ; Thu, 20 Dec 2018 19:45:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DC3D289CC; Thu, 20 Dec 2018 19:45:00 +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 32FE1288F7 for ; Thu, 20 Dec 2018 19:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389098AbeLTTo6 (ORCPT ); Thu, 20 Dec 2018 14:44:58 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38133 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731483AbeLTTo5 (ORCPT ); Thu, 20 Dec 2018 14:44:57 -0500 Received: by mail-wr1-f66.google.com with SMTP id v13so2978838wrw.5 for ; Thu, 20 Dec 2018 11:44:57 -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=6VRjcnBvSrlU4gBKfhbliNQT9yhqphW2VwFgzkHDULY=; b=W5uHB146GLek2uzDSzg8AZV644XsKHSGr++FIsq66IXwak/F66n0TnDoxhm4DMJb1O IKLKPVED7IKALQW/q0gLr9QNR1fmCjmpQ2ghfzpHNbZvTcBRd592hLYbOy3c+G0xsQcB kgXqILYixGXbds9BGY+2qQcWFfO6YkEdJ6joOinEk2tlLy37fzC4KdJ6DJiD8EHL8QPL h7v6v/UFWqKm4p2gpfdHdqIgvYG3sJ+htenshoPv6gzd++cZRt+9zGwbSDwcyNaJUo5Y 5i3oCyPolVkyv03yJnUaifdUjJiCbNVTmCbOS2VX9elcyehq4r7qRjDDoPx/zd++VEXt 33sQ== 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=6VRjcnBvSrlU4gBKfhbliNQT9yhqphW2VwFgzkHDULY=; b=EctE6dVCeM4ETz5s0ZOSYXB09o+OCpHUmfV4iDwoT6CtOBtoMqtQf+gQVoJ2x0ZXYq 1udARiw1wzVGhxg80IPv7mQNXq5rh9UWnRVutrGVOd6b0UE4rAUeJJER7foPy45dqLe9 jEbGxiOF+vz2+aNQyKeuKlW1JKzKb76n1EpZ8dchwLzt95Xig0T5VDpfq9b4Yh0TpUoe IEKjcTamnQsLMnfKmrMX828gmWkgyo+tcnSHqW+9Tib881HlC/7Yo/Y6Yv2imP7lBRXq RDAHOplVLVbkM4COgm+ZgPdE9z0Aqz4JpXR0vXx5t/8oFacpFaFYb3h4fkzvuxNSEx2L Wk0g== X-Gm-Message-State: AA+aEWa6y5sJx0pdM3iIM/sjqUJ4NsJJjMq9vO8dRASraTBqpTomtAM/ as+94C85xVoSMx2ct4VhgLYzcBetWsU= X-Google-Smtp-Source: AFSGD/UQe9D1ZD1EsBOG4IbLxhfyk37t3tOU32Cf3hTBfsDSS56uNfbLTWqlO97CBz8udQnOMDvD9g== X-Received: by 2002:adf:9c8a:: with SMTP id d10mr9989947wre.244.1545335096173; Thu, 20 Dec 2018 11:44:56 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:55 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 08/26] stash: add tests for `git stash show` config Date: Thu, 20 Dec 2018 21:44:24 +0200 Message-Id: <29c2db2e73bae6b8249a5b4d73ce784a4c861953.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 Dec 20 19:44: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: 10739477 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 632196C2 for ; Thu, 20 Dec 2018 19:45:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50154288F7 for ; Thu, 20 Dec 2018 19:45:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43C4228999; Thu, 20 Dec 2018 19:45:01 +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 DCDB4288F7 for ; Thu, 20 Dec 2018 19:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389148AbeLTTo7 (ORCPT ); Thu, 20 Dec 2018 14:44:59 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51570 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729246AbeLTTo7 (ORCPT ); Thu, 20 Dec 2018 14:44:59 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so3255129wmj.1 for ; Thu, 20 Dec 2018 11:44:57 -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=xDSWjKd21WaMX58/5uJjvAzuGhFStRiXxCB1dAbcSv4=; b=rotkJZg21CnJrPque8nISZ4c84Ph9bPf5jUwV0I2WGJE8hH8Zbzberr6Z+ra5+a738 SufLcWZEd5+A6VHIFwC4liPIsQXewm9eTBynvH8a0lHkyRRZolE0oPkjRFpRmBTl9iiA 5egXRCZNF/RQIvMmOYFF1KxUszdJRDAmQQON0FG0cQE1pcZVyfJ0Xqjope6CVQhHbfcq qExU5eL8dH6eWnflO6v3bDkBRzZXzOns5ld1XK9kj1KU2GOU+Z0HLY+wu5R8/odqrDAh TAyRXh+2YWUyydyjexqc43kKaIpBcN21aOy+4tA3/jLVJktmIcb10Muw4qE0lw47D0VV Fp3Q== 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=xDSWjKd21WaMX58/5uJjvAzuGhFStRiXxCB1dAbcSv4=; b=XIV9+7Lx0Pib9UPPsd9UvOqHdhkfWV5l7xmmxk7ROIAbqLDx5y/fB3mwVaygi7JB7T 66MZFkdhckYhiu+HgTxjBMvH1CHi67b0mJP3DMmu4b/FdRMdEOdKrakMFRNy16aHi3zW nAnWxS2aF4xbfwmQYt9qDXR48BGW2nZVOuQokd3glWLRRbw+06+urh0WqUAybCpL6NVi ORE/AagR0kqjitFJ1gX40HRhhNMB7Q5dvFUIyRiT4JLpfUqDO/m8h/MvE83nh3Boy3Pe FO+7Aq3G2IpZBOXXWXtITZZmsU4bbVNPf66PNd8q+kEFCatorYOgVJtuMMGSUhPAjbNy rLGA== X-Gm-Message-State: AA+aEWYdblm88dHS2HCFvZg67GfMgcgP1Uhg2w4Uw+6z8TDnX9r1XCcv Hz2fo2E7uNV4zYMGEwNWNtdlb5SJj4o= X-Google-Smtp-Source: AFSGD/XOrOOsuAEziSUVyT60P1miDuMq5wfTsAealQJBtQDcpWESVsErg1FqtKt9+OfPLc3pxu+nFg== X-Received: by 2002:a1c:c58d:: with SMTP id v135mr16794wmf.88.1545335097102; Thu, 20 Dec 2018 11:44:57 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:56 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 09/26] stash: mention options in `show` synopsis Date: Thu, 20 Dec 2018 21:44:25 +0200 Message-Id: <1e187c54fcb13555e463c5b6f910b4bc13974e3e.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 Dec 20 19:44: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: 10739481 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 BE04C746 for ; Thu, 20 Dec 2018 19:45:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB67B288F7 for ; Thu, 20 Dec 2018 19:45:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F3CE28949; Thu, 20 Dec 2018 19:45:05 +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 ECB26288F7 for ; Thu, 20 Dec 2018 19:45:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389399AbeLTTpE (ORCPT ); Thu, 20 Dec 2018 14:45:04 -0500 Received: from mail-wm1-f50.google.com ([209.85.128.50]:50999 "EHLO mail-wm1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731483AbeLTTpC (ORCPT ); Thu, 20 Dec 2018 14:45:02 -0500 Received: by mail-wm1-f50.google.com with SMTP id n190so3259211wmd.0 for ; Thu, 20 Dec 2018 11:44:59 -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=5437Q2Sp7n0f1v5a6KFtGIlUK8YGWfwoQL1NFPYIFL4=; b=lMLAlBQ5PiNAc/UBrhSh63xUjknT3QfDe3oqxvtxwPCYhPhMd/Fmml0CYZdCqXBW22 YQmRdT/6dRUUnqB9eBK0OQZBv1OLhCX+ySMRODVsQKGYZaKDc/z8fvQqrhE/qfqcUC2v 0UQ5d0tPWBfvcnbVbIx7+X22ia80shXuag4miD7DWNPMYz4LLgaTCzOwAhmxxOaosF5W PYuCOhLJgr7uai7BrEcrfeB+SyJr+kkar7ZW85Vg6RUbXTojKVusopaaHx4Kv6rJxLEl QEH4c9l1B2MdBVT7X6+lmMNSQgqkSF2SM7ZZQ6zsdCMTmUAz/gxAK/LmGAPX+nIL1qOf XO8A== 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=5437Q2Sp7n0f1v5a6KFtGIlUK8YGWfwoQL1NFPYIFL4=; b=bxIblTECsseEegfABId4s+e6HwOuYD58Z8yk+gat2KEFPVeKhJcUsz6MXnsbHpXdtz 8T1kCiql7TFk+lGWh+Nj7PjSI30LTvdzEBDQMhu5Gq13z6E1tCOZRwHVFhup2lKdPJOE V6rfR2EglLwtXhsadKDDamQvIWOa570cTUJzAvwZV0Z1mZco2i2H0ey990EnA32XG8q/ xIm/S5jFygdLHgFaw0MdZN9al5kAyUrGcCuqjdGvWRCazEXaGkuNElV9wwjMdceALY8/ 01y+zNOrLZ8BgZJe51Foy7BQXL8nc0HmKhBj4wFGhYeZT+t30yRNY3kuzg9nwK3t26tG 5oOA== X-Gm-Message-State: AA+aEWZi4YcWbAdEH/0EnFJNuFuLFowr7kaHykA5PGUbcvDgWLOqO+LU RD6/OQftHQvkvSdVtGRczmsv4JVbuMI= X-Google-Smtp-Source: AFSGD/Vde62RlTkORwD+MeUlVMt9Lam49ao4mK6PkalNacMSP95NpmGNEb2UX1mdTrx3YAJoqQvicg== X-Received: by 2002:a1c:e287:: with SMTP id z129mr12558151wmg.71.1545335098167; Thu, 20 Dec 2018 11:44:58 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:57 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 10/26] stash: convert apply to builtin Date: Thu, 20 Dec 2018 21:44:26 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 1a44c811aa..c246fc7078 100644 --- a/Makefile +++ b/Makefile @@ -1117,6 +1117,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 789ce2f41d..366a082853 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -583,76 +583,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() { @@ -730,7 +665,8 @@ push) ;; apply) shift - apply_stash "$@" + cd "$START_DIR" + git stash--helper apply "$@" ;; clear) shift diff --git a/git.c b/git.c index 4d53a3d50d..de9c774573 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 Dec 20 19:44: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: 10739493 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 01E86746 for ; Thu, 20 Dec 2018 19:45:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4C17288F7 for ; Thu, 20 Dec 2018 19:45:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8E0A28949; Thu, 20 Dec 2018 19:45:14 +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 2484F28918 for ; Thu, 20 Dec 2018 19:45:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389488AbeLTTpL (ORCPT ); Thu, 20 Dec 2018 14:45:11 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54698 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729246AbeLTTpD (ORCPT ); Thu, 20 Dec 2018 14:45:03 -0500 Received: by mail-wm1-f65.google.com with SMTP id a62so3242013wmh.4 for ; Thu, 20 Dec 2018 11:44:59 -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=UCt68U6JDmLabnJePwMoA9fxXTHaNM/GapwpHtuQfTU=; b=n4ak4kCIF9zS27nbqq6Ht/9qC3yW4QDIsatIr9+hZKPGYlc7eY5TUviRrUXiEe1j9+ UbNPq/1BnSDtX1eI/lESU9/ah+/f5/34V30gnTtjQ2VzYN/PLmV2xSmgOgJZEpx1JhKW HsYdBzDzLzlhWLlG2iMGD9LsaasubIdRL17kRyM738cznz623qrbyLtr6cB65y2piooC QfToBIN4DZzpy/w+EHzN8+dDPnsNMR03b4wL1+ZzZ6aokTOntL2ZeouLgSozGV9MAIia z3w4xSkct+hF08TqV7CKcq+hlH+Hlfu+pJ5nqoeB39Qou+420bViXQcTgpx5V9MucRO5 FOQQ== 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=UCt68U6JDmLabnJePwMoA9fxXTHaNM/GapwpHtuQfTU=; b=RzQjeTc+xFb3SYhPeCklFpfDmfuamoa8KA4f2vJPFAvnq4nKqZzE9VZQTxpn+bbCt0 hrghN8uuxxqQPShfTGcll7qrXjzTgKUEULkmube8xW0TNHPRtsdVtnSMhyqDqurUQ9LD 2Zf1cr8gx1qgqfuysU2xMqdpwMf596ZsTdS/psa080wLKGaLJ9C9eBitiQwUhDN+Wlr6 1gJZsCkVFIQP+2lxflaff/ut3h0Us1tzqEpm5OigMOKKVsoHGwoCR1vRN+eZn/cCYYsq opfXi+22/kB147xEjWx96YW9ApbNXHHyXPP8Z069UlZ7WD0NUcp0TVnm7rELbOTy6/HC gwNg== X-Gm-Message-State: AA+aEWbwnVidjhT+GXxxVX8CvW7jvU/mgG6hmESDIPGCusR9HPDjjBdn igB/phu4TT5A9DcVqtW8+rAyACrAX5A= X-Google-Smtp-Source: AFSGD/Vn7xzELw+IBjceqGqUkqBitRMSlMVlaHklmTeWxUmVfdKtJxECBeMoBYdZQrie/dJrRT/mBg== X-Received: by 2002:a1c:400b:: with SMTP id n11mr13003627wma.85.1545335099005; Thu, 20 Dec 2018 11:44:59 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:58 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 11/26] stash: convert drop and clear to builtin Date: Thu, 20 Dec 2018 21:44:27 +0200 Message-Id: <42af83890f1b85f4ae19fc68c26e6a3afb9062cd.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 366a082853..b8f70230f9 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -670,7 +670,7 @@ apply) ;; clear) shift - clear_stash "$@" + git stash--helper clear "$@" ;; create) shift @@ -682,7 +682,7 @@ store) ;; drop) shift - drop_stash "$@" + git stash--helper drop "$@" ;; pop) shift From patchwork Thu Dec 20 19:44: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: 10739483 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 09CD9746 for ; Thu, 20 Dec 2018 19:45:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE843288F7 for ; Thu, 20 Dec 2018 19:45:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2AC828949; Thu, 20 Dec 2018 19:45:06 +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 93069288F7 for ; Thu, 20 Dec 2018 19:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389421AbeLTTpF (ORCPT ); Thu, 20 Dec 2018 14:45:05 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40323 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389202AbeLTTpD (ORCPT ); Thu, 20 Dec 2018 14:45:03 -0500 Received: by mail-wm1-f66.google.com with SMTP id f188so3492833wmf.5 for ; Thu, 20 Dec 2018 11:45:00 -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=HlIF+lfhvQDm16Se1Y52mVjVO6oEVfbhl3tVwsxkctE=; b=sYX4bKeuqQ3b0ILT/jItFA9QVhEYYeH2HBVoinzCjyOsCGUNYKQfXQd2c6JaLxP759 FNOHTQryjp0rqdsJclihyM5OeYcH440+9y9LC65zZHt0Zaigqa8i4heGpLChxe2AAYJU E50NE+y+11wKufixL4U1pjwlwNn88Fz0IWy65KT45wM8h0nv/BjpFhBw094hRbtGyoSl Pep8BFXGRY41mYYIA1xp4JM46X/BzE8dAqJSYjOKU1qbpH/gOby48ucS5tXpKgw2oX7D 6dxcu7wd5MDmASkF1GJ0Co3+3eClhQaMsDrJ4mFBI5uKWYLuMdrbWp0ku8hUoJKnoYbN 8mdg== 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=HlIF+lfhvQDm16Se1Y52mVjVO6oEVfbhl3tVwsxkctE=; b=EjSowasQXTK6aYb34/EC5gJ317KPeUin2GstBYPv04/oCwg0icm7xaX1ZmM/vGgT5T WNe/5t3juyMPAcmO0tCMaz+TtkX04KhSYjwXZ3BNwSSpt6rcjfyxrsxQFXTu+KSyXj6v X1y3XXWCmjFjeknsOBMRvKndneTI4A3S14UTQKtoorwtU8jjuwn5DarS1uy2tGOj3fr4 zmK0v/vYvHI1oIFtOUtsbHu76LDcNh49dUGpfY2D+LF39nw0abccx9aekaJfdi54i4o1 etLP0KJeLnjviYsAFNNaBCJETbxLACNpbuLTiGL2FG4BxOc5AtL4zEOXaQy1vVXIikoc qiMg== X-Gm-Message-State: AJcUukfcMmEbJHcbzBzP25ikf2u1wGttTTjT77p26WzI4DfBKioPZZWC UyE+K9prsbqLMjshV9kWlf2V8Xn/Mbo= X-Google-Smtp-Source: AFSGD/XhMCVXTeybieBZb5quZcU8ZY6G/o+abQtWGqfjOShVhTnm54BEF+87Is18SiHpnyvwGFpo9A== X-Received: by 2002:a1c:934e:: with SMTP id v75mr8017wmd.126.1545335099944; Thu, 20 Dec 2018 11:44:59 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.44.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:44:59 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 12/26] stash: convert branch to builtin Date: Thu, 20 Dec 2018 21:44:28 +0200 Message-Id: <9f69a7f2530772992bd3319c450f516bb100675e.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 b8f70230f9..67db321a4c 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -615,20 +615,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' @@ -690,7 +676,8 @@ pop) ;; branch) shift - apply_to_branch "$@" + cd "$START_DIR" + git stash--helper branch "$@" ;; *) case $# in From patchwork Thu Dec 20 19:44: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: 10739491 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 9CB426C5 for ; Thu, 20 Dec 2018 19:45:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CDA1288F7 for ; Thu, 20 Dec 2018 19:45:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8125C28949; Thu, 20 Dec 2018 19:45:12 +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 32291288F7 for ; Thu, 20 Dec 2018 19:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389486AbeLTTpL (ORCPT ); Thu, 20 Dec 2018 14:45:11 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38561 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389287AbeLTTpD (ORCPT ); Thu, 20 Dec 2018 14:45:03 -0500 Received: by mail-wm1-f65.google.com with SMTP id m22so3516191wml.3 for ; Thu, 20 Dec 2018 11:45:01 -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=K+0ukJY62ilbYzGfOmqQX2KF/iHJSOtry09abN810cY=; b=llGJd427pGmXBnYFYC9fCvYdTEvvjsqFgJvayuT0f81gnCiqlgjnsoLL2Awg1oxI7f u388Tk/fcFj/LaPI6vQD5XHY+avli5j5uGCX/iVRyJT+jwjdqBcAtG4zqjrsxrr9crGF Jm7NTTGUJu41ZDlbzlY2a+caNzsvwGDmugswIf/YftiFAODLmO2mRjvwkaQs++8LY47v VSN1e+xnMv5AFL57uzM+wJW4uVt+840r07zOGieYELAUrAUYxVk7CeURyY8AbuWu8qKm UjoQDF2J2y/tk9x1dDE7NQaeAvV9sama4ZgEz4b23YpuV04LdWdXTJuE4oK6C4/rlOcd IiAQ== 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=K+0ukJY62ilbYzGfOmqQX2KF/iHJSOtry09abN810cY=; b=l3XNuKnBwP4bWV0JKSEhtGDXXB9Cev95ShTQft9O7N/KZ0CQiw1wlEN1IPOi6sole2 akoux1CzrZfvpbwZVJF1gkdUNrT5duJ07lMeFoA/Y5m6PEkiSUwSoU910AAzsJ4QQl2T 0r272NxsLOGiM2jbqF6F0cfACCYW/s7VFHLlFCdLFeg8CVrXlxN8SuD+XweUfCvL+oEM wuEpIGveJanDXnRm/T5eTjyVnvNc2BvENNtmjzLXYi14sKzEbxYjvPgzw3X7SZEoigHn O4yGwtzS+eVSmaRgDVk16y2KfEKzdw9/fgAByaVKO3f+u1cVMqqlp53ooY+KWY48O2WL HM+w== X-Gm-Message-State: AA+aEWb4M+gI617y/5kklEWk96hj9j8bJNvaiZ+7qqElIob/X3HJK6sT UbmATGoBNYqf7X3RIHBkDyi9E/7ehas= X-Google-Smtp-Source: AFSGD/WglduUu2p3nYFd7a+CpeF8g5JjzzbJSsrDPABmKrkS6QQttX1LL3F/fGTiDKSiWew7uYfUdA== X-Received: by 2002:a1c:f207:: with SMTP id s7mr12444646wmc.87.1545335100992; Thu, 20 Dec 2018 11:45:00 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:00 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 13/26] stash: convert pop to builtin Date: Thu, 20 Dec 2018 21:44:29 +0200 Message-Id: <08bacf490dfa766fd5f6b35ac3fd96f37242c52b.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 67db321a4c..8a9f907aa9 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -571,50 +571,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' @@ -672,7 +628,8 @@ drop) ;; pop) shift - pop_stash "$@" + cd "$START_DIR" + git stash--helper pop "$@" ;; branch) shift From patchwork Thu Dec 20 19:44: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: 10739489 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 1507E6C5 for ; Thu, 20 Dec 2018 19:45:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05D9A288F7 for ; Thu, 20 Dec 2018 19:45:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE1A228949; Thu, 20 Dec 2018 19:45:10 +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 A5597288F7 for ; Thu, 20 Dec 2018 19:45:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389473AbeLTTpJ (ORCPT ); Thu, 20 Dec 2018 14:45:09 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50270 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731612AbeLTTpD (ORCPT ); Thu, 20 Dec 2018 14:45:03 -0500 Received: by mail-wm1-f68.google.com with SMTP id n190so3259355wmd.0 for ; Thu, 20 Dec 2018 11:45:02 -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=HfDX7o6pDfIKWbvvg/L6ZObKOWCviZjfJLmXTNSu8DM=; b=NHKOCG+5kMS1lsO5UEe6Bx15bcsaO/919TTTF+iH2erfMVDZsVjatTV/bBLXwrO2In bzyAZ/7OG8B2s5YU7wzHpKfM/b+g5y9Hx2iwUzN7BW7IJNWZGpHxcS1ChlO9ay6xW3do jzq7TA+P35sRt/wOYw7D5qzMBrjTYNO+7Hi0Zsys/G57nnVDpaOFjyS7qyS0vwaBryMS n9vP7EZawF2Jt4t+effw60btGmNyYvq+SOvlKIX6sDfN2tstdO1gwQcNW8JlbCnZfddj 8+EG6eibRXenJqG0+QO7bvn72ZNKkZkAWOiWeFqx/fIQ0gh7r+7NCeDPiRrrF3kvI1uY hp1Q== 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=HfDX7o6pDfIKWbvvg/L6ZObKOWCviZjfJLmXTNSu8DM=; b=BSPwJS43Y6wvikX/U4WtlJpyKAlzVre6JVoqiKUF2lfwTWoOPXYIfk3Oz7nEwBlAYD D5lQrqWbq3Lm34QgOgCtIV6Az8b2Y0JUC1UtQ6QM9tC7bSJVoWr2gOdaDfl57kgUEHxc psMCh1+ozqJ3Gz/6mcZ7d9J5CTz65Dofj1BokpP/f++hWjS1ftDUzoEoxoLb2gpcQsgw LFySRoB1Lu4py4K+a1giL6Mh78ukenhJaN3go5vAwgvt0YwXmtzE5QQUf5XUo+DklnVe 9Vd2AeOb1k6EmB3bFXlILIndbTuC2P4P+lAjOpuQbq6+Elh0fvYGf+fBiFZulYyvNAxr yMBA== X-Gm-Message-State: AA+aEWY1PbpGwCzgytHtgNvTT3i/q8QHFSFLyzLKT6j8kyxOri/GwCzU +Z0Y0PHhQuv0DYllh0gyfZHAqRUPtjg= X-Google-Smtp-Source: ALg8bN7z36KYvqrMOar47IFczQkrk/3MBrHVSyW2uQYMy8xaCXz+7ZD9XVbxBj4Szjv78iKld8h01g== X-Received: by 2002:a1c:cbc7:: with SMTP id b190mr1605wmg.13.1545335101823; Thu, 20 Dec 2018 11:45:01 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:01 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 14/26] stash: convert list to builtin Date: Thu, 20 Dec 2018 21:44:30 +0200 Message-Id: <09b927684780e34eb65742d03ae9b20be90e929d.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 8a9f907aa9..ab3992b59d 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -399,11 +399,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 "$@" @@ -591,7 +586,7 @@ test -n "$seen_non_option" || set "push" "$@" case "$1" in list) shift - list_stash "$@" + git stash--helper list "$@" ;; show) shift From patchwork Thu Dec 20 19:44: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: 10739485 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 3350F6C5 for ; Thu, 20 Dec 2018 19:45:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22E8A288F7 for ; Thu, 20 Dec 2018 19:45:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1736F28949; Thu, 20 Dec 2018 19:45:08 +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 A8196288F7 for ; Thu, 20 Dec 2018 19:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389439AbeLTTpG (ORCPT ); Thu, 20 Dec 2018 14:45:06 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38565 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389375AbeLTTpF (ORCPT ); Thu, 20 Dec 2018 14:45:05 -0500 Received: by mail-wm1-f67.google.com with SMTP id m22so3516250wml.3 for ; Thu, 20 Dec 2018 11:45:03 -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=5Pf6CIX20kPZL9hb6fyLZ7eMiZZ108ucDKIaGVOrf9k=; b=exMlWNsSAv0hWIn8LSHpnDiK/l2QJ7TrTCAkTffsbokJ1TNI0dzPCoX00EgsaG5bFL gwp0HIzGen1u05ohsx6EHz12foi5RN+LPo3A3y6tcGWT+10BWgzXCUc74QNdCksmToQc ux8+gpXw7EsNwAoS0Q5wWP/xFHu8IG1WCwvXSlUOOSBLWmCCjW5EjB+4xY5FoIiIAoP+ j9DgnJOddQtueBkbW9T3Jz21zzQEHT1wO9FOxLoaDY9t4E9O8pNVPnNpN7mylvm1xFwk dKuAQjod197dnKTuQ3YwMWLMlCW5eoTVRw6K5rfsGG+J4u/l2RDI8xF1Ubitfe8o1V3o f3Og== 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=5Pf6CIX20kPZL9hb6fyLZ7eMiZZ108ucDKIaGVOrf9k=; b=A38ALSC9f+35HXxBvx2EeWa0mjgJId0APN0fqhZ+6K3iUOSt80lU1isIuVGPQm+IYP zD7zIuCstAX0mkNZYlENLtp9k7KobZyaPaf8OrSojLprnfF8fwrEXkXhF7O47gklNS1F O93g5La6W/oVtkGGIt07cTSdjAAF2QqmCzH/8T7hd+H7jbkAwhlVsiradknxWgdkfWM2 SeiReyU03LIA+ZV/yKQ4/0kOUSZzbNzcUP/+xnujQ4fwJ+Ui7+SP2naqQILvJALzwPpB lkRNOGymwuV+txt21/jq0Niqwe+6+cYcmjCl2KI+asixkADJZOrTMMe7x0rPsHbs1Dil rRnA== X-Gm-Message-State: AJcUukdNM8Qz1C1h+RT9sFzC5SvzCqr6DB2AaUoERJnicG/lFjmgrLQd 1qrjWLfMLSf7QG6htHtkwhW4aQiFvF0= X-Google-Smtp-Source: ALg8bN6AoHCQ2lGhulAkCMevcDPni7h3emK3gl5z0F9JydN7xfY1y4r3FzTUL7p3ToK8jyJPQot1Jg== X-Received: by 2002:a1c:541a:: with SMTP id i26mr6099wmb.128.1545335102731; Thu, 20 Dec 2018 11:45:02 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:02 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 15/26] stash: convert show to builtin Date: Thu, 20 Dec 2018 21:44:31 +0200 Message-Id: <28c03869f67c04eef446b8849ab7e3ddc1bbccb0.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 ab3992b59d..d0318f859e 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -395,35 +395,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 @@ -465,107 +436,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' @@ -590,7 +460,7 @@ list) ;; show) shift - show_stash "$@" + git stash--helper show "$@" ;; save) shift From patchwork Thu Dec 20 19:44: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: 10739487 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 BC0C817E1 for ; Thu, 20 Dec 2018 19:45:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD174288F7 for ; Thu, 20 Dec 2018 19:45:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A192628949; Thu, 20 Dec 2018 19:45:08 +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 504DC288F7 for ; Thu, 20 Dec 2018 19:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389460AbeLTTpH (ORCPT ); Thu, 20 Dec 2018 14:45:07 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53453 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389401AbeLTTpG (ORCPT ); Thu, 20 Dec 2018 14:45:06 -0500 Received: by mail-wm1-f65.google.com with SMTP id d15so3236887wmb.3 for ; Thu, 20 Dec 2018 11:45:04 -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=yHJbCaWpESaDvn0w0KAdTlXNUSuNsDwO4zlh31wAvHc=; b=PzwbzHtJxu51ciM13HGPoALMrh8w9jLmpCbbACMCs78R1GdqO0iaPk3/fQFQVl4q3s EUC8wVCnof+gl0EKpNKrY1w48W/yEa7NuM0t5ZkoYz6wYo1xTlgSLoZi0N9eqkUFuk8W P9ET67H9eqKWjEz0AGzHEhz3f3Vr0ePXda3i7BCjT1BWaSl83az4d3xcxcP8hpV/exrv G8WtYuOMTkeTWmfqg+cpKZbeVzaJ8KJPuR/sBuxem1roRNTeW7f2MgUVPMQ6Zp1QFRBa NH+jssu4kLBwTHkTCv5zcZoHbsrqZFSTm4nMSieBb5QaT7vB4uV1pjhWGnZy1Qsdg30o rxFw== 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=yHJbCaWpESaDvn0w0KAdTlXNUSuNsDwO4zlh31wAvHc=; b=j+I/Jx4DyqwfEGODnUxULpVNZKl7OmkkfLEQkT4Sb1gySCOC/yVrzsqhqFe6N2PumK FeUHPGAby+ZuXF3u6GVboQ/EFaCLkZzTZDQxPHCTxdZA+22rjU0eXcVZMDTNgdScqWi7 0H049zVrDnF4LikWELtnG8Y4iCWFgEhgpa2tuToZSkZQXSrr6XHV579XU1wF5CYHa6C9 /U2IKZteTYc+MarZ35r8WAtWA1q/Na0BIFm0FmOe+oXFfkCcxBun5Kb8noL/z9V4Qlp+ U6imbiLTft4Py+7c9I+K5Xvqzvddu/+eH1jTj13fyUvDP8Hrw0wbPHseREVKjskfC2hI qmkA== X-Gm-Message-State: AJcUukcF2hXTyFcgE2uq+hhW9O9O1Xmdb3MDH7lFiIPtDPF8hgFy6aJo B01hD/PXQc/8l+Aj51fxDFN7PgBwnT4= X-Google-Smtp-Source: ALg8bN6FGYZmJRCk3U1t0BS5brOZrbsfm0jGKeEG23sRXwwJQ12haHN+t2H7IOF7xwPueKuhzKTYoA== X-Received: by 2002:a1c:8d49:: with SMTP id p70mr18872wmd.68.1545335103603; Thu, 20 Dec 2018 11:45:03 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:03 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 16/26] stash: convert store to builtin Date: Thu, 20 Dec 2018 21:44:32 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 d0318f859e..ff5556ccb0 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -208,45 +208,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= @@ -325,7 +286,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")" @@ -485,7 +446,7 @@ create) ;; store) shift - store_stash "$@" + git stash--helper store "$@" ;; drop) shift From patchwork Thu Dec 20 19:44: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: 10739513 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 4252E746 for ; Thu, 20 Dec 2018 19:45:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FDB0289A0 for ; Thu, 20 Dec 2018 19:45:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23B45289DA; Thu, 20 Dec 2018 19:45: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 8B378289A0 for ; Thu, 20 Dec 2018 19:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389513AbeLTTpd (ORCPT ); Thu, 20 Dec 2018 14:45:33 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46084 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389202AbeLTTpH (ORCPT ); Thu, 20 Dec 2018 14:45:07 -0500 Received: by mail-wr1-f68.google.com with SMTP id l9so2955949wrt.13 for ; Thu, 20 Dec 2018 11:45:05 -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=RfJz1bHi4dD9FH986Tbgr3jcoEGFAFQHTbZ6PTnMBB8=; b=l+NX5r+bdk15gd3CteYKvaS8hqRDU8bWBGBP/mCrmc7mOumETKOG6791gP2FZkCZRH KgdU3OfoxqbJL8edm1lPGgn2+RASWJaRWi5e2fdVRtBsuEXzIpyZOHKvDjBvoKzUiXqR TeK6CxNS176T0ERDnznWRDuCa+kvhdBeCibnJz/BIvwlMaFQVlkM7MdQ9ys2zYib6CDi +0GZEToyK4QPmnAQ3gQ4iNUzswM6kpJ9yZxrUZSyrJwEJbQp0e1OiV0PFOMhYKV9g7ay FbRa2DV79BarWdDefrCzun9wI/xsIGbb2bFB2nz8WFoMmPouyOA9D1QAlFIOVVJfP9OX JRBg== 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=RfJz1bHi4dD9FH986Tbgr3jcoEGFAFQHTbZ6PTnMBB8=; b=Nn6lW9l+PiC8xFerm5XHD4fuTiEE6hxn/QqJSL+D2pMhtKVZFzy77PpcoFwrGqoIBt yXURoY6i//AyOThrmoSlLRpEhkv4NXOnD4d/rwZsQ8sIX6PFycqUN272M7lY/NEBiKFy BmmdUqcdcZp0on/OX0uBRyE8A/q8beGsyngOMcUmoZVsC9985i9ton32H16iMH9jRLHA nUdU4VkWYn5DJPhVToHNoeDVO35JyjMWyMJNoufjoNMHJ/12DSvDhtHXH9B+brBx6sgo bTz1KcV6qbyw/IuXfBE9SpstNFEb+Gj499wEcXgrBQGt/p8B5tc1aFYI1ta89VJllnB9 rSSw== X-Gm-Message-State: AA+aEWZJUPqyekck1Z+QqFG8yUh6PN6vJaZVih16VyShQAlM9uMUnIXi mtHoFUEH1DDIcysXyun6IBk85NoRVBw= X-Google-Smtp-Source: AFSGD/XZ9zHcbM+bcqS9rnb1VUX7pqGwhw3i+V+U+5q2wCeOgmqXE0Fc8kOJm6S3MuOUhzkqDXtISw== X-Received: by 2002:adf:e247:: with SMTP id n7mr22801343wri.205.1545335104580; Thu, 20 Dec 2018 11:45:04 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:04 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 17/26] stash: convert create to builtin Date: Thu, 20 Dec 2018 21:44:33 +0200 Message-Id: <44eb8652aeea920705e76462b7f4b2333253a34f.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 | 453 +++++++++++++++++++++++++++++++++++++++- git-stash.sh | 2 +- 2 files changed, 453 insertions(+), 2 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 5dc6c068d7..080c2f7aa6 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,429 @@ 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; + + prepare_fallback_ident("git stash", "git@stash"); + + 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 +1248,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 +1275,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 ff5556ccb0..a9b3064ff0 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -442,7 +442,7 @@ clear) ;; create) shift - create_stash -m "$*" && echo "$w_commit" + git stash--helper create --message "$*" ;; store) shift From patchwork Thu Dec 20 19:44: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: 10739507 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 E12D9746 for ; Thu, 20 Dec 2018 19:45:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFC7428949 for ; Thu, 20 Dec 2018 19:45:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C308D289CC; Thu, 20 Dec 2018 19:45:24 +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 4FDF428949 for ; Thu, 20 Dec 2018 19:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389496AbeLTTpO (ORCPT ); Thu, 20 Dec 2018 14:45:14 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45052 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389375AbeLTTpJ (ORCPT ); Thu, 20 Dec 2018 14:45:09 -0500 Received: by mail-wr1-f65.google.com with SMTP id z5so2965276wrt.11 for ; Thu, 20 Dec 2018 11:45:06 -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=/XMvulrcwyIdGeBFtmSnGoJYr3nmru6TeMJ2OkIMjLw=; b=myhDsxIe0+bU7Ulm9AxVo3qmHkUNYCk/NHHxDrLiAUP6/+b+wJ6fAVX59nMoFnB0/d oywPc9c08Xhf/g6vEagM/apsoIdx45Ic7hZL0xUphUM5mXOYBCu/zi4rb4rSmakrtjqJ fYtSunRtLv18MBZfsSJe7M70ExfHwp9quE67j9tgnhl5ni/q0mGYkdvrCUuVObfYbRRo vBwgCBxKfoZBnVyeXuC2qhkvLJHLsxLJD3BMPm2IosQLroUYe1rV5wAzzJ0mvZVJsSK2 s6VlzOuVoT5WhlqRU/Pcwycg0HfAmknNSjDyVPnJwAJBG4AWWKya7ZOK+PhSvbTZX9k8 WSUg== 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=/XMvulrcwyIdGeBFtmSnGoJYr3nmru6TeMJ2OkIMjLw=; b=mH5IQxY/+u3bWpX5QOmenyeceEad01qLuXHPALWDscG0UFGomWsPUAc9VTNyCg2Y5U Qk/jVahbPF4hLfJru9G3uMQq8xp8uJoUBEhk6rUw7TR7F2rz0sXCsa8TPW9wRsyXidQZ KopXE9OSy5QLdSTRz68+l1kMOGtnK/Vnh7jFxfXJR/BGSJABGsQ/6MiUHnLxFymrOLd1 G5GaHFjnOFLbxBPsuvTFAQE0eNLcw/I/XjU3U8IBvRjaDbe89pNT7zxV8MvteA36tK4E OSGH0WdIbIbN3acXPO0kbaf9S5g/gZulnvsVXRSxBId4l9Qqd/KDUSKwNuXSEW7JFP/I RAgA== X-Gm-Message-State: AA+aEWYFe+hPlESeudMUbIGF9lBW9zqIT5fVd4Mvl+C70Oedx1TIeBJU kcL0lHFVNL4L7UIH38PCNxv+vsUdKvU= X-Google-Smtp-Source: AFSGD/UUxQlyQQv1DdvwuL1UcGrTBUU0v+/cg/HnvYPzagogLMkcV8AswQtl2WnxRsAn2ZQVNom5Yw== X-Received: by 2002:adf:b6a1:: with SMTP id j33mr23897888wre.55.1545335105535; Thu, 20 Dec 2018 11:45:05 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:05 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 18/26] stash: convert push to builtin Date: Thu, 20 Dec 2018 21:44:34 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 080c2f7aa6..c77f62c895 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; prepare_fallback_ident("git stash", "git@stash"); @@ -1154,7 +1163,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")); @@ -1225,7 +1234,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)); @@ -1239,6 +1249,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(); @@ -1277,6 +1512,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 a9b3064ff0..51d7a06601 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -429,7 +429,8 @@ save) ;; push) shift - push_stash "$@" + cd "$START_DIR" + git stash--helper push "$@" ;; apply) shift @@ -465,7 +466,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 Dec 20 19:44: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: 10739495 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 7616217E1 for ; Thu, 20 Dec 2018 19:45:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6513F288F7 for ; Thu, 20 Dec 2018 19:45:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5958428918; Thu, 20 Dec 2018 19:45:15 +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 EC76528950 for ; Thu, 20 Dec 2018 19:45:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389492AbeLTTpN (ORCPT ); Thu, 20 Dec 2018 14:45:13 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40656 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389449AbeLTTpJ (ORCPT ); Thu, 20 Dec 2018 14:45:09 -0500 Received: by mail-wr1-f65.google.com with SMTP id p4so2988412wrt.7 for ; Thu, 20 Dec 2018 11:45:07 -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=CzzPuVxc3vgTRs8OE9ZT9k8wESiX84mYKjr6qiWY7bM=; b=F/mACFAP8WpNcb3zi/C+taIb1CdLRF7TljFGqw67AxrI5VR2nVoOjQ2tnehb0p8D46 hmmsneigzqrbGsdW7djHhR0DMwu3lXkHp+Sh/IGgd+2Y8iQsrx/CfsUau5PK3V4E/S9A XCKCl0wycfPiY4Q6uC8o7c4BSKZx9mtlV5/AFR3WYAv2A/hnfHRyBLSptVmlWoSlfg0I tgMyL7yGHhYyiOgIdZKs9xVbJ9Urqz2iYwc/CLaz3oTisP1DBo4qM651pUYKa/g4JqrU Jl1HYf41KPp4aph7Fh6S4Vk+rwulMri2Y6ezTUo5YjH74K3v+kl8fgJ6AfYLz2E8mGzo F/7w== 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=CzzPuVxc3vgTRs8OE9ZT9k8wESiX84mYKjr6qiWY7bM=; b=O7tXZoPeXR+ELAkHpgIswiQ4ba/InW/p1YNb3/jkC1WF+T8ZqUojzW+Qf835U/fmLu /YGkf9elVxTwauawFikG4M4vvOJmvZNoI52q/MzpSl1tIirscyA8Gh6iy/pFO6y1aGMG AZyxvUzqJZ2fOhpQK6/UrLk9lHdZUJe8ySiINnX1UKCwTt0NcZK9QH/gGA2MdBe/UO5+ eNDj6ivvWUJIgMXAXyKiIjF66T9X5bz3TEk9Sq6VLFk5Zsy9YYpjhyik638yiWFlcCpe jkX7bklfScU5/zCE62Yw2vjL5SM6dhVzpjNI/rS4ZMtlUOijCrE6yOlOY3TRclzjvXvm vACQ== X-Gm-Message-State: AA+aEWZDirTbeagUK3cfGpgwrwIPEbAnnNx/5DuPIVsd7BSeaHd1veDl w7/tUo0f64k6SPGPGJF2/hRXF101IBU= X-Google-Smtp-Source: AFSGD/W8DjmUdwdgRRoDOrFJ9VkhRWr+LeEu7/QsGuK4ssuZSlc0xNomWK3RpWs0vh4/k2/PA3dbQg== X-Received: by 2002:adf:91a3:: with SMTP id 32mr21538544wri.99.1545335106490; Thu, 20 Dec 2018 11:45:06 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:05 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 19/26] stash: make push -q quiet Date: Thu, 20 Dec 2018 21:44:35 +0200 Message-Id: <033e7911bbdca69bd785e04c5645390f5adae984.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 c77f62c895..5f9914ca27 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; @@ -1122,7 +1124,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 { @@ -1147,7 +1151,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; } @@ -1155,26 +1161,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; } @@ -1200,7 +1209,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; } @@ -1235,7 +1246,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)); @@ -1298,26 +1309,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) { @@ -1418,7 +1432,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 98c25a671c..b67d7a1120 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 Dec 20 19:44: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: 10739505 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 8AB39746 for ; Thu, 20 Dec 2018 19:45:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 791A628949 for ; Thu, 20 Dec 2018 19:45:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D947289CC; Thu, 20 Dec 2018 19:45:23 +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 EA5D828949 for ; Thu, 20 Dec 2018 19:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731928AbeLTTpQ (ORCPT ); Thu, 20 Dec 2018 14:45:16 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33229 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389401AbeLTTpJ (ORCPT ); Thu, 20 Dec 2018 14:45:09 -0500 Received: by mail-wm1-f66.google.com with SMTP id r24so12682844wmh.0 for ; Thu, 20 Dec 2018 11:45:08 -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=Nke+nAq5QQPSe/It7C9Y7bmTueWz02m2VjOe5mfUz4Y=; b=J7vM2U8/ncvpu0LHA+tJp+EqsWk9dl8TEadlQXL0ChZYxQm/genlp6r2OjZSiroD1g MACelR2CY157V96girqJIGOLwSFNabH1rw1d9swvs4HH3bgWUAif2jRKcQSqEW3yiX3i 96H378ob8CBKXmNeaHB/vwkeksvAyjUME2S49vcpqxbXnAeBQfvreX0nPG6w5cZX9GNM CbC1PaoEucWsP5z1DgRSc/mY5I4ShyHBxy2eQaV+QU1ryGFmp6qGKIc1zPXcIG6moiZQ ppLGPv6zT+zMv4IbpSnUt9sKqiY/+bDw7GGaXg+AVX4o7xX5/hDmlsAye2WyID6f6b3M C6LQ== 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=Nke+nAq5QQPSe/It7C9Y7bmTueWz02m2VjOe5mfUz4Y=; b=B5qqiPGB0rWWTP+DMkmSZLqoeIlBlTO74cMNck2+rHnDopWUiiiM0j5/+uZk8Wb/TQ 4z1qQpq3jjun3YYNrC1ZZMyFig7tq8meD3CdjkPI9/bo0yneAb7SDe8XfBQ11T8hp2Ak w8hI6iugo+IRIVk+aIjk7e/evRbEr49gvv+Cg4U9a6pYSO5S++B/1cHEVnyJHr0tNwPl ICJoprZyPphF8w2HavpAcdbGay8E+RzuHaWG84wRc180Urp1r9F03vVnlQAxy8Vm6tsg TZuLWsoaYOQHf9Xq6Gv5+vdd9oQM8H/3jGnUzOY+MNsAExBCiY4iCowYET6uTT/HcZWL 3K2A== X-Gm-Message-State: AA+aEWYert1K2iFvVsrd1JPRx24nQVpUqUT28BbIvCY135Mx72B8Ue76 x9mlTXxMe6u9n9eCF0UZXVBV491XeAI= X-Google-Smtp-Source: ALg8bN4QMwAUjcztbyMXlVhlqlUMBv2MShuhkthBQhw7BiVSnTVaunpQHkzhhAgFBmMaxxakRHRtPA== X-Received: by 2002:a1c:f613:: with SMTP id w19mr26843wmc.0.1545335107333; Thu, 20 Dec 2018 11:45:07 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:06 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 20/26] stash: convert save to builtin Date: Thu, 20 Dec 2018 21:44:36 +0200 Message-Id: <1b16cdb63b0d40161bf3b70480ff7177f14fd3bf.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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 | 328 +--------------------------------------- 2 files changed, 52 insertions(+), 326 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 5f9914ca27..19ead63c46 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; @@ -1490,6 +1498,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(); @@ -1530,6 +1578,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 51d7a06601..695f1feba3 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -36,331 +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 -- "$@" -} - -prepare_fallback_ident () { - if ! git -c user.useconfigonly=yes var GIT_COMMITTER_IDENT >/dev/null 2>&1 - then - GIT_AUTHOR_NAME="git stash" - GIT_AUTHOR_EMAIL=git@stash - GIT_COMMITTER_NAME="git stash" - GIT_COMMITTER_EMAIL=git@stash - export GIT_AUTHOR_NAME - export GIT_AUTHOR_EMAIL - export GIT_COMMITTER_NAME - export GIT_COMMITTER_EMAIL - fi -} - -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 () { - - prepare_fallback_ident - - 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} @@ -425,7 +100,8 @@ show) ;; save) shift - save_stash "$@" + cd "$START_DIR" + git stash--helper save "$@" ;; push) shift From patchwork Thu Dec 20 19:44: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: 10739499 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 AF654746 for ; Thu, 20 Dec 2018 19:45:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A069A28949 for ; Thu, 20 Dec 2018 19:45:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9473528999; Thu, 20 Dec 2018 19:45:19 +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 317F328949 for ; Thu, 20 Dec 2018 19:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389498AbeLTTpR (ORCPT ); Thu, 20 Dec 2018 14:45:17 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37436 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389465AbeLTTpL (ORCPT ); Thu, 20 Dec 2018 14:45:11 -0500 Received: by mail-wr1-f67.google.com with SMTP id s12so2982786wrt.4 for ; Thu, 20 Dec 2018 11:45:09 -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=KpJb117B1K2e4z/+lpG/mu2y6lsg2RVSsYgbj/YfSKI=; b=CRKBzSBVxRr/NFPR68CCAiS2FCGB7AXi9Ebb4EF3sFIeLuVmIVra26Omfgz1SYKUUL Prqfq2DlF0qj3aCpAYRCW6Fte5qvA14wiVYuaTIGzBDritZ+Fqk8AqM+H5mK27G+HiI6 WxQQNjUTIqOUecDQLbwxYNCB+RXRxUc/YVoFe8pDXZry5J99yqfSXdmuvvp5MLJ4Mv/z 9US0Rtl5XFNCf/rwC7HhGmUrClMqydrOvAmofihxiPmLpV/VDnA1YOkwqClStfY+lTHc SIBTSwkK8J8TRXjzzzC+EYbnmzqrdkdurphW8/SBpM41+jJNAZNHtE6PpIIkpsIs3ESW Yo9w== 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=KpJb117B1K2e4z/+lpG/mu2y6lsg2RVSsYgbj/YfSKI=; b=CQ5obGQmFYhjeUziR/H2SxLqO/hz6x1sMXh6DK6x+cU1HTAkj0ED9JADg2URtILYKc xpBvBSHo1i2Fd1Lo7kin7QturK5QHsTN/80NiJZfek8g3Pre7pCvDIk+uFLcnzn9ZAXb Fw7vVo1xwxjEPnbYlgqfrpmF4HNWdKxiyNHAj8chiNWj6KvDzc9v7M+7UthRfdjxT5Bh ARL8iD/wtKVR/e1mB59csdeJuJTJb/XHYFuq8lesGhxnVO/oJyUpVhNJtTTRa+i7Lh1S GHKuwdgrzEoQsO/KDvTtzYk7/ArPt/qmWUPwndiLQYQqO1pMYc4WAllnCPGmY9dvg07o wSwA== X-Gm-Message-State: AA+aEWapjGkrzWVPQVfQEsZKxiWCIsSVFfgnMQdSjEGVfqkIQOdQKF23 yzUmvGAi2uchOxsfgYznBtzvVcieuFc= X-Google-Smtp-Source: AFSGD/Va2oQy2jj7QJY9n2jCrMbLb12EPoIZU68htrite3NkSg5Ky11aL9URlR4hEhQydwLUxwjpLQ== X-Received: by 2002:a5d:4586:: with SMTP id p6mr23215857wrq.69.1545335108603; Thu, 20 Dec 2018 11:45:08 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:07 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 21/26] stash: optimize `get_untracked_files()` and `check_changes()` Date: Thu, 20 Dec 2018 21:44:37 +0200 Message-Id: <17f45e4bb48bdf9588d87c7b134afd703dbd69e6.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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--helper.c | 53 +++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 19ead63c46..4b63352927 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -884,18 +884,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)) @@ -923,14 +923,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, @@ -1141,7 +1153,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; } @@ -1166,8 +1178,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 " @@ -1252,20 +1263,15 @@ static int create_stash(int argc, const char **argv, const char *prefix) 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, - NULL, 0); + if (!check_changes_tracked_files(ps)) + return 0; - if (!ret) + strbuf_addstr(&stash_msg_buf, stash_msg); + 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, @@ -1275,6 +1281,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; @@ -1309,7 +1316,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 Dec 20 19:44: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: 10739497 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 DB2986C5 for ; Thu, 20 Dec 2018 19:45:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB63C28949 for ; Thu, 20 Dec 2018 19:45:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFBE328999; Thu, 20 Dec 2018 19:45:18 +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 61A0528949 for ; Thu, 20 Dec 2018 19:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389499AbeLTTpR (ORCPT ); Thu, 20 Dec 2018 14:45:17 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38573 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389475AbeLTTpM (ORCPT ); Thu, 20 Dec 2018 14:45:12 -0500 Received: by mail-wm1-f68.google.com with SMTP id m22so3516507wml.3 for ; Thu, 20 Dec 2018 11:45:10 -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=/6WRbwssI+OW/a9OvjLI98BDK/OlW2q3PXyQdSqCD7M=; b=rpBaNRS+xSUx8jGb6cu6g4L3vs6w78SbVj0RqlEylkqrh6UG41onZ+wzSyGzK//nBU mmsE0EwH6XSGsABANcQ3FDkQJqqaFCoZVeu39sNGA/SReS53kIWQi11mmdZwXF/H7JcR 2QrLNPo0v+GCPoJx+xSlKRK4H/4pdg1aFOexNoYrtRnPUVXupeD6i2rj0z3fQ4hX43iJ aMyUCuxL9zNEttmEoATSpLfqdRUUjpESLT4JS11BdbuaxVLt5zaXr/66jqCLEqWK91fF xDkqDZZJcUgFq56/ORcRQRy+WbQgm5DSJHw9sZ0WKEDB8Tt2woIKt3hrLVOnTYgS3npN X+Sw== 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=/6WRbwssI+OW/a9OvjLI98BDK/OlW2q3PXyQdSqCD7M=; b=uMWDYF+FBQw20ezdlfpsnmsV6Qvc2YBpAbhYth0x0rEStCMgZfQD8lDCw4v0zWy5oK 6Lhu0d1SZxw+BcBi/St9vUStPqS+EQ+U/kyKrA9HrziHkujiSBI+1INwVKLPKuj51lDb 7KyJVH8HDZM3JgstIVnYAKkchsIieFbMRKYVLMPXt8wy90JgjvLmO+lmStVNOj07cP8i 8uZXmTjO8rStvW4QjxZt/+pPUvgGLx90iR3ywdCOAqrylbH967SkbugPCzlq8FIMa/jy IPUykYMUXTaTweuvx2PqDAoJ0ZJBCLU7WjaebScWFtebSIJwqx6J8LavAOcPy5mN1+IT 8clQ== X-Gm-Message-State: AA+aEWbi4als2XZshXUabsE6m8ztSBYzAfLKtHHmuWcBKnHGn4ZkBMbb p6/RjzTCMIqTLHl+TCvul2MDZVIYaQo= X-Google-Smtp-Source: AFSGD/VWJBMcWTlhjmJyHzNtxjZ6Rk8m8Ya7A96Vbp+sWAOlO2fTLH8MyQa5jfUEsgNAEaYPtBXMOg== X-Received: by 2002:a7b:c5d1:: with SMTP id n17mr2535wmk.152.1545335109510; Thu, 20 Dec 2018 11:45:09 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:09 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 22/26] stash: replace all `write-tree` child processes with API calls Date: Thu, 20 Dec 2018 21:44:38 +0200 Message-Id: <73eac729193a64fe6ce5f2e38b73362263631b5b.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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--helper.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c index 4b63352927..39fcff32b7 100644 --- a/builtin/stash--helper.c +++ b/builtin/stash--helper.c @@ -950,9 +950,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", @@ -967,15 +966,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)) { @@ -984,8 +979,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; } @@ -994,11 +989,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); @@ -1024,17 +1018,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); @@ -1050,7 +1039,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; } @@ -1060,9 +1049,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)) { @@ -1101,20 +1089,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); From patchwork Thu Dec 20 19:44: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: 10739511 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 B109C6C5 for ; Thu, 20 Dec 2018 19:45:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A065728949 for ; Thu, 20 Dec 2018 19:45:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91DF628A0E; Thu, 20 Dec 2018 19:45: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 D10B128949 for ; Thu, 20 Dec 2018 19:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389504AbeLTTpY (ORCPT ); Thu, 20 Dec 2018 14:45:24 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35843 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389489AbeLTTpO (ORCPT ); Thu, 20 Dec 2018 14:45:14 -0500 Received: by mail-wr1-f66.google.com with SMTP id u4so2985870wrp.3 for ; Thu, 20 Dec 2018 11:45:11 -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=s+vYJTBBsL/3j1u7TscbYY7ltzR/Vwdr3yyklg0Kz38=; b=p0UcvVCBrlEVUKdjpzvrjvTObGKzRFuYjQTVzjJnEA1C4vjicdeggaX+B4srzIKGN+ TD2yJn6vWf4JwZMNfSgHGVdvJXPi46j/7Yum0TUS31fV5SacjqvJL1QBEXAUeFiaiGaR 9BeLHbz64hw6TvHDZs/4WJlIFmfV9XvvWy2jMFGgs6AWiiJT4W5hy//JpG51hw32hBbd U5tEKAOMCZI2NB3fFQfKQvBnOseB04s8jcriB5y36kW2PpYcxUU05DuH8vRsfyxzhrM3 40EdyGwQLCHW7xXbpP4hrpUgalIvDIflZ6zW7CH3ArB3XcHgFmbanzX3kQxYcq0Jciou QGHw== 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=s+vYJTBBsL/3j1u7TscbYY7ltzR/Vwdr3yyklg0Kz38=; b=uiYCGrfQ7/sv0fzoZ1CNMb44CdXb09sPryGZO5Zkz/eemf6vTkxspZ2H0yyL5DBPuR vvNxwU70DpsgprNPt5KhxhUroAmv1ZbNw1y/H6tG35bdxv5TKUTqdjCW1CRmb+nDyRYj SLXGOqyHFYCKLmBRwBenL1e2NixeIhPATKZbRZJTLf3Fow+HSE+Sq0v91/en7MzMVgkw Ynr/kEy9klwVxOpV7fj3WsgSye6u1VmjAYU9yvmB1zDvnHZYwk24Fn9AA5q6vJ8QsN91 T1sqY1B1Y6ZdN8TGAAQqV388YlvF6nAxwNQqP2yI1ZgSl1Bmwi9Z7/HV7HhlZUqLubB3 sdwQ== X-Gm-Message-State: AA+aEWYrA7MrPCd3on2s7xhPSFn+O7SbgKMEB6VWJiFePo61kVVa0LSJ YUw9uRkTYjgbxsgk3T8Nqk48KU9txbU= X-Google-Smtp-Source: AFSGD/VbqhcejWkfPZMNpsQf7MqYRoNDs2RZFgv+N+b2MhAyCqFf02QxaT/lMu5BaYekFhav9DZTYQ== X-Received: by 2002:adf:d1d2:: with SMTP id m18mr24851215wri.138.1545335110622; Thu, 20 Dec 2018 11:45:10 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:10 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 23/26] stash: convert `stash--helper.c` into `stash.c` Date: Thu, 20 Dec 2018 21:44:39 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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} | 154 +++++++++++++++------------ git-stash.sh | 153 -------------------------- git.c | 2 +- 6 files changed, 91 insertions(+), 224 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 c246fc7078..8cee2731aa 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 @@ -1117,7 +1116,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 39fcff32b7..fe32ff42fd 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) { @@ -1227,29 +1222,18 @@ 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)); if (!check_changes_tracked_files(ps)) return 0; - strbuf_addstr(&stash_msg_buf, stash_msg); if (!(ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info, NULL, 0))) printf_ln("%s", oid_to_hex(&info.w_commit)); @@ -1479,9 +1463,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, @@ -1514,7 +1499,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) @@ -1528,10 +1513,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() @@ -1539,16 +1526,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); @@ -1570,7 +1557,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 de9c774573..8a20909eae 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 Dec 20 19:44: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: 10739503 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 08BAC6C5 for ; Thu, 20 Dec 2018 19:45:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA26028949 for ; Thu, 20 Dec 2018 19:45:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDA5928999; Thu, 20 Dec 2018 19:45:21 +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 3A6A828949 for ; Thu, 20 Dec 2018 19:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389502AbeLTTpU (ORCPT ); Thu, 20 Dec 2018 14:45:20 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43631 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389491AbeLTTpP (ORCPT ); Thu, 20 Dec 2018 14:45:15 -0500 Received: by mail-wr1-f66.google.com with SMTP id r10so2967675wrs.10 for ; Thu, 20 Dec 2018 11:45:12 -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=TjmbJehfLIHyLgJYA35b9n8bK74FJ/2DR6M0h3Ep400=; b=J9l4rHuI0oXxWDkInz9EzN8gEBjvigHSzigNVgeCzMUEDZhZ6LiAP3DurPvGT/evgb opuK9ex/yUA/e86LPB7sExdCsL5qChOG7CiTd3mgo+8VJHqK9FqFkdKA9W9zc2nXiNZE OpYuf95j3sVVdE+WepybVhCw2AQpLm4VsllHIGIXJdODASivAfSFvYlBcq7Y+K+qTB61 QHKKcHjQfSNIxwcpfAiqfugzp7Jxv2Ao60tkANfAAGKYqZlDSYkOLAjQNtF2LKZ8Ecnr 8H7GN4qjHlMZC6DxL9PdcGiLPMae5pIi9QZUZG91CgqP4mkqhbxe0vC3j3eh6wlmOzyA 2tiA== 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=TjmbJehfLIHyLgJYA35b9n8bK74FJ/2DR6M0h3Ep400=; b=ObUdxqZBcSUojgoaoZB5UM6K1WxMX1h0cCe1W/hP8ns3ciRrzEKqlp5pQNMwn9+G5e 16iEH9sOcKJKAwpb/xjuWPRrukPhOYwoj2JZpfrY0knFGuLuPfsJtou5tG363n+R1FVS Tdk0UMWQe4LI+6mcHvOKXdkQ0kPlX0HlICYmLSaN6HBFz6pLfzfUNh6Zx24ICU6ovbkn 4UXfB+R2pew/m4jyEbRtHgzFiwDOiRzLbyQqvcXlzh82sTqlFHdgntskgSZsUsWOv/om XiD6/LxLH46u3JQpiS/FmAMJE3c7LbqiI29E+U4Ej72GCIo5Nwp1UejsihRvn4+d4vAb oMyw== X-Gm-Message-State: AA+aEWYkxADOyWLPscli6w3YWjT554C6yaPvWV36UwyFJAnipsT+kb5Q mp1JS8jDPaCPuCA1L6IhR2nZnVJPiWo= X-Google-Smtp-Source: AFSGD/VYbpjJnsUgxgZs6SckMDJuTFWG0vfpTaLkMri/p8AKXmdXj/aYneKITdcKT0ZoKLub1wr0Hw== X-Received: by 2002:adf:f807:: with SMTP id s7mr25627794wrp.173.1545335111807; Thu, 20 Dec 2018 11:45:11 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:11 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 24/26] stash: add back the original, scripted `git stash` Date: Thu, 20 Dec 2018 21:44:40 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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: Johannes Schindelin This simply copies the version as of sd/stash-wo-user-name verbatim. As of now, it is not hooked up. The next commit will change the builtin `stash` to hand off to the scripted `git stash` when `stash.useBuiltin=false`. Signed-off-by: Johannes Schindelin --- git-stash.sh | 769 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 769 insertions(+) create mode 100755 git-stash.sh diff --git a/git-stash.sh b/git-stash.sh new file mode 100755 index 0000000000..789ce2f41d --- /dev/null +++ b/git-stash.sh @@ -0,0 +1,769 @@ +#!/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 + +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 -- "$@" +} + +prepare_fallback_ident () { + if ! git -c user.useconfigonly=yes var GIT_COMMITTER_IDENT >/dev/null 2>&1 + then + GIT_AUTHOR_NAME="git stash" + GIT_AUTHOR_EMAIL=git@stash + GIT_COMMITTER_NAME="git stash" + GIT_COMMITTER_EMAIL=git@stash + export GIT_AUTHOR_NAME + export GIT_AUTHOR_EMAIL + export GIT_COMMITTER_NAME + export GIT_COMMITTER_EMAIL + fi +} + +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 () { + + prepare_fallback_ident + + 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")" +} + +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= + 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" -- "$@" + store_stash -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 +} + +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 "$@" + + 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 +} + +# +# 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" +# + +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")" + } +} + +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 () { + + 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 +} + +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 +} + +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' +# 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 + list_stash "$@" + ;; +show) + shift + show_stash "$@" + ;; +save) + shift + save_stash "$@" + ;; +push) + shift + push_stash "$@" + ;; +apply) + shift + apply_stash "$@" + ;; +clear) + shift + clear_stash "$@" + ;; +create) + shift + create_stash -m "$*" && echo "$w_commit" + ;; +store) + shift + store_stash "$@" + ;; +drop) + shift + drop_stash "$@" + ;; +pop) + shift + pop_stash "$@" + ;; +branch) + shift + apply_to_branch "$@" + ;; +*) + case $# in + 0) + push_stash && + say "$(gettext "(To restore them type \"git stash apply\")")" + ;; + *) + usage + esac + ;; +esac From patchwork Thu Dec 20 19:44: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: 10739509 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 8D0826C5 for ; Thu, 20 Dec 2018 19:45:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BC5128949 for ; Thu, 20 Dec 2018 19:45:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70535289CC; Thu, 20 Dec 2018 19:45:26 +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 08C4228949 for ; Thu, 20 Dec 2018 19:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389509AbeLTTpY (ORCPT ); Thu, 20 Dec 2018 14:45:24 -0500 Received: from mail-wr1-f47.google.com ([209.85.221.47]:39000 "EHLO mail-wr1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389493AbeLTTpO (ORCPT ); Thu, 20 Dec 2018 14:45:14 -0500 Received: by mail-wr1-f47.google.com with SMTP id t27so2980102wra.6 for ; Thu, 20 Dec 2018 11:45: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=3XMjaE3CL0jfklZ2FToojJDguSHp8O+KmwDd0a6+4ak=; b=PuzC9ixEqpCuh2vedTiEyw3D8WIS3WpPpYltW3X9MPzaEzVlH1YavjE3jGs7firAah +JwFZS/CNuTOUH+A8VLSirx/twHEonLtpaq3J30jha3AfYrnviTyArJZYcHRBqkEE2ww drQohFcLvEJPHqjreYpleOuGz/itM2b1JZ6EBFKlCiTpEPe8ZT0WnwfTDi6Jt23EiTMg dTR6hPxmCuTmD+pZay34ogeWdPe6Dr0Qvq0V6+hQmaV21snoFu0+ip10QXcjIZ8Q3Cgv RBkCtL1FqYWpYrgO+TRQzm5KVqHVC72lLrQ6BMQc8NHDN3R++kpyA1OxBQNUrM2Y6AY6 oqGA== 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=3XMjaE3CL0jfklZ2FToojJDguSHp8O+KmwDd0a6+4ak=; b=JaezntZUOUYkanbKVAJ1eDwuUmOB2N7fib1qIaviYlGX0iNq2imnPCM4gx/IwaWici PdMNziTpfBariuiZe5xsO4RRH2pCnwZBK0HPsqpOKnc6lqNZBNRz83uywTb2Xla+NHf8 ZfkK+tLMV/LyJkrEnVsVXgXO0Iw9bjT4SvZbxcm5oCgC2Bj1taZOT4/rQ+6YG1y7mFCo Ft1QiB3+2gu2U+gxCggijYow4NeDwMOmj0iK+pTKBQWNQXHc2qU9dl5vzLfysVbooqQC hH596nWuHzJ37qX3F8LaS4mYUjV+ykn1K9tz8w1br/lX9Fb9Uau/QmUP9VkYtJVxXLcP ibnw== X-Gm-Message-State: AA+aEWaFtoz9gbNtccWJMeamujzG20aIARDjN6w5N7FB5vajHZP0AoGE sn+VUclFb/atj9sqoPPI1fJUkpEawwU= X-Google-Smtp-Source: AFSGD/UrW8q6bJ+jndczMJDP3TZYR+w0OZaOj18wm1laFgJKaZBDNq9RESKEO/J8tm3frZMAM0hbfw== X-Received: by 2002:adf:e64d:: with SMTP id b13mr24616062wrn.276.1545335112907; Thu, 20 Dec 2018 11:45:12 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:12 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 25/26] stash: optionally use the scripted version again Date: Thu, 20 Dec 2018 21:44:41 +0200 Message-Id: X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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: Johannes Schindelin We recently converted the `git stash` command from Unix shell scripts to builtins. Let's end users a way out when they discover a bug in the builtin command: `stash.useBuiltin`. As the file name `git-stash` is already in use, let's rename the scripted backend to `git-legacy-stash`. To make the test suite pass with `stash.useBuiltin=false`, this commit also backports rudimentary support for `-q` (but only *just* enough to appease the test suite), and adds a super-ugly hack to force exit code 129 for `git stash -h`. Signed-off-by: Johannes Schindelin --- .gitignore | 1 + Makefile | 1 + builtin/stash.c | 35 +++++++++++++++++++++++++++++ git-stash.sh => git-legacy-stash.sh | 34 +++++++++++++++++++++++++--- git-sh-setup.sh | 1 + git.c | 7 +++++- 6 files changed, 75 insertions(+), 4 deletions(-) rename git-stash.sh => git-legacy-stash.sh (97%) diff --git a/.gitignore b/.gitignore index 0d77ea5894..7b0164675e 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ /git-interpret-trailers /git-instaweb /git-legacy-rebase +/git-legacy-stash /git-log /git-ls-files /git-ls-remote diff --git a/Makefile b/Makefile index 8cee2731aa..810231a0b5 100644 --- a/Makefile +++ b/Makefile @@ -617,6 +617,7 @@ SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-legacy-rebase.sh +SCRIPT_SH += git-legacy-stash.sh SCRIPT_SH += git-remote-testgit.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-submodule.sh diff --git a/builtin/stash.c b/builtin/stash.c index fe32ff42fd..346c9d2bb1 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -13,6 +13,7 @@ #include "revision.h" #include "log-tree.h" #include "diffcore.h" +#include "exec-cmd.h" #define INCLUDE_ALL_FILES 2 @@ -1513,6 +1514,26 @@ static int save_stash(int argc, const char **argv, const char *prefix) return ret; } +static int use_builtin_stash(void) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + int ret; + + argv_array_pushl(&cp.args, + "config", "--bool", "stash.usebuiltin", NULL); + cp.git_cmd = 1; + if (capture_command(&cp, &out, 6)) { + strbuf_release(&out); + return 1; + } + + strbuf_trim(&out); + ret = !strcmp("true", out.buf); + strbuf_release(&out); + return ret; +} + int cmd_stash(int argc, const char **argv, const char *prefix) { int i = -1; @@ -1524,6 +1545,20 @@ int cmd_stash(int argc, const char **argv, const char *prefix) OPT_END() }; + if (!use_builtin_stash()) { + const char *path = mkpath("%s/git-legacy-stash", + git_exec_path()); + + if (sane_execvp(path, (char **)argv) < 0) + die_errno(_("could not exec %s"), path); + else + BUG("sane_execvp() returned???"); + } + + prefix = setup_git_directory(); + trace_repo_setup(prefix); + setup_work_tree(); + git_config(git_diff_basic_config, NULL); argc = parse_options(argc, argv, prefix, options, git_stash_usage, diff --git a/git-stash.sh b/git-legacy-stash.sh similarity index 97% rename from git-stash.sh rename to git-legacy-stash.sh index 789ce2f41d..8a8c4a9270 100755 --- a/git-stash.sh +++ b/git-legacy-stash.sh @@ -80,6 +80,28 @@ clear_stash () { fi } +maybe_quiet () { + case "$1" in + --keep-stdout) + shift + if test -n "$GIT_QUIET" + then + eval "$@" 2>/dev/null + else + eval "$@" + fi + ;; + *) + if test -n "$GIT_QUIET" + then + eval "$@" >/dev/null 2>&1 + else + eval "$@" + fi + ;; + esac +} + create_stash () { prepare_fallback_ident @@ -112,15 +134,18 @@ create_stash () { done git update-index -q --refresh - if no_changes "$@" + if maybe_quiet no_changes "$@" then exit 0 fi # state of the base commit - if b_commit=$(git rev-parse --verify HEAD) + if b_commit=$(maybe_quiet --keep-stdout git rev-parse --verify HEAD) then head=$(git rev-list --oneline -n 1 HEAD --) + elif test -n "$GIT_QUIET" + then + exit 1 else die "$(gettext "You do not have the initial commit yet")" fi @@ -315,7 +340,7 @@ push_stash () { test -n "$untracked" || git ls-files --error-unmatch -- "$@" >/dev/null || exit 1 git update-index -q --refresh - if no_changes "$@" + if maybe_quiet no_changes "$@" then say "$(gettext "No local changes to save")" exit 0 @@ -370,6 +395,9 @@ save_stash () { while test $# != 0 do case "$1" in + -q|--quiet) + GIT_QUIET=t + ;; --) shift break diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 378928518b..10d9764185 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -101,6 +101,7 @@ $LONG_USAGE")" case "$1" in -h) echo "$LONG_USAGE" + case "$0" in *git-legacy-stash) exit 129;; esac exit esac fi diff --git a/git.c b/git.c index 8a20909eae..591ebe9409 100644 --- a/git.c +++ b/git.c @@ -554,7 +554,12 @@ 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", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, + /* + * NEEDSWORK: Until the builtin stash is thoroughly robust and no + * longer needs redirection to the stash shell script this is kept as + * is, then should be changed to RUN_SETUP | NEED_WORK_TREE + */ + { "stash", cmd_stash }, { "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 Dec 20 19:44: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: 10739501 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 86749746 for ; Thu, 20 Dec 2018 19:45:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7660D28949 for ; Thu, 20 Dec 2018 19:45:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7F628999; Thu, 20 Dec 2018 19:45:20 +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 2623D28949 for ; Thu, 20 Dec 2018 19:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389500AbeLTTpS (ORCPT ); Thu, 20 Dec 2018 14:45:18 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38162 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389495AbeLTTpP (ORCPT ); Thu, 20 Dec 2018 14:45:15 -0500 Received: by mail-wr1-f67.google.com with SMTP id v13so2979656wrw.5 for ; Thu, 20 Dec 2018 11:45: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=zIpjZfHhkkC3bAiUe4fvBhidMZv/DInGoWy6dimZZ94=; b=XCZsWNd8WORA9YYK8yuNmB7pPXlbW8WHgG0E1BpxtrLUo6MLyTlyFM56R0l+rFZia+ C6jbX8NNdW3Yjez+7kWpfg7IFFf1Oz3RPXj0KXga9v2jPdY0sA1XLAlIZsAkhbqIsPrp lBvNk17ImXcxya9FAOr1ZmPjBoVgkEGP1rZqmPm7jXQl3wwsJn6tVf1iyjoWXRf4hoyb X9A6eJWJBmNuoym818FACrlsRGbynxD+fSFSwD+hvJHCGvzCiFfF1BtL9TuyvI8fvNDD jq1JR6kabZSX41Zq0d9EjD4OGIlqti5pDn9SQ8auOYxhd5ve1/lDLiICRDedf7GTTzYJ +FvA== 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=zIpjZfHhkkC3bAiUe4fvBhidMZv/DInGoWy6dimZZ94=; b=q6IAx62SGCZ/Ien+SPXOgj86kUSBrVYYCg/LnRtgv4omnrMDg4zjI+9jV2bfaK/3EH iHImRfge1d/2CI+ta+CV0L3rbqQvjcGijNVVrWkxCvBPC+lYaqbymWWBBDFD/1yuBaEf zJmlvfayxTc7XvvS3L0wigIov3HWHGDOq5xvrxvxeSkStQ9blX2lT5NsNhz1s4JI99OM nP2O3/7bPXm9HpRMcD7nDDDZm5sAzJizljA7x/ICyZqY2IXErRkGZuiK5rwMy9SnIQ4t T9yTMLB+6oRq/E+Cd7sejokYlIow0R1AA9c/8Cbs+/O2ln+HyhBA1bnoF35v3orvAk2T BaIQ== X-Gm-Message-State: AA+aEWazPhsop1nz0zV1erPuBEyrNIMNCsgYIlnBAyoq5vtq77zGe5zA +VpLUVyL19jwrpUGs89HFuWN/3pRI4A= X-Google-Smtp-Source: AFSGD/VsXm7BNTBfxPNSa9Y5zgAaJ369GhljXzSmXao+K/T3fO0qTojXzqgZdCUXIIaEwYudeMrIZw== X-Received: by 2002:adf:eec9:: with SMTP id a9mr23087653wrp.242.1545335113808; Thu, 20 Dec 2018 11:45:13 -0800 (PST) Received: from sebi-laptop.tendawifi.com ([188.24.227.76]) by smtp.gmail.com with ESMTPSA id j129sm7587267wmb.39.2018.12.20.11.45.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 11:45:13 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com, Johannes.Schindelin@gmx.de Subject: [PATCH v12 26/26] tests: add a special setup where stash.useBuiltin is off Date: Thu, 20 Dec 2018 21:44:42 +0200 Message-Id: <764a526393ca8ae76394aecc8a87d66abb80c1b4.1545331726.git.ungureanupaulsebastian@gmail.com> X-Mailer: git-send-email 2.20.1.336.g43b67505b2.dirty 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: Johannes Schindelin Add a GIT_TEST_STASH_USE_BUILTIN=false test mode which is equivalent to running with stash.useBuiltin=false. This is needed to spot that we're not introducing any regressions in the legacy stash version while we're carrying both it and the new built-in version. This imitates the equivalent treatment for the built-in rebase in 62c23938fae5 (tests: add a special setup where rebase.useBuiltin is off, 2018-11-14). Signed-off-by: Johannes Schindelin --- builtin/stash.c | 5 ++++- t/README | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/stash.c b/builtin/stash.c index 346c9d2bb1..3ee8a41cda 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1518,7 +1518,10 @@ static int use_builtin_stash(void) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf out = STRBUF_INIT; - int ret; + int ret, env = git_env_bool("GIT_TEST_STASH_USE_BUILTIN", -1); + + if (env != -1) + return env; argv_array_pushl(&cp.args, "config", "--bool", "stash.usebuiltin", NULL); diff --git a/t/README b/t/README index 28711cc508..9187eeea8e 100644 --- a/t/README +++ b/t/README @@ -349,6 +349,10 @@ GIT_TEST_REBASE_USE_BUILTIN=, when false, disables the builtin version of git-rebase. See 'rebase.useBuiltin' in git-config(1). +GIT_TEST_STASH_USE_BUILTIN=, when false, disables the +built-in version of git-stash. See 'stash.useBuiltin' in +git-config(1). + GIT_TEST_INDEX_THREADS= enables exercising the multi-threaded loading of the index for the whole test suite by bypassing the default number of cache entries and thread minimums. Setting this to 1 will make the