From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aleksey Mokhovikov Subject: [PATCH][GSOC] Selection of the verbose message is replaced with generated message in install_branch_config() Date: Mon, 17 Mar 2014 16:55:04 +0700 Message-ID: <1395050104-19152-1-git-send-email-moxobukob@gmail.com> Cc: Aleksey Mokhovikov To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon Mar 17 10:48:31 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WPU9k-0002dj-R7 for gcvg-git-2@plane.gmane.org; Mon, 17 Mar 2014 10:48:29 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756348AbaCQJsZ (ORCPT ); Mon, 17 Mar 2014 05:48:25 -0400 Received: from mail-lb0-f177.google.com ([209.85.217.177]:33236 "EHLO mail-lb0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756118AbaCQJsY (ORCPT ); Mon, 17 Mar 2014 05:48:24 -0400 Received: by mail-lb0-f177.google.com with SMTP id z11so3375536lbi.8 for ; Mon, 17 Mar 2014 02:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=GlCw72qea5uZtrTjijBqbT+I7zns4peSiFvzmXUeINk=; b=vxLnJsYPPPiCyJBepaRqH1mDsazaJ4jIlD0CYtH60mUKL/mpjH8tRVIxs/DG05nH1L mH4y0k5ioXfN/YPfZccg7FeM43Vxd/RhID2BOXn9yRQdwUEUthyjbXn6zF80XPDpn5DR 10WbWKVH6tA5b7bkuyQvEouBEEEJzCmH6WwHNrpHK+kZgW+/aAZlTtC/gqMTizo0vL2T w2Pb4s6EfA5ylDVYzOj73hGNiZ121pJxUzJ/csKVZzMyO0FvzD/c5e78lLSw3mLlA5aV /ix9e/hQUoyZ+I7Hot2q7O7QV4FVI7+YJLtq8D0lBD4o+Hki/By8qWd88CZybgIH+Csv jRSA== X-Received: by 10.112.173.6 with SMTP id bg6mr15264877lbc.17.1395049702488; Mon, 17 Mar 2014 02:48:22 -0700 (PDT) Received: from localhost.localdomain ([94.180.36.152]) by mx.google.com with ESMTPSA id zf7sm13469776lab.7.2014.03.17.02.48.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Mar 2014 02:48:21 -0700 (PDT) X-Mailer: git-send-email 1.8.3.2 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This is a milliproject from git google summer of code page. The current code that selects the output message is quite easy to understand. So I tried to improve it by removing nested conditions and code duplication. The output string is generated by selecting the proper parts of the message and concatenating them the into one template string. Signed-off-by: Aleksey Mokhovikov --- branch.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/branch.c b/branch.c index 723a36b..2ee353f 100644 --- a/branch.c +++ b/branch.c @@ -77,29 +77,22 @@ void install_branch_config(int flag, const char *local, const char *origin, cons strbuf_release(&key); if (flag & BRANCH_CONFIG_VERBOSE) { - if (remote_is_branch && origin) - printf_ln(rebasing ? - _("Branch %s set up to track remote branch %s from %s by rebasing.") : - _("Branch %s set up to track remote branch %s from %s."), - local, shortname, origin); - else if (remote_is_branch && !origin) - printf_ln(rebasing ? - _("Branch %s set up to track local branch %s by rebasing.") : - _("Branch %s set up to track local branch %s."), - local, shortname); - else if (!remote_is_branch && origin) - printf_ln(rebasing ? - _("Branch %s set up to track remote ref %s by rebasing.") : - _("Branch %s set up to track remote ref %s."), - local, remote); - else if (!remote_is_branch && !origin) - printf_ln(rebasing ? - _("Branch %s set up to track local ref %s by rebasing.") : - _("Branch %s set up to track local ref %s."), - local, remote); - else - die("BUG: impossible combination of %d and %p", - remote_is_branch, origin); + const char *message_template_parts[] = { + "Branch %s set up to track", + origin ? " remote" : " local", + remote_is_branch ? " branch %s" : " ref %s", + (remote_is_branch && origin) ? " from %s" : "", + rebasing ? " by rebasing." : "."}; + struct strbuf message_template = STRBUF_INIT; + size_t i = 0; + + for (i = 0; i < sizeof(message_template_parts)/sizeof(const char *); ++i) { + strbuf_addstr(&message_template, message_template_parts[i]); + } + + printf_ln(_(message_template.buf), local, remote_is_branch ? shortname : remote, origin); + + strbuf_release(&message_template); } } -- 1.8.3.2