From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH 03/18] revert: Simplify and inline add_message_to_msg Date: Wed, 27 Jul 2011 08:49:00 +0530 Message-ID: <1311736755-24205-4-git-send-email-artagnon@gmail.com> References: <1311736755-24205-1-git-send-email-artagnon@gmail.com> Cc: Jonathan Nieder , Junio C Hamano , Christian Couder , Daniel Barkalow , Jeff King To: Git List X-From: git-owner@vger.kernel.org Wed Jul 27 05:22:55 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qluhy-0005xW-5g for gcvg-git-2@lo.gmane.org; Wed, 27 Jul 2011 05:22:54 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753966Ab1G0DWe (ORCPT ); Tue, 26 Jul 2011 23:22:34 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:35904 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753827Ab1G0DWb (ORCPT ); Tue, 26 Jul 2011 23:22:31 -0400 Received: by mail-pz0-f42.google.com with SMTP id 37so1938359pzk.1 for ; Tue, 26 Jul 2011 20:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=KVxqZt74Mhh8Sorkq2xMrm/WVzy9tmlg0/aMXWXQpc0=; b=RxsYfkPiwO0GdCFZn1PUaL4F4iphdhOz3XmFgvXnMfzA2YTgDkmuWCxYAu0dnoKi9d i5uf0h/06n1FhRfdhKJqZrAs6M0c8yi7swl1zjjY6lZ6qQdrOtjl5alkFEAnBcwr7q5u XcZ+v7uUHxb0F2kbXGeYs/vXAOgl+t+hxDFZY= Received: by 10.68.27.131 with SMTP id t3mr11532789pbg.487.1311736951063; Tue, 26 Jul 2011 20:22:31 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.41]) by mx.google.com with ESMTPS id p7sm1210706pbn.65.2011.07.26.20.22.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 26 Jul 2011 20:22:29 -0700 (PDT) X-Mailer: git-send-email 1.7.4.rc1.7.g2cf08.dirty In-Reply-To: <1311736755-24205-1-git-send-email-artagnon@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: The add_message_to_msg function has some dead code, an unclear API, only one callsite. While it originally intended fill up an empty commit message with the commit object name while picking, it really doesn't do this -- a bug introduced in 9509af6 (Make git-revert & git-cherry-pick a builtin, 2007-03-01). Today, tests in t3505-cherry-pick-empty.sh indicate that not filling up an empty commit message is the desired behavior. Re-implement and inline the function accordingly. Helped-by: Junio C Hamano Mentored-by: Jonathan Nieder Signed-off-by: Ramkumar Ramachandra --- builtin/revert.c | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index 2df3f3b..7dfe295 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -185,19 +185,6 @@ static char *get_encoding(const char *message) return NULL; } -static void add_message_to_msg(struct strbuf *msgbuf, const char *message) -{ - const char *p = message; - while (*p && (*p != '\n' || p[1] != '\n')) - p++; - - if (!*p) - strbuf_addstr(msgbuf, sha1_to_hex(commit->object.sha1)); - - p += 2; - strbuf_addstr(msgbuf, p); -} - static void write_cherry_pick_head(void) { int fd; @@ -462,11 +449,24 @@ static int do_pick_commit(void) } strbuf_addstr(&msgbuf, ".\n"); } else { + const char *p; + base = parent; base_label = msg.parent_label; next = commit; next_label = msg.label; - add_message_to_msg(&msgbuf, msg.message); + + /* + * Append the commit log message to msgbuf; it starts + * after the tree, parent, author, committer + * information followed by "\n\n". + */ + p = strstr(msg.message, "\n\n"); + if (p) { + p += 2; + strbuf_addstr(&msgbuf, p); + } + if (no_replay) { strbuf_addstr(&msgbuf, "(cherry picked from commit "); strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1)); -- 1.7.4.rc1.7.g2cf08.dirty