[PATCH 5/6] builtin-commit.c: further refactor branch switching

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

 



This adds reset_index_and_worktree() to further factor out the logic for
switching the index and the work tree state from one commit to another to
shrink merge_working_tree() function.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 builtin-checkout.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/builtin-checkout.c b/builtin-checkout.c
index 9c45c49..a08941a 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -433,6 +433,18 @@ static int switch_trees(int merge, int quiet, int *wt_error,
 	return ret;
 }
 
+int reset_index_and_worktree(int force, int merge, int quiet, int *wt_error,
+			     struct commit *old_commit, const char *old_label,
+			     struct commit *new_commit, const char *new_label)
+{
+	if (force)
+		return reset_tree(new_commit->tree, quiet, 1, wt_error);
+	else
+		return switch_trees(merge, quiet, wt_error,
+				    old_commit, old_label,
+				    new_commit, new_label);
+}
+
 struct branch_info {
 	const char *name; /* The short name used */
 	const char *path; /* The full name of a real branch */
@@ -457,14 +469,10 @@ static int merge_working_tree(struct checkout_opts *opts,
 	if (read_cache() < 0)
 		return error("corrupt index file");
 
-	if (opts->force)
-		ret = reset_tree(new->commit->tree, opts->quiet, 1,
-				 &opts->writeout_error);
-	else
-		ret = switch_trees(opts->merge, opts->quiet,
-				   &opts->writeout_error,
-				   old->commit, "local",
-				   new->commit, new->name);
+	ret = reset_index_and_worktree(opts->force, opts->merge, opts->quiet,
+				       &opts->writeout_error,
+				       old->commit, "local",
+				       new->commit, new->name);
 	if (ret)
 		return ret;
 
-- 
1.6.1.rc1.72.ga5ce6

--
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]

  Powered by Linux