[PATCH] git mv: try harder to keep index entries intact

Previous thread: [PATCH 1/2] clone: Add an option to set up a mirror by Johannes Schindelin on Friday, August 1, 2008 - 10:00 am. (9 messages)

Next thread: Re: [PATCH] git-svn now work with crlf convertion enabled. by Junio C Hamano on Friday, August 1, 2008 - 3:42 pm. (12 messages)
To: <gitster@...>, <pasky@...>, <git@...>
Date: Friday, August 1, 2008 - 12:49 pm

Some filesystems change the ctime during a rename(), for technical
reasons. Since this is the only change, the contents need not be
rehashed. So just update the ctime after renaming the entry.

This change requires rename_index_entry_at() to return the new
position.

As git-mv assumes that it runs in a non-bare repository, and is
marked as such in the cmd_struct in git.c, the changes do not have
to be guarded against running in a bare repository.

To test this properly, you need to run t7001 with the environment
variable TEST_CTIME_WITH_SLEEP set non-empty, since there is no way
to manipulate the ctime directly; we have to sleep.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

builtin-mv.c | 15 +++++++++++++--
cache.h | 2 +-
read-cache.c | 4 ++--
t/t7001-mv.sh | 10 ++++++++--
4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/builtin-mv.c b/builtin-mv.c
index 4f65b5a..166a019 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -214,8 +214,19 @@ int cmd_mv(int argc, const char **argv, const char *prefix)

pos = cache_name_pos(src, strlen(src));
assert(pos >= 0);
- if (!show_only)
- rename_cache_entry_at(pos, dst);
+ if (!show_only) {
+ struct stat st;
+ pos = rename_cache_entry_at(pos, dst);
+
+ /*
+ * Renaming can update the ctime. Do not force
+ * a complete rehash just because of that.
+ */
+ if (!lstat(dst, &st))
+ active_cache[pos]->ce_ctime = st.st_ctime;
+ else if (!ignore_errors)
+ die ("Could not stat '%s'", dst);
+ }
}

if (active_cache_changed) {
diff --git a/cache.h b/cache.h
index 8155ab8..4b6876b 100644
--- a/cache.h
+++ b/cache.h
@@ -371,7 +371,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name
#define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */
extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
extern struct cache_entry *refresh_cache_e...

Previous thread: [PATCH 1/2] clone: Add an option to set up a mirror by Johannes Schindelin on Friday, August 1, 2008 - 10:00 am. (9 messages)

Next thread: Re: [PATCH] git-svn now work with crlf convertion enabled. by Junio C Hamano on Friday, August 1, 2008 - 3:42 pm. (12 messages)