[RFC/PATCH 09/18] revert: make pick_commits() return an error on --ff incompatible option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As we want to use pick_commits() many times and write TODO and DONE
file in case of errors, we must not die in case of error inside
pick_commits() but return an error.

Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
---
 builtin/revert.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index 1f20251..57d4300 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -578,33 +578,33 @@ static void read_and_refresh_cache(const char *me)
 	rollback_lock_file(&index_lock);
 }
 
+static int ff_incompatible(int val, const char *opt)
+{
+	return val ? error("cherry-pick --ff cannot be used with %s", opt) : 0;
+}
+
 static int pick_commits(struct args_info *infos)
 {
 	struct rev_info revs;
 	struct commit *commit;
+	int res = 0;
 
-	if (infos->allow_ff) {
-		if (infos->signoff)
-			die("cherry-pick --ff cannot be used with --signoff");
-		if (infos->no_commit)
-			die("cherry-pick --ff cannot be used with --no-commit");
-		if (infos->no_replay)
-			die("cherry-pick --ff cannot be used with -x");
-		if (infos->edit)
-			die("cherry-pick --ff cannot be used with --edit");
-	}
+	if (infos->allow_ff &&
+	    ((res = ff_incompatible(infos->signoff, "--signoff")) ||
+	     (res = ff_incompatible(infos->no_commit, "--no_commit")) ||
+	     (res = ff_incompatible(infos->no_replay, "-x")) ||
+	     (res = ff_incompatible(infos->edit, "--edit"))))
+			return res;
 
 	read_and_refresh_cache(me);
 
 	prepare_revs(&revs, infos);
 
-	while ((commit = get_revision(&revs))) {
-		int res = do_pick_commit(infos, commit);
-		if (res)
-			return res;
-	}
+	while ((commit = get_revision(&revs)) &&
+	       !(res = do_pick_commit(infos, commit)))
+		; /* do nothing */
 
-	return 0;
+	return res;
 }
 
 static int revert_or_cherry_pick(int argc, const char **argv, int revert, int edit)
-- 
1.7.3.2.504.g59d466


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]