[PATCH 3/4] git-read-tree --set-base=<commit>

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

 



This allows the caller of read-tree to record the base commit
object in the index, so that later operations that build a new
commit based on the contents of the index can verify that the
HEAD is still at the expected place, and notice cases where
somebody else updated the tip of the current branch while we are
looking the other way.

Signed-off-by: Junio C Hamano <junkio@xxxxxxx>
---
 Documentation/git-read-tree.txt |    6 +++++-
 builtin-read-tree.c             |   19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-read-tree.txt b/Documentation/git-read-tree.txt
index 0ff2890..ef731e2 100644
--- a/Documentation/git-read-tree.txt
+++ b/Documentation/git-read-tree.txt
@@ -8,7 +8,7 @@ git-read-tree - Reads tree information into the index
 
 SYNOPSIS
 --------
-'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
+'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--set-base=<commit>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
 
 
 DESCRIPTION
@@ -86,6 +86,10 @@ OPTIONS
 	file (usually '.gitignore') and allows such an untracked
 	but explicitly ignored file to be overwritten.
 
+--set-base=<commit>::
+	This option records the commit object name in the index,
+	later to be retrieved with the `git-update-index --get-base`.
+
 <tree-ish#>::
 	The id of the tree object(s) to be read/merged.
 
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 06c2912..d1c4489 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -93,6 +93,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 {
 	int i, newfd, stage = 0;
 	unsigned char sha1[20];
+	unsigned char newbase[20];
+	int newbase_set = 0;
 	struct unpack_trees_options opts;
 
 	memset(&opts, 0, sizeof(opts));
@@ -158,6 +160,15 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 			continue;
 		}
 
+		if (!prefixcmp(arg, "--set-base=")) {
+			if (get_sha1(arg+11, newbase) ||
+			    sha1_object_info(newbase, NULL) != OBJ_COMMIT)
+				die("Specified base is not a valid commit object name '%s'",
+				    arg);
+			newbase_set = 1;
+			continue;
+		}
+
 		if (!strcmp(arg, "--trivial")) {
 			opts.trivial_merges_only = 1;
 			continue;
@@ -261,12 +272,20 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 	 * "-m ent" or "--reset ent" form), we can obtain a fully
 	 * valid cache-tree because the index must match exactly
 	 * what came from the tree.
+	 *
+	 * Also when we read from a single commit with --reset, the
+	 * index will be used to build a commit on top of it.
 	 */
 	if (trees && trees->item && !opts.prefix && (!opts.merge || (stage == 2))) {
 		cache_tree_free(&active_cache_tree);
 		prime_cache_tree();
 	}
 
+	if (newbase_set) {
+		active_cache_base_valid = 1;
+		hashcpy(active_cache_base, newbase);
+	}
+
 	if (write_cache(newfd, active_cache, active_nr) ||
 	    close(newfd) || commit_lock_file(&lock_file))
 		die("unable to write new index file");
-- 
1.5.1.730.g0d43be


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