git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-mv: Keep moved index entries inact

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 19, 2008, 23:54 UTC
Message-ID
<7vej5pwhub.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080717223036.20680.9672.stgit@localhost>
Petr Baudis <pasky@suse.cz> writes:
Show 5 quoted lines
> A new test has been added to the testsuite to reflect this change.
> Also, based on suggestion by Junio about desired symlink behaviour
> of git mv, I have added two tests for that; however, I do not have
> need or desire to spend time fixing this, so they are expected
> to fail for now until someone gets around to fixing that.
Well, somebody would eventually come to help, then ;-).
Show 5 quoted lines
>  builtin-mv.c  |   62 ++++++++-------------------------------------------------
>  cache.h       |    2 ++
>  read-cache.c  |   15 ++++++++++++++
>  t/t7001-mv.sh |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 83 insertions(+), 53 deletions(-)
Very nice code reduction, isn't it?
Show 22 quoted lines
> diff --git a/read-cache.c b/read-cache.c
> index 1648428..70e5f57 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -38,6 +38,21 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
>  	istate->cache_changed = 1;
>  }
>  
> +void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name)
> +{
> +	struct cache_entry *old = istate->cache[nr], *new;
> +	int namelen = strlen(new_name);
> +
> +	new = xmalloc(cache_entry_size(namelen));
> +	copy_cache_entry(new, old);
> +	new->ce_flags = (new->ce_flags & ~CE_NAMEMASK) | namelen;
> +	memcpy(new->name, new_name, namelen);
> +
> +	cache_tree_invalidate_path(istate->cache_tree, old->name);
> +	remove_index_entry_at(istate, nr);
> +	add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
> +}

Hmm, would this use of copy_cache_entry() kosher, I have to wonder. This new copy of cache entry begins its life unhashed, doesn't it? Shouldn't we be not copying its hashed/unhashed bits from the old one?

Also setting of that ce_flags looks wrong when namelen does not fit within the width of CE_NAMEMASK. Shouldn't it be doing the same thing as create_ce_flags()?

Show 9 quoted lines
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> index 336cfaa..6b615f8 100755
> --- a/t/t7001-mv.sh
> +++ b/t/t7001-mv.sh
> @@ -156,4 +156,61 @@ test_expect_success 'absolute pathname outside should fail' '(
>  
>  )'
>  
> +# git mv meets angry Git maintainer
What's this comment about?
Show 7 quoted lines
> +test_expect_success 'git mv should not change sha1 of moved cache entry' '
> +
> +	rm -fr .git &&
> +	git init &&
> +	echo 1 >dirty &&
> +	git add dirty &&
> +	entry="$(git ls-files --stage dirty | cut -f 1)"
"rev-parse :dirty"?
Previous: Petr BaudisNext: Petr Baudis
Message 11 of 56 in “Submodule support in git mv, git rm”
  1. Petr BaudisJul 16, 2008
  2. 1/7 git-mv: Remove dead code branchPetr Baudis, Jul 16, 2008
  3. 2/7 t7400: Add short "git submodule add" testsuitePetr Baudis, Jul 16, 2008
  4. 3/7 git submodule add: Fix naming clash handlingPetr Baudis, Jul 16, 2008
  5. 4/7 submodule.*: Introduce simple C interface for submodule lookup by pathPetr Baudis, Jul 16, 2008
  6. 5/7 git mv: Support moving submodulesPetr Baudis, Jul 16, 2008
  7. Junio C HamanoJul 17, 2008
  8. Petr BaudisJul 17, 2008
  9. git-mv: Keep moved index entries inactPetr Baudis, Jul 17, 2008
  10. git mv: Support moving submodulesPetr Baudis, Jul 17, 2008
  11. Junio C HamanoJul 19, 2008
  12. Petr BaudisJul 21, 2008
  13. [PATCHv2] git-mv: Keep moved index entries inactPetr Baudis, Jul 21, 2008
  14. Junio C HamanoJul 21, 2008
  15. Junio C HamanoJul 26, 2008
  16. Petr BaudisJul 27, 2008
  17. t/t7001-mv.sh: Propose ability to use git-mv on conflicting entriesPetr Baudis, Jul 27, 2008
  18. Junio C HamanoJul 28, 2008
  19. Junio C HamanoJul 28, 2008
  20. SZEDER GáborJul 28, 2008
  21. Johannes SchindelinJul 28, 2008
  22. Johannes SchindelinJul 28, 2008
  23. Johannes SchindelinJul 28, 2008
  24. Junio C HamanoJul 28, 2008
  25. Johannes SchindelinJul 28, 2008
  26. Johannes SchindelinJul 28, 2008
  27. Petr BaudisJul 29, 2008
  28. Junio C HamanoJul 29, 2008
  29. Junio C HamanoJul 29, 2008
  30. Not going beyond symbolic linksJunio C Hamano, Aug 4, 2008
  31. 1/2 update-index: refuse to add working tree items beyond symlinksJunio C Hamano, Aug 4, 2008
  32. 2/2 add: refuse to add working tree items beyond symlinksJunio C Hamano, Aug 4, 2008
  33. Linus TorvaldsAug 5, 2008
  34. Junio C HamanoAug 5, 2008
  35. Linus TorvaldsAug 5, 2008
  36. Johannes SchindelinAug 5, 2008
  37. Linus TorvaldsAug 5, 2008
  38. Junio C HamanoAug 5, 2008
  39. Dmitry PotapovAug 5, 2008
  40. Junio C HamanoAug 5, 2008
  41. Linus TorvaldsAug 5, 2008
  42. Junio C HamanoAug 5, 2008
  43. Johannes SchindelinAug 5, 2008
  44. Junio C HamanoAug 5, 2008
  45. david@lang.hmAug 5, 2008
  46. Junio C HamanoAug 7, 2008
  47. Junio C HamanoAug 8, 2008
  48. Linus TorvaldsAug 8, 2008
  49. Johannes SchindelinJul 21, 2008
  50. Petr BaudisJul 21, 2008
  51. Junio C HamanoJul 21, 2008
  52. 6/7 git rm: Support for removing submodulesPetr Baudis, Jul 16, 2008
  53. Johannes SchindelinJul 16, 2008
  54. Petr BaudisJul 17, 2008
  55. Johannes SchindelinJul 17, 2008
  56. 7/7 t7403: Submodule git mv, git rm testsuitePetr Baudis, Jul 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.