From patchwork Tue Oct 30 10:39:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10660649 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 01D981734 for ; Tue, 30 Oct 2018 10:39:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E219929EEA for ; Tue, 30 Oct 2018 10:39:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D63B029F14; Tue, 30 Oct 2018 10:39:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 11C5B29F11 for ; Tue, 30 Oct 2018 10:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727534AbeJ3TcV (ORCPT ); Tue, 30 Oct 2018 15:32:21 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:15529 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727377AbeJ3TcV (ORCPT ); Tue, 30 Oct 2018 15:32:21 -0400 Received: from lindisfarne.localdomain ([92.22.32.73]) by smtp.talktalk.net with SMTP id HRQbg5GIzdJAeHRQigS6Mk; Tue, 30 Oct 2018 10:39:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1540895964; bh=yiV+rGxaQqQbbgXMjd/he6CGkjrVB2KKXu+hBZOTu2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=RjjKPmFosJkMo9hOOfprqL9z1yCnE9ILhH+rhmEi9v0R5fj8A93i21oaTLHSm42jp UYAD3xZJBdylu+k62GZDd3NCS7ESv4FJW5PwgPovEvIhG5nXqbQZRx1L8lzwKlrG2+ MKec7eFGKLGQ8ujR2OkYWuuII/5DHfJ96B/hvwCI= X-Originating-IP: [92.22.32.73] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=w3K0eKD2tyZHkEydg3BQCA==:117 a=w3K0eKD2tyZHkEydg3BQCA==:17 a=evINK-nbAAAA:8 a=BCjA09oAAAAA:8 a=1ulBX1ryXkBVU36sZhAA:9 a=Z5tHxQ38kdD2Mam8:21 a=iSUq80Ko9vD66vLc:21 a=RfR_gqz1fSpA9VikTjo0:22 a=jYKBPJSq9nmHKCndOPe9:22 From: Phillip Wood To: Git Mailing List , Junio C Hamano Cc: Eric Sunshine , Johannes Schindelin , Phillip Wood Subject: [PATCH v3 1/5] am: don't die in read_author_script() Date: Tue, 30 Oct 2018 10:39:12 +0000 Message-Id: <20181030103916.6241-2-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030103916.6241-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> <20181030103916.6241-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfD1SEs9fZRSNd3MMjvb4kHEOB80kfXmcb5XgEPx0rAwdbdniLTHdJd6EpUwLqmHPbX7svp+4NBmdu6JZtaQAyrA1lsWMRqD3DjtrFxL8U6cAao5190wY CW739GCRfB7lh37SWzwNbx6owiG8H2/7YcgRcrYHMiJxYx3j8eqzVtwWulF5NfDteyIjFuITx7JLqeFey1Q//vTEvaMDv6z85N7dyutBGT9u2HdYMUgBOlQ7 n64sIufT001iL+nEeP60mTJlCSYCXKLl6WTx1pTRx/xk3jDr38BCtzZ/gPv8DHAq3vXREyp82n5MqzE5e7WyMHafp1u5BBwlaavJhD7ik40= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood The caller is already prepared to handle errors returned from this function so there is no need for it to die if it cannot read the file. Suggested-by: Eric Sunshine Signed-off-by: Phillip Wood --- builtin/am.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/am.c b/builtin/am.c index 5e866d17c7..b68578bc3f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -318,7 +318,8 @@ static int read_author_script(struct am_state *state) if (fd < 0) { if (errno == ENOENT) return 0; - die_errno(_("could not open '%s' for reading"), filename); + return error_errno(_("could not open '%s' for reading"), + filename); } strbuf_read(&buf, fd, 0); close(fd); From patchwork Tue Oct 30 10:39:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10660645 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 A93831751 for ; Tue, 30 Oct 2018 10:39:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9210E29EEA for ; Tue, 30 Oct 2018 10:39:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85AFC29F17; Tue, 30 Oct 2018 10:39:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 9178829F14 for ; Tue, 30 Oct 2018 10:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727552AbeJ3TcW (ORCPT ); Tue, 30 Oct 2018 15:32:22 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:23638 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727381AbeJ3TcW (ORCPT ); Tue, 30 Oct 2018 15:32:22 -0400 Received: from lindisfarne.localdomain ([92.22.32.73]) by smtp.talktalk.net with SMTP id HRQbg5GIzdJAeHRQigS6Mq; Tue, 30 Oct 2018 10:39:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1540895965; bh=GFM0le2VaUxvWRXa/+KKZSk+sDezPdECjdnshG0Pqgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=XPp5QNJL7MSwF9s9qwxONN0Vwi6LgcLmLoH4I8l9I5QAunWL+MsMj5hKCFCGDm0iy KJYk3FgQ44+abFqTfdZPn6ypj4SHL6DZhQw3HUrhPaDGvWjr8rP2xhbyuTpx12v6aP 7ImoHFlvUQJu776oT9Fw83KkET8QNumwU/uselOo= X-Originating-IP: [92.22.32.73] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=w3K0eKD2tyZHkEydg3BQCA==:117 a=w3K0eKD2tyZHkEydg3BQCA==:17 a=evINK-nbAAAA:8 a=Ci-q4SUaBBSLNT-odzMA:9 a=f3lRf5HHv4U0SPG5:21 a=5JVnrwbNiQWVHTK8:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Git Mailing List , Junio C Hamano Cc: Eric Sunshine , Johannes Schindelin , Phillip Wood Subject: [PATCH v3 2/5] am: improve author-script error reporting Date: Tue, 30 Oct 2018 10:39:13 +0000 Message-Id: <20181030103916.6241-3-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030103916.6241-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> <20181030103916.6241-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfCWbeC7Y5QWISaNlSVo2M+qNSfkTjm9kRP7V/5SvTaiqgu/vY9LXDWBcS59uv2NYw0PoZnA1RNPghBj1yg4u/jJcnDQffHLXJsb7jy57NZ/UFDHIZFl3 S+RIjQOuxCE130CeDrJPilfV4LbNVsJKdbSckn5s1UtYlPwmOjKya3gL166cKN+lzk3xe8awZIvCnWKeMhLSAXgUbhOASnlV9Fn+mcqeb/mLKKE9QWMsY3k4 vAkamf87lrnP8DabyCJbkI9gO7RDVOzNF7XNhDxZy6lN+ASHJ6ySblrBarxDTHM6ciN4/gzXxXxDDSVL2N4G8tLeoFNmUFb46R02Gezq+Ek= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood If there are errors in a user edited author-script there was no indication of what was wrong. This commit adds some specific error messages depending on the problem. It also relaxes the requirement that the variables appear in a specific order in the file to match the behavior of 'rebase --interactive'. Signed-off-by: Phillip Wood --- builtin/am.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index b68578bc3f..d42b725273 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -270,8 +270,11 @@ static int parse_key_value_squoted(char *buf, struct string_list *list) struct string_list_item *item; char *np; char *cp = strchr(buf, '='); - if (!cp) - return -1; + if (!cp) { + np = strchrnul(buf, '\n'); + return error(_("unable to parse '%.*s'"), + (int) (np - buf), buf); + } np = strchrnul(cp, '\n'); *cp++ = '\0'; item = string_list_append(list, buf); @@ -280,7 +283,8 @@ static int parse_key_value_squoted(char *buf, struct string_list *list) *np = '\0'; cp = sq_dequote(cp); if (!cp) - return -1; + return error(_("unable to dequote value of '%s'"), + item->string); item->util = xstrdup(cp); } return 0; @@ -308,6 +312,7 @@ static int read_author_script(struct am_state *state) struct strbuf buf = STRBUF_INIT; struct string_list kv = STRING_LIST_INIT_DUP; int retval = -1; /* assume failure */ + int i, name_i = -2, email_i = -2, date_i = -2, err = 0; int fd; assert(!state->author_name); @@ -326,14 +331,38 @@ static int read_author_script(struct am_state *state) if (parse_key_value_squoted(buf.buf, &kv)) goto finish; - if (kv.nr != 3 || - strcmp(kv.items[0].string, "GIT_AUTHOR_NAME") || - strcmp(kv.items[1].string, "GIT_AUTHOR_EMAIL") || - strcmp(kv.items[2].string, "GIT_AUTHOR_DATE")) + for (i = 0; i < kv.nr; i++) { + if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) { + if (name_i >= 0) + name_i = error(_("'GIT_AUTHOR_NAME' already given")); + else + name_i = i; + } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) { + if (email_i >= 0) + email_i = error(_("'GIT_AUTHOR_EMAIL' already given")); + else + email_i = i; + } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) { + if (date_i >= 0) + date_i = error(_("'GIT_AUTHOR_DATE' already given")); + else + date_i = i; + } else { + err = error(_("unknown variable '%s'"), + kv.items[i].string); + } + } + if (name_i == -2) + error(_("missing 'GIT_AUTHOR_NAME'")); + if (email_i == -2) + error(_("missing 'GIT_AUTHOR_EMAIL'")); + if (date_i == -2) + error(_("missing 'GIT_AUTHOR_DATE'")); + if (date_i < 0 || email_i < 0 || date_i < 0 || err) goto finish; - state->author_name = kv.items[0].util; - state->author_email = kv.items[1].util; - state->author_date = kv.items[2].util; + state->author_name = kv.items[name_i].util; + state->author_email = kv.items[email_i].util; + state->author_date = kv.items[date_i].util; retval = 0; finish: string_list_clear(&kv, !!retval); From patchwork Tue Oct 30 10:39:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10660655 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 5C1A515E9 for ; Tue, 30 Oct 2018 10:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4765629F17 for ; Tue, 30 Oct 2018 10:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B5FD29F3E; Tue, 30 Oct 2018 10:39:33 +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,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 D2F1E29F2A for ; Tue, 30 Oct 2018 10:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbeJ3Tc0 (ORCPT ); Tue, 30 Oct 2018 15:32:26 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:51848 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727484AbeJ3TcW (ORCPT ); Tue, 30 Oct 2018 15:32:22 -0400 Received: from lindisfarne.localdomain ([92.22.32.73]) by smtp.talktalk.net with SMTP id HRQbg5GIzdJAeHRQjgS6Mv; Tue, 30 Oct 2018 10:39:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1540895965; bh=V98OIZ9/wcZEy6Q93qylF+8qhLCcXXMbKsMwFt8Ajes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=NLX898JTllOUaRuQglkPE/3a2uw//jVNUZqvZeTMhvLW4ki0Nc8l6chbcp0fQ9Goo RtX8M6qySIHXEo6boU7KsKzRs6QKxEQS5npJ4NA4+Dg69ys81mfBJyy4NrsgRQt1XV Uiqsgii6YRz15Y4U8yhrKXHiTGZw7PI7TNwMFTBU= X-Originating-IP: [92.22.32.73] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=w3K0eKD2tyZHkEydg3BQCA==:117 a=w3K0eKD2tyZHkEydg3BQCA==:17 a=evINK-nbAAAA:8 a=jAbL0x3HlbHIGo4u6YsA:9 a=2pq0VG0WY9_6zSxb:21 a=q43gRipxSBSK2way:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Git Mailing List , Junio C Hamano Cc: Eric Sunshine , Johannes Schindelin , Phillip Wood Subject: [PATCH v3 3/5] am: rename read_author_script() Date: Tue, 30 Oct 2018 10:39:14 +0000 Message-Id: <20181030103916.6241-4-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030103916.6241-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> <20181030103916.6241-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfCWbeC7Y5QWISaNlSVo2M+qNSfkTjm9kRP7V/5SvTaiqgu/vY9LXDWBcS59uv2NYw0PoZnA1RNPghBj1yg4u/jJcnDQffHLXJsb7jy57NZ/UFDHIZFl3 S+RIjQOuxCE130CeDrJPilfV4LbNVsJKdbSckn5s1UtYlPwmOjKya3gL166cKN+lzk3xe8awZIvCnWKeMhLSAXgUbhOASnlV9Fn+mcqeb/mLKKE9QWMsY3k4 vAkamf87lrnP8DabyCJbkI9gO7RDVOzNF7XNhDxZy6lN+ASHJ6ySblrBarxDTHM6ciN4/gzXxXxDDSVL2N4G8tLeoFNmUFb46R02Gezq+Ek= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Rename read_author_script() in preparation for adding a shared read_author_script() function to libgit. Signed-off-by: Phillip Wood --- builtin/am.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index d42b725273..991d13f9a2 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -306,7 +306,7 @@ static int parse_key_value_squoted(char *buf, struct string_list *list) * script, and thus if the file differs from what this function expects, it is * better to bail out than to do something that the user does not expect. */ -static int read_author_script(struct am_state *state) +static int read_am_author_script(struct am_state *state) { const char *filename = am_path(state, "author-script"); struct strbuf buf = STRBUF_INIT; @@ -441,7 +441,7 @@ static void am_load(struct am_state *state) BUG("state file 'last' does not exist"); state->last = strtol(sb.buf, NULL, 10); - if (read_author_script(state) < 0) + if (read_am_author_script(state) < 0) die(_("could not parse author script")); read_commit_msg(state); From patchwork Tue Oct 30 10:39:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10660651 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 7EF571734 for ; Tue, 30 Oct 2018 10:39:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F7A29EEA for ; Tue, 30 Oct 2018 10:39:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C97B29F2A; Tue, 30 Oct 2018 10:39:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 0E5F129EEA for ; Tue, 30 Oct 2018 10:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727556AbeJ3TcX (ORCPT ); Tue, 30 Oct 2018 15:32:23 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:31456 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727529AbeJ3TcX (ORCPT ); Tue, 30 Oct 2018 15:32:23 -0400 Received: from lindisfarne.localdomain ([92.22.32.73]) by smtp.talktalk.net with SMTP id HRQbg5GIzdJAeHRQjgS6N1; Tue, 30 Oct 2018 10:39:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1540895966; bh=2RJR+U3FpS3hEGJo3oC44K6LdjAw0TYYMsjZ8QIwN+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=eNz0/o6UEIXUWLAnQPVZe2SbrTO+rsmY4FT/Hz+SJDT+6HYUd3PHL77obOphoZL85 NXev43NMXTFqgUNF+v7Y+E8khRiWWXZ2x28Tv3O1bqolyzry2tCE9BRQq0/KGUBHi1 mu3RoRFFZEtwuE3N+yFkG8oB8Rwue/htp1U0OwwA= X-Originating-IP: [92.22.32.73] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=w3K0eKD2tyZHkEydg3BQCA==:117 a=w3K0eKD2tyZHkEydg3BQCA==:17 a=evINK-nbAAAA:8 a=ptTNLviJEnKM3T6GpPoA:9 a=k2_1p6PUbCVEKFBt:21 a=VGg1cHLJUown9a68:21 a=RfR_gqz1fSpA9VikTjo0:22 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Phillip Wood To: Git Mailing List , Junio C Hamano Cc: Eric Sunshine , Johannes Schindelin , Phillip Wood Subject: [PATCH v3 4/5] add read_author_script() to libgit Date: Tue, 30 Oct 2018 10:39:15 +0000 Message-Id: <20181030103916.6241-5-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030103916.6241-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> <20181030103916.6241-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfIhW44sJHgmCWlHLTqmNEFHAkETef7oAqgeLze42SXCAthVohqaGV6KBGC7Q1cSi0vWCvPlBsFDoM9QVvCSnlROAzO37FNxu9fweOqAojCR6odBjxC7L d/6EufXrvuHoxk8iqT5U7pojJi/GnDJYh53Kk21sj99gewxWyGMR30nFwABkfMqXDGAGADlhb2AX77zKQUSaeUftqIphiGJy9y5qMqDQpb9TtBVEZiL1E/+U Q1ydxHc1GDIWK5oJHIexwV0KkCpxA0WCpSw6IJRYUyLFHhN+zDdjo5coPzgV1s8RaZ4fDIPXdb6099ZcOgz++0bLguuzktOeGjdmookHcms= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Add read_author_script() to sequencer.c based on the implementation in builtin/am.c and update read_am_author_script() to use read_author_script(). The sequencer code that reads the author script will be updated in the next commit. Signed-off-by: Phillip Wood --- Notes: changes since v1: - added comment above read_author_script() - rebased to reflect changes added in patch 2 builtin/am.c | 86 +---------------------------------------- sequencer.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 3 ++ 3 files changed, 110 insertions(+), 84 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 991d13f9a2..c5373158c0 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -260,36 +260,6 @@ static int read_state_file(struct strbuf *sb, const struct am_state *state, die_errno(_("could not read '%s'"), am_path(state, file)); } -/** - * Take a series of KEY='VALUE' lines where VALUE part is - * sq-quoted, and append at the end of the string list - */ -static int parse_key_value_squoted(char *buf, struct string_list *list) -{ - while (*buf) { - struct string_list_item *item; - char *np; - char *cp = strchr(buf, '='); - if (!cp) { - np = strchrnul(buf, '\n'); - return error(_("unable to parse '%.*s'"), - (int) (np - buf), buf); - } - np = strchrnul(cp, '\n'); - *cp++ = '\0'; - item = string_list_append(list, buf); - - buf = np + (*np == '\n'); - *np = '\0'; - cp = sq_dequote(cp); - if (!cp) - return error(_("unable to dequote value of '%s'"), - item->string); - item->util = xstrdup(cp); - } - return 0; -} - /** * Reads and parses the state directory's "author-script" file, and sets * state->author_name, state->author_email and state->author_date accordingly. @@ -309,65 +279,13 @@ static int parse_key_value_squoted(char *buf, struct string_list *list) static int read_am_author_script(struct am_state *state) { const char *filename = am_path(state, "author-script"); - struct strbuf buf = STRBUF_INIT; - struct string_list kv = STRING_LIST_INIT_DUP; - int retval = -1; /* assume failure */ - int i, name_i = -2, email_i = -2, date_i = -2, err = 0; - int fd; assert(!state->author_name); assert(!state->author_email); assert(!state->author_date); - fd = open(filename, O_RDONLY); - if (fd < 0) { - if (errno == ENOENT) - return 0; - return error_errno(_("could not open '%s' for reading"), - filename); - } - strbuf_read(&buf, fd, 0); - close(fd); - if (parse_key_value_squoted(buf.buf, &kv)) - goto finish; - - for (i = 0; i < kv.nr; i++) { - if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) { - if (name_i >= 0) - name_i = error(_("'GIT_AUTHOR_NAME' already given")); - else - name_i = i; - } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) { - if (email_i >= 0) - email_i = error(_("'GIT_AUTHOR_EMAIL' already given")); - else - email_i = i; - } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) { - if (date_i >= 0) - date_i = error(_("'GIT_AUTHOR_DATE' already given")); - else - date_i = i; - } else { - err = error(_("unknown variable '%s'"), - kv.items[i].string); - } - } - if (name_i == -2) - error(_("missing 'GIT_AUTHOR_NAME'")); - if (email_i == -2) - error(_("missing 'GIT_AUTHOR_EMAIL'")); - if (date_i == -2) - error(_("missing 'GIT_AUTHOR_DATE'")); - if (date_i < 0 || email_i < 0 || date_i < 0 || err) - goto finish; - state->author_name = kv.items[name_i].util; - state->author_email = kv.items[email_i].util; - state->author_date = kv.items[date_i].util; - retval = 0; -finish: - string_list_clear(&kv, !!retval); - strbuf_release(&buf); - return retval; + return read_author_script(filename, &state->author_name, + &state->author_email, &state->author_date, 1); } /** diff --git a/sequencer.c b/sequencer.c index dc2c58d464..3530dbeb6c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -660,6 +660,111 @@ static int write_author_script(const char *message) return res; } +/** + * Take a series of KEY='VALUE' lines where VALUE part is + * sq-quoted, and append at the end of the string list + */ +static int parse_key_value_squoted(char *buf, struct string_list *list) +{ + while (*buf) { + struct string_list_item *item; + char *np; + char *cp = strchr(buf, '='); + if (!cp) { + np = strchrnul(buf, '\n'); + return error(_("unable to parse '%.*s'"), + (int) (np - buf), buf); + } + np = strchrnul(cp, '\n'); + *cp++ = '\0'; + item = string_list_append(list, buf); + + buf = np + (*np == '\n'); + *np = '\0'; + cp = sq_dequote(cp); + if (!cp) + return error(_("unable to dequote value of '%s'"), + item->string); + item->util = xstrdup(cp); + } + return 0; +} + +/** + * Reads and parses the state directory's "author-script" file, and sets name, + * email and date accordingly. + * Returns 0 on success, -1 if the file could not be parsed. + * + * The author script is of the format: + * + * GIT_AUTHOR_NAME='$author_name' + * GIT_AUTHOR_EMAIL='$author_email' + * GIT_AUTHOR_DATE='$author_date' + * + * where $author_name, $author_email and $author_date are quoted. We are strict + * with our parsing, as the file was meant to be eval'd in the old + * git-am.sh/git-rebase--interactive.sh scripts, and thus if the file differs + * from what this function expects, it is better to bail out than to do + * something that the user does not expect. + */ +int read_author_script(const char *path, char **name, char **email, char **date, + int allow_missing) +{ + struct strbuf buf = STRBUF_INIT; + struct string_list kv = STRING_LIST_INIT_DUP; + int retval = -1; /* assume failure */ + int i, name_i = -2, email_i = -2, date_i = -2, err = 0; + + if (strbuf_read_file(&buf, path, 256) <= 0) { + strbuf_release(&buf); + if (errno == ENOENT && allow_missing) + return 0; + else + return error_errno(_("could not open '%s' for reading"), + path); + } + + if (parse_key_value_squoted(buf.buf, &kv)) + goto finish; + + for (i = 0; i < kv.nr; i++) { + if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) { + if (name_i >= 0) + name_i = error(_("'GIT_AUTHOR_NAME' already given")); + else + name_i = i; + } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) { + if (email_i >= 0) + email_i = error(_("'GIT_AUTHOR_EMAIL' already given")); + else + email_i = i; + } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) { + if (date_i >= 0) + date_i = error(_("'GIT_AUTHOR_DATE' already given")); + else + date_i = i; + } else { + err = error(_("unknown variable '%s'"), + kv.items[i].string); + } + } + if (name_i == -2) + error(_("missing 'GIT_AUTHOR_NAME'")); + if (email_i == -2) + error(_("missing 'GIT_AUTHOR_EMAIL'")); + if (date_i == -2) + error(_("missing 'GIT_AUTHOR_DATE'")); + if (date_i < 0 || email_i < 0 || date_i < 0 || err) + goto finish; + *name = kv.items[name_i].util; + *email = kv.items[email_i].util; + *date = kv.items[date_i].util; + retval = 0; +finish: + string_list_clear(&kv, !!retval); + strbuf_release(&buf); + return retval; +} /* * write_author_script() used to fail to terminate the last line with a "'" and diff --git a/sequencer.h b/sequencer.h index c751c9d6e4..3713f955f5 100644 --- a/sequencer.h +++ b/sequencer.h @@ -107,4 +107,7 @@ void commit_post_rewrite(const struct commit *current_head, #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) void print_commit_summary(const char *prefix, const struct object_id *oid, unsigned int flags); + +int read_author_script(const char *path, char **name, char **email, char **date, + int allow_missing); #endif From patchwork Tue Oct 30 10:39:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10660653 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 061BF1734 for ; Tue, 30 Oct 2018 10:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1D4429F17 for ; Tue, 30 Oct 2018 10:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D644629F32; Tue, 30 Oct 2018 10:39: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,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 D02DB29F11 for ; Tue, 30 Oct 2018 10:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727564AbeJ3TcY (ORCPT ); Tue, 30 Oct 2018 15:32:24 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:34662 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727525AbeJ3TcY (ORCPT ); Tue, 30 Oct 2018 15:32:24 -0400 Received: from lindisfarne.localdomain ([92.22.32.73]) by smtp.talktalk.net with SMTP id HRQbg5GIzdJAeHRQkgS6N6; Tue, 30 Oct 2018 10:39:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1540895966; bh=7F9WReZg7ga6+/PQWusQsogHlg+1J4/vhBNZ1dK9Qqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=BQE1taqpLnloBngUic7o6SVESrFon3oZedQy5Ql32CBwfWiHjlqICbam5RRQ/pfSO DSEwzR74t8uTOVlqPPdueyhhseblhEG/IjRe3Yso3HA1bO3nlNsjgBcWjXpaZAVxUZ WSrzzjCN+AHraj2y8Ld/QZa7XeXNiKeE1kmgkpOo= X-Originating-IP: [92.22.32.73] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=w3K0eKD2tyZHkEydg3BQCA==:117 a=w3K0eKD2tyZHkEydg3BQCA==:17 a=evINK-nbAAAA:8 a=hmY0TbxAJEL1NjLCw64A:9 a=VF1MDj8z9UGIESg9:21 a=KeheEo3eoYsdSEJ7:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Git Mailing List , Junio C Hamano Cc: Eric Sunshine , Johannes Schindelin , Phillip Wood Subject: [PATCH v3 5/5] sequencer: use read_author_script() Date: Tue, 30 Oct 2018 10:39:16 +0000 Message-Id: <20181030103916.6241-6-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030103916.6241-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> <20181030103916.6241-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfIhW44sJHgmCWlHLTqmNEFHAkETef7oAqgeLze42SXCAthVohqaGV6KBGC7Q1cSi0vWCvPlBsFDoM9QVvCSnlROAzO37FNxu9fweOqAojCR6odBjxC7L d/6EufXrvuHoxk8iqT5U7pojJi/GnDJYh53Kk21sj99gewxWyGMR30nFwABkfMqXDGAGADlhb2AX77zKQUSaeUftqIphiGJy9y5qMqDQpb9TtBVEZiL1E/+U Q1ydxHc1GDIWK5oJHIexwV0KkCpxA0WCpSw6IJRYUyLFHhN+zDdjo5coPzgV1s8RaZ4fDIPXdb6099ZcOgz++0bLguuzktOeGjdmookHcms= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Use the new function added in the last commit to read the author script, updating read_env_script() and read_author_ident(). We now have a single code path that reads the author script for am and all flavors of rebase. This changes the behavior of read_env_script() as previously it would set any environment variables that were in the author-script file. Now it is an error if the file contains other variables or any of GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE are missing. This is what am and the non interactive version of rebase have been doing for several years so hopefully it will not cause a problem for interactive rebase users. The advantage is that we are reusing existing code from am which uses sq_dequote() to properly dequote variables. This fixes potential problems with user edited scripts as read_env_script() which did not track quotes properly. This commit also removes the fallback code for checking for a broken author script after git is upgraded when a rebase is stopped. Now that the parsing uses sq_dequote() it will reliably return an error if the quoting is broken and the user will have to abort the rebase and restart. This isn't ideal but it's a corner case and the detection of the broken quoting could be confused by user edited author scripts. Signed-off-by: Phillip Wood --- Notes: changes since v1 - use argv_array_pushf() as suggested by Eric - fixed strbuf handling as suggested by Eric - fix comments and commit message to reflect changed behavior of read_env_script() sequencer.c | 97 ++++++++++++----------------------------------------- 1 file changed, 21 insertions(+), 76 deletions(-) diff --git a/sequencer.c b/sequencer.c index 3530dbeb6c..987542f67c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -767,53 +767,24 @@ int read_author_script(const char *path, char **name, char **email, char **date, } /* - * write_author_script() used to fail to terminate the last line with a "'" and - * also escaped "'" incorrectly as "'\\\\''" rather than "'\\''". We check for - * the terminating "'" on the last line to see how "'" has been escaped in case - * git was upgraded while rebase was stopped. - */ -static int quoting_is_broken(const char *s, size_t n) -{ - /* Skip any empty lines in case the file was hand edited */ - while (n > 0 && s[--n] == '\n') - ; /* empty */ - if (n > 0 && s[n] != '\'') - return 1; - - return 0; -} - -/* - * Read a list of environment variable assignments (such as the author-script - * file) into an environment block. Returns -1 on error, 0 otherwise. + * Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a + * file with shell quoting into struct argv_array. Returns -1 on + * error, 0 otherwise. */ static int read_env_script(struct argv_array *env) { - struct strbuf script = STRBUF_INIT; - int i, count = 0, sq_bug; - const char *p2; - char *p; + char *name, *email, *date; - if (strbuf_read_file(&script, rebase_path_author_script(), 256) <= 0) + if (read_author_script(rebase_path_author_script(), + &name, &email, &date, 0)) return -1; - /* write_author_script() used to quote incorrectly */ - sq_bug = quoting_is_broken(script.buf, script.len); - for (p = script.buf; *p; p++) - if (sq_bug && skip_prefix(p, "'\\\\''", &p2)) - strbuf_splice(&script, p - script.buf, p2 - p, "'", 1); - else if (skip_prefix(p, "'\\''", &p2)) - strbuf_splice(&script, p - script.buf, p2 - p, "'", 1); - else if (*p == '\'') - strbuf_splice(&script, p-- - script.buf, 1, "", 0); - else if (*p == '\n') { - *p = '\0'; - count++; - } - for (i = 0, p = script.buf; i < count; i++) { - argv_array_push(env, p); - p += strlen(p) + 1; - } + argv_array_pushf(env, "GIT_AUTHOR_NAME=%s", name); + argv_array_pushf(env, "GIT_AUTHOR_EMAIL=%s", email); + argv_array_pushf(env, "GIT_AUTHOR_DATE=%s", date); + free(name); + free(email); + free(date); return 0; } @@ -833,54 +804,28 @@ static char *get_author(const char *message) /* Read author-script and return an ident line (author timestamp) */ static const char *read_author_ident(struct strbuf *buf) { - const char *keys[] = { - "GIT_AUTHOR_NAME=", "GIT_AUTHOR_EMAIL=", "GIT_AUTHOR_DATE=" - }; struct strbuf out = STRBUF_INIT; - char *in, *eol; - const char *val[3]; - int i = 0; + char *name, *email, *date; - if (strbuf_read_file(buf, rebase_path_author_script(), 256) <= 0) + if (read_author_script(rebase_path_author_script(), + &name, &email, &date, 0)) return NULL; - /* dequote values and construct ident line in-place */ - for (in = buf->buf; i < 3 && in - buf->buf < buf->len; i++) { - if (!skip_prefix(in, keys[i], (const char **)&in)) { - warning(_("could not parse '%s' (looking for '%s')"), - rebase_path_author_script(), keys[i]); - return NULL; - } - - eol = strchrnul(in, '\n'); - *eol = '\0'; - if (!sq_dequote(in)) { - warning(_("bad quoting on %s value in '%s'"), - keys[i], rebase_path_author_script()); - return NULL; - } - val[i] = in; - in = eol + 1; - } - - if (i < 3) { - warning(_("could not parse '%s' (looking for '%s')"), - rebase_path_author_script(), keys[i]); - return NULL; - } - /* validate date since fmt_ident() will die() on bad value */ - if (parse_date(val[2], &out)){ + if (parse_date(date, &out)){ warning(_("invalid date format '%s' in '%s'"), - val[2], rebase_path_author_script()); + date, rebase_path_author_script()); strbuf_release(&out); return NULL; } strbuf_reset(&out); - strbuf_addstr(&out, fmt_ident(val[0], val[1], val[2], 0)); + strbuf_addstr(&out, fmt_ident(name, email, date, 0)); strbuf_swap(buf, &out); strbuf_release(&out); + free(name); + free(email); + free(date); return buf->buf; }