From patchwork Wed Sep 12 10:10:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10597309 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 4530115E2 for ; Wed, 12 Sep 2018 10:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 346D229ACA for ; Wed, 12 Sep 2018 10:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2865929B34; Wed, 12 Sep 2018 10:10:51 +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 843C229ACA for ; Wed, 12 Sep 2018 10:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbeILPOj (ORCPT ); Wed, 12 Sep 2018 11:14:39 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:63187 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726798AbeILPOj (ORCPT ); Wed, 12 Sep 2018 11:14:39 -0400 Received: from lindisfarne.localdomain ([89.242.190.162]) by smtp.talktalk.net with SMTP id 026Ygd54KdJAe026ggxHB3; Wed, 12 Sep 2018 11:10:47 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1536747047; bh=3nrcFIDVEwVz+Vs0/qDyBgOJqv+mOVLVPRO2DGILMGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=npHCisJGs0sPAjBn4+xVOIJ608JEdyYBPGZ6iTJnF/0/0ELnPFCBX1dQHY6LQeebL s+rhI9GocmSdpXiKYeuUtbrcROE+xKTKNQb1uvgicgT9QNq6MSjhm7nNXiNXIDUadJ U+1ZoKQ74CPKC8ZKoLSnTlkvqTBOHni8sgFCqLVs= X-Originating-IP: [89.242.190.162] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=yWw/b5KBQb65dAU66aqL/Q==:117 a=yWw/b5KBQb65dAU66aqL/Q==:17 a=evINK-nbAAAA:8 a=jAbL0x3HlbHIGo4u6YsA:9 a=9cwk9Okqd2CfRaF0:21 a=q43gRipxSBSK2way:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Junio C Hamano , Johannes Schindelin Cc: Git Mailing List , Eric Sunshine , Phillip Wood Subject: [PATCH 1/3] am: rename read_author_script() Date: Wed, 12 Sep 2018 11:10:27 +0100 Message-Id: <20180912101029.28052-2-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180912101029.28052-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfG6gRX1GqTBQ0/GE0ijBJ4yx/Grydn9JQ9Lp9QiwJ6GmF6HJ98xvylyKLP0ur09s0pur2ffmh9ZWgJ4fOjhlVdXskRQExBxOZ3EQjDvyC7BtFDzxbDf1 2scAa6WDx05COq59zNWK43c2Uq1xEGc0OleZkaR4/doYRiittDzr68DNpw69dV2Hib22tv1sVD7icav90q3HzJ/Kp7YVQUwJrptXZMSmS8P1tSUHWZT86zQO vIimjtnsKpaXEEoLBVbpx10wtoXBg9INNKOlKBe6cFMCFC/nDUD/JG+69OQ6ZqKB9EtpUDR/3+LF9aOdyLJN/RM3LW0Me5YecymQPrzeg9c= 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 5e866d17c7..8c165f747b 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -302,7 +302,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; @@ -411,7 +411,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 Wed Sep 12 10:10:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10597313 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 C32D617DF for ; Wed, 12 Sep 2018 10:10:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B142629ACA for ; Wed, 12 Sep 2018 10:10:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2F2629A2A; Wed, 12 Sep 2018 10:10:52 +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 22B9529A2A for ; Wed, 12 Sep 2018 10:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbeILPOk (ORCPT ); Wed, 12 Sep 2018 11:14:40 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:4446 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeILPOk (ORCPT ); Wed, 12 Sep 2018 11:14:40 -0400 Received: from lindisfarne.localdomain ([89.242.190.162]) by smtp.talktalk.net with SMTP id 026Ygd54KdJAe026hgxHBB; Wed, 12 Sep 2018 11:10:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1536747048; bh=mp4+/E8O9jXda2Qd9EIkoDDztXK3Aoi1K0IVjp3p57I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=UxSwmFY9dxTcJNmKXSF0YdsZiGGMYoW6qGxyeiEcUXKoSbwj8le4rk+MUzO3s1ody Jq1ZX7Rfc1q70N38NR1vVotozDcCNSQJ2pmJ4cTT9B25FULdtXxpDSY/KJq/jbfCZS FtC6bOm45PeSldWiIT7psixxiyEutncFysDkp26U= X-Originating-IP: [89.242.190.162] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=yWw/b5KBQb65dAU66aqL/Q==:117 a=yWw/b5KBQb65dAU66aqL/Q==:17 a=evINK-nbAAAA:8 a=vWm1S-qXhEGamv5ALUgA:9 a=g6tL_zFA9Chf9GHQ:21 a=YTKOyC_TbRCNyoDt:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Junio C Hamano , Johannes Schindelin Cc: Git Mailing List , Eric Sunshine , Phillip Wood Subject: [PATCH 2/3] add read_author_script() to libgit Date: Wed, 12 Sep 2018 11:10:28 +0100 Message-Id: <20180912101029.28052-3-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180912101029.28052-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfIi185e51JesJuDTgTz7Woj9i43bDlV1gIgrGetHY+PXwC6g83mOR91TcwyrpLdYSlfhLNHfwrj3wDUyw3tr5M935PplUjcv3Ko01T377boEcVQqS18Q wEbl1ApSYjBzcIINOzEH9qq75brSCW9U2kle6o6gtTsjZII0FE4sjiJLE8EXvOGt+i72BTaMI/MdD9ZK/HdSSxxVs9/f9hrYMKNssCq8bPWTEplr5AHhg7my WWJ6+Ze8DBWhSc2PMSLBQoY5c5JIQwysXOnDOBvMpnWF5apKcpL8wta3+t2CGwQERE2sreor4QKeVBeMvnNbvN0lSh6k4uMHLpW3ZtP0Ueo= 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 --- builtin/am.c | 57 ++++------------------------------------------- sequencer.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 3 +++ 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 8c165f747b..aa5de0ee73 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -260,32 +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) - return -1; - 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 -1; - 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. @@ -305,39 +279,16 @@ 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 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; - die_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; + if (read_author_script(filename, &state->author_name, + &state->author_email, &state->author_date, 1)) + exit(128); - 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")) - goto finish; - state->author_name = kv.items[0].util; - state->author_email = kv.items[1].util; - state->author_date = kv.items[2].util; - retval = 0; -finish: - string_list_clear(&kv, !!retval); - strbuf_release(&buf); - return retval; + return 0; } /** diff --git a/sequencer.c b/sequencer.c index dc2c58d464..5d0ff8f1c1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -660,6 +660,68 @@ 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) + return -1; + 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 -1; + item->util = xstrdup(cp); + } + return 0; +} + +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; + + 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)) { + error(_("unable to parse '%s'"), path); + 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")) { + error(_("unable to parse '%s'"), path); + goto finish; + } + *name = kv.items[0].util; + *email = kv.items[1].util; + *date = kv.items[2].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 Wed Sep 12 10:10:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10597315 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 157FD921 for ; Wed, 12 Sep 2018 10:10:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0347D29A2A for ; Wed, 12 Sep 2018 10:10:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBCE629B15; Wed, 12 Sep 2018 10:10: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,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 6D4CA29A2A for ; Wed, 12 Sep 2018 10:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726992AbeILPOk (ORCPT ); Wed, 12 Sep 2018 11:14:40 -0400 Received: from smtp-out-5.talktalk.net ([62.24.135.69]:63794 "EHLO smtp-out-5.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726552AbeILPOk (ORCPT ); Wed, 12 Sep 2018 11:14:40 -0400 Received: from lindisfarne.localdomain ([89.242.190.162]) by smtp.talktalk.net with SMTP id 026Ygd54KdJAe026igxHBG; Wed, 12 Sep 2018 11:10:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1536747048; bh=1VIpNeoWYmdwTqfa/7asWskmTPzvGqvfBwMKZoInxqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=Zw1vwYXCetiyD/IE8f0EDI6dkyRSKCQB9bXD+8vsM8Qy/C7mYV96QFQnZLrDWpWip C+B/96RZrJQ377XDih5H5DJvTegtqt+RjEsFWfDdtxIaWs3wuMmGesMh6rZ05JZ+4i +Ca4N5A0Gt7hYbE/T4bKf7nvoCBnPAFL/kZa4ERw= X-Originating-IP: [89.242.190.162] X-Spam: 0 X-OAuthority: v=2.3 cv=V8BTL9vi c=1 sm=1 tr=0 a=yWw/b5KBQb65dAU66aqL/Q==:117 a=yWw/b5KBQb65dAU66aqL/Q==:17 a=evINK-nbAAAA:8 a=hmY0TbxAJEL1NjLCw64A:9 a=lUuLDBlSICsWFDiz:21 a=lDCOD0JcADFK45N1:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Junio C Hamano , Johannes Schindelin Cc: Git Mailing List , Eric Sunshine , Phillip Wood Subject: [PATCH 3/3] sequencer: use read_author_script() Date: Wed, 12 Sep 2018 11:10:29 +0100 Message-Id: <20180912101029.28052-4-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180912101029.28052-1-phillip.wood@talktalk.net> References: <20180912101029.28052-1-phillip.wood@talktalk.net> Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfIi185e51JesJuDTgTz7Woj9i43bDlV1gIgrGetHY+PXwC6g83mOR91TcwyrpLdYSlfhLNHfwrj3wDUyw3tr5M935PplUjcv3Ko01T377boEcVQqS18Q wEbl1ApSYjBzcIINOzEH9qq75brSCW9U2kle6o6gtTsjZII0FE4sjiJLE8EXvOGt+i72BTaMI/MdD9ZK/HdSSxxVs9/f9hrYMKNssCq8bPWTEplr5AHhg7my WWJ6+Ze8DBWhSc2PMSLBQoY5c5JIQwysXOnDOBvMpnWF5apKcpL8wta3+t2CGwQERE2sreor4QKeVBeMvnNbvN0lSh6k4uMHLpW3ZtP0Ueo= 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 to read the author script, updating read_env_script() and read_author_ident(). This means we now have a single code path that reads the author script and uses sq_dequote() to dequote it. 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 --- sequencer.c | 108 +++++++++++++++------------------------------------- 1 file changed, 30 insertions(+), 78 deletions(-) diff --git a/sequencer.c b/sequencer.c index 5d0ff8f1c1..630741cfe0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -723,54 +723,35 @@ int read_author_script(const char *path, char **name, char **email, char **date, return retval; } -/* - * 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. */ 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; - } + strbuf_addstr(&script, "GIT_AUTHOR_NAME="); + strbuf_addstr(&script, name); + argv_array_push(env, script.buf); + strbuf_reset(&script); + strbuf_addstr(&script, "GIT_AUTHOR_EMAIL="); + strbuf_addstr(&script, email); + argv_array_push(env, script.buf); + strbuf_reset(&script); + strbuf_addstr(&script, "GIT_AUTHOR_DATE="); + strbuf_addstr(&script, date); + argv_array_push(env, script.buf); + strbuf_release(&script); + + free(name); + free(email); + free(date); return 0; } @@ -790,54 +771,25 @@ 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, buf)){ warning(_("invalid date format '%s' in '%s'"), - val[2], rebase_path_author_script()); - strbuf_release(&out); + date, rebase_path_author_script()); + strbuf_release(buf); return NULL; } - strbuf_reset(&out); - strbuf_addstr(&out, fmt_ident(val[0], val[1], val[2], 0)); - strbuf_swap(buf, &out); - strbuf_release(&out); + strbuf_reset(buf); + strbuf_addstr(buf, fmt_ident(name, email, date, 0)); + free(name); + free(email); + free(date); return buf->buf; }