From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH 01/18] advice: Introduce error_resolve_conflict Date: Mon, 1 Aug 2011 23:36:48 +0530 Message-ID: <1312222025-28453-2-git-send-email-artagnon@gmail.com> References: <1312222025-28453-1-git-send-email-artagnon@gmail.com> Cc: Git List , Jonathan Nieder , Christian Couder , Daniel Barkalow , Jeff King To: Junio C Hamano X-From: git-owner@vger.kernel.org Mon Aug 01 20:11:09 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 1QnwxD-0003Xt-V1 for gcvg-git-2@lo.gmane.org; Mon, 01 Aug 2011 20:11:04 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751880Ab1HASKt (ORCPT ); Mon, 1 Aug 2011 14:10:49 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:41572 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750699Ab1HASKo (ORCPT ); Mon, 1 Aug 2011 14:10:44 -0400 Received: by yxi11 with SMTP id 11so3305634yxi.19 for ; Mon, 01 Aug 2011 11:10:43 -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=1Y+Ow/+11X8K58gVxAlVM4EcIQEKcIl0PhinAZX6CEs=; b=eqwzDBe6Ve+ZtJsW5xPAzGsjVqgheM8o/KFX3BHLtshBzbXA95F4JbhLcM1L4Vo0KF Heyhb68KN7evAFNvgdsHKxhKdyNZvm7dDjwuMDBjC97sxdGqc/sCiz5ineLqL6O7UgYx ZHR87OC05HSt5C/0yRUgShSIQPGUvLPIX4DrE= Received: by 10.143.165.3 with SMTP id s3mr890530wfo.84.1312222242775; Mon, 01 Aug 2011 11:10:42 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.41]) by mx.google.com with ESMTPS id d3sm5789958pbh.37.2011.08.01.11.10.34 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Aug 2011 11:10:41 -0700 (PDT) X-Mailer: git-send-email 1.7.4.rc1.7.g2cf08.dirty In-Reply-To: <1312222025-28453-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: Enable future callers to report a conflict and not die immediately by introducing a new function called error_resolve_conflict. Re-implement die_resolve_conflict as a call to error_resolve_conflict followed by a call to die. Consequently, the message printed by die_resolve_conflict changes from fatal: 'commit' is not possible because you have unmerged files. Please, fix them up in the work tree ... ... to error: 'commit' is not possible because you have unmerged files. hint: Fix them up in the work tree ... hint: ... fatal: Exiting because of an unresolved conflict. Hints are printed using the same advise function introduced in v1.7.3-rc0~26^2~3 (Introduce advise() to print hints, 2010-08-11). Inspired-by: Christian Couder Helped-by: Jonathan Nieder Reviewed-by: Jonathan Nieder Signed-off-by: Ramkumar Ramachandra --- advice.c | 31 ++++++++++++++++++++++++------- advice.h | 3 ++- builtin/revert.c | 9 --------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/advice.c b/advice.c index 0be4b5f..e02e632 100644 --- a/advice.c +++ b/advice.c @@ -19,6 +19,15 @@ static struct { { "detachedhead", &advice_detached_head }, }; +void advise(const char *advice, ...) +{ + va_list params; + + va_start(params, advice); + vreportf("hint: ", advice, params); + va_end(params); +} + int git_default_advice_config(const char *var, const char *value) { const char *k = skip_prefix(var, "advice."); @@ -34,16 +43,24 @@ int git_default_advice_config(const char *var, const char *value) return 0; } -void NORETURN die_resolve_conflict(const char *me) +int error_resolve_conflict(const char *me) { - if (advice_resolve_conflict) + error("'%s' is not possible because you have unmerged files.", me); + if (advice_resolve_conflict) { /* * Message used both when 'git commit' fails and when * other commands doing a merge do. */ - die("'%s' is not possible because you have unmerged files.\n" - "Please, fix them up in the work tree, and then use 'git add/rm ' as\n" - "appropriate to mark resolution and make a commit, or use 'git commit -a'.", me); - else - die("'%s' is not possible because you have unmerged files.", me); + advise("Fix them up in the work tree,"); + advise("and then use 'git add/rm ' as"); + advise("appropriate to mark resolution and make a commit,"); + advise("or use 'git commit -a'."); + } + return -1; +} + +void NORETURN die_resolve_conflict(const char *me) +{ + error_resolve_conflict(me); + die("Exiting because of an unresolved conflict."); } diff --git a/advice.h b/advice.h index 3244ebb..e5d0af7 100644 --- a/advice.h +++ b/advice.h @@ -11,7 +11,8 @@ extern int advice_implicit_identity; extern int advice_detached_head; int git_default_advice_config(const char *var, const char *value); - +void advise(const char *advice, ...); +int error_resolve_conflict(const char *me); extern void NORETURN die_resolve_conflict(const char *me); #endif /* ADVICE_H */ diff --git a/builtin/revert.c b/builtin/revert.c index 1f27c63..2df3f3b 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -214,15 +214,6 @@ static void write_cherry_pick_head(void) strbuf_release(&buf); } -static void advise(const char *advice, ...) -{ - va_list params; - - va_start(params, advice); - vreportf("hint: ", advice, params); - va_end(params); -} - static void print_advice(void) { char *msg = getenv("GIT_CHERRY_PICK_HELP"); -- 1.7.4.rc1.7.g2cf08.dirty