summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0d641f7)
raw | patch | inline | side by side (parent: 0d641f7)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 12 Nov 2008 19:52:35 +0000 (11:52 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 12 Nov 2008 22:16:50 +0000 (14:16 -0800) |
Earlier commit 5521883 (checkout: do not lose staged removal, 2008-09-07)
tightened the rule to prevent switching branches from losing local
changes, so that staged removal of paths can be protected, while
attempting to keep a loophole to still allow a special case of switching
out of an un-checked-out state.
However, the loophole was made a bit too tight, and did not allow
switching from one branch (in an un-checked-out state) to check out
another branch.
The change to builtin-checkout.c in this commit loosens it to allow this,
by not insisting the original commit and the new commit to be the same.
It also introduces a new function, is_index_unborn (and an associated
macro, is_cache_unborn), to check if the repository is truly in an
un-checked-out state more reliably, by making sure that $GIT_INDEX_FILE
did not exist when populating the in-core index structure. A few places
the earlier commit 5521883 added the check for the initial checkout
condition are updated to use this function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tightened the rule to prevent switching branches from losing local
changes, so that staged removal of paths can be protected, while
attempting to keep a loophole to still allow a special case of switching
out of an un-checked-out state.
However, the loophole was made a bit too tight, and did not allow
switching from one branch (in an un-checked-out state) to check out
another branch.
The change to builtin-checkout.c in this commit loosens it to allow this,
by not insisting the original commit and the new commit to be the same.
It also introduces a new function, is_index_unborn (and an associated
macro, is_cache_unborn), to check if the repository is truly in an
un-checked-out state more reliably, by making sure that $GIT_INDEX_FILE
did not exist when populating the in-core index structure. A few places
the earlier commit 5521883 added the check for the initial checkout
condition are updated to use this function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-checkout.c | patch | blob | history | |
builtin-read-tree.c | patch | blob | history | |
cache.h | patch | blob | history | |
read-cache.c | patch | blob | history |
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 05eee4ecc71d7a20d9faf59c849d3c693ae4cc8d..25845cdd5e6ed47a726b4be57929b9ec4d348fff 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
}
/* 2-way merge to the new branch */
- topts.initial_checkout = (!active_nr &&
- (old->commit == new->commit));
+ topts.initial_checkout = is_cache_unborn();
topts.update = 1;
topts.merge = 1;
topts.gently = opts->merge;
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 0706c958181c54aeb18d91f6e3dbe7c9f572b94d..38fef34d3fb6c24ab89043951f1ecf6c96e9bf51 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
break;
case 2:
opts.fn = twoway_merge;
- opts.initial_checkout = !active_nr;
+ opts.initial_checkout = is_cache_unborn();
break;
case 3:
default:
index a1e4982cd424ec5c3695c2221583bca1bd861614..3960931a9559e9f292f4ea4f01488f7294057148 100644 (file)
--- a/cache.h
+++ b/cache.h
#define read_cache() read_index(&the_index)
#define read_cache_from(path) read_index_from(&the_index, (path))
+#define is_cache_unborn() is_index_unborn(&the_index)
#define read_cache_unmerged() read_index_unmerged(&the_index)
#define write_cache(newfd, cache, entries) write_index(&the_index, (newfd))
#define discard_cache() discard_index(&the_index)
/* Initialize and use the cache information */
extern int read_index(struct index_state *);
extern int read_index_from(struct index_state *, const char *path);
+extern int is_index_unborn(struct index_state *);
extern int read_index_unmerged(struct index_state *);
extern int write_index(const struct index_state *, int newfd);
extern int discard_index(struct index_state *);
diff --git a/read-cache.c b/read-cache.c
index 967f483f783693eff4fd4e252dae7a0cc8b12ada..525d138e90c524d08ef3d9755f1a2486c34adc39 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
die("index file corrupt");
}
+int is_index_unborn(struct index_state *istate)
+{
+ return (!istate->cache_nr && !istate->alloc && !istate->timestamp);
+}
+
int discard_index(struct index_state *istate)
{
istate->cache_nr = 0;