[PATCH] Preserve ORIG_HEAD if already up-to-date with remote.

DORMANTno replies

2 messages, 1 author, 2016-06-15 · open the first message on its own page

[PATCH] Preserve ORIG_HEAD if already up-to-date with remote.

From: Kunal Gangakhedkar <hidden>
Date: 2016-06-15 22:51:28

By default, the ORIG_HEAD ref is moved to point to HEAD during a merge.
If there are no changes (i.e. if the local is in sync with remote), it
becomes difficult to see the last set of changes as the range of commits
is lost.

This is especially true when the pull is performed via a cronjob or a
script.

Following this mail is a patch that tries to address the problem 
by not updating the ORIG_HEAD ref when it detects an empty merge
(i.e. local is in sync with the remote).
That way, one can still do diffstat/log between ORIG_HEAD..HEAD.

It's still possible to revert to old behavior with:
o. --force-update-orig-head cmd line option
o. merge.forceupdateorighead config option

Please review the patch and let me know if:
a) it makes sense to have this functionality
b) if the patch looks OK

Please let me know if there are any changes required.
I'll write the test cases and send them in another mail later.

Thanks,
Kunal

Kunal Gangakhedkar (1):
  merge: Preserve ORIG_HEAD if already up-to-date with remote.

 builtin/merge.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

-- 
1.7.6.rc1.2.g20c4a.dirty

[PATCH] merge: Preserve ORIG_HEAD if already up-to-date with remote.

From: Kunal Gangakhedkar <hidden>
Date: 2016-06-15 22:51:28

Do not update ORIG_HEAD ref to current HEAD if the repo is already
in-sync with the remote.

Otherwise, it becomes difficult to keep track of last set of changes.

With this patch, it's possible to do a diffstat/log for last set of
changes even after a pull/merge that returns 'Already up-to-date'.
This is especially useful when the pull is performed via a cronjob/script.

The old behaviour can still be forced via:
o. --force-update-orig-head cmd line option
o. merge.forceupdateorighead config option

Signed-off-by: Kunal Gangakhedkar <redacted>
---
 builtin/merge.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 325891e..6ac26f0 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -63,6 +63,7 @@ static int allow_rerere_auto;
 static int abort_current_merge;
 static int show_progress = -1;
 static int default_to_upstream;
+static int force_update_orig_head = 0;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -206,6 +207,8 @@ static struct option builtin_merge_options[] = {
 	OPT_BOOLEAN(0, "abort", &abort_current_merge,
 		"abort the current in-progress merge"),
 	OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
+	OPT_BOOLEAN(0, "force-update-orig-head", &force_update_orig_head,
+			"force-update ORIG_HEAD even if in sync with remote"),
 	OPT_END()
 };
 
@@ -563,7 +566,11 @@ static int git_merge_config(const char *k, const char *v, void *cb)
 	} else if (!strcmp(k, "merge.defaulttoupstream")) {
 		default_to_upstream = git_config_bool(k, v);
 		return 0;
+	} else if (!strcmp(k, "merge.forceupdateorighead")) {
+		force_update_orig_head = git_config_bool(k, v);
+		return 0;
 	}
+
 	return git_diff_ui_config(k, v, cb);
 }
 
@@ -1017,6 +1024,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	struct commit_list *common = NULL;
 	const char *best_strategy = NULL, *wt_strategy = NULL;
 	struct commit_list **remotes = &remoteheads;
+	int orig_head_updated = 0;
 
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage_with_options(builtin_merge_usage, builtin_merge_options);
@@ -1212,8 +1220,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		free(list);
 	}
 
-	update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
-		DIE_ON_ERR);
+	if (force_update_orig_head) {
+		update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+			DIE_ON_ERR);
+		orig_head_updated = 1;
+	}
 
 	if (!common)
 		; /* No common ancestors found. We need a real merge. */
@@ -1254,6 +1265,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 
 		finish(o->sha1, msg.buf);
 		drop_save();
+		if (!orig_head_updated) {
+			update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+				DIE_ON_ERR);
+			orig_head_updated = 1;
+		}
 		return 0;
 	} else if (!remoteheads->next && common->next)
 		;
@@ -1306,6 +1322,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 	}
 
+	if (!orig_head_updated) {
+		update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+			DIE_ON_ERR);
+		orig_head_updated = 1;
+	}
+
 	if (fast_forward_only)
 		die(_("Not possible to fast-forward, aborting."));
 
-- 
1.7.6.rc1.2.g20c4a.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help