{"thread":{"id":"4078","subject":"[PATCH/RFC (git-core)] update-index --again","startedAt":"2006-05-06T05:05:15Z","lastAt":"2006-05-06T05:05:15Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19593","messageId":"7vodybvj3o.fsf@assigned-by-dhcp.cox.net","threadId":"4078","inReplyTo":null,"subject":"[PATCH/RFC (git-core)] update-index --again","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-06T05:05:15Z","receivedAt":"2006-05-06T05:05:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"After running 'git-update-index' for some paths, you may want to\ndo the update on the same set of paths again.\n\nThe new flag --again checks the paths whose index entries are\nare different from the HEAD commit and updates them from the\nworking tree contents.\n\nThis was brought up by Carl Worth on #git.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n * I want to reorganize index file to contain both blob and tree\n   entries in not so distant future, so I probably should not be\n   doing something like this which _would_ need rework when that\n   happens, but I think what Carl wanted to do is a reasonable\n   thing to ask.\n\n   http://colabti.de/irclogger/irclogger_log/git?date=2006-05-05,Fri&sel=16#l31\n\n Documentation/git-update-index.txt |    6 ++-\n t/t2101-update-index-reupdate.sh   |   73 ++++++++++++++++++++++++++++++++++++\n update-index.c                     |   56 ++++++++++++++++++++++++++--\n 3 files changed, 131 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\nindex 57177c7..d043e86 100644\n--- a/Documentation/git-update-index.txt\n+++ b/Documentation/git-update-index.txt\n@@ -15,7 +15,7 @@ SYNOPSIS\n \t     [--cacheinfo <mode> <object> <file>]\\*\n \t     [--chmod=(+|-)x]\n \t     [--assume-unchanged | --no-assume-unchanged]\n-\t     [--really-refresh] [--unresolve]\n+\t     [--really-refresh] [--unresolve] [--again]\n \t     [--info-only] [--index-info]\n \t     [-z] [--stdin]\n \t     [--verbose]\n@@ -80,6 +80,10 @@ OPTIONS\n \tfilesystem that has very slow lstat(2) system call\n \t(e.g. cifs).\n \n+--again::\n+\tRuns `git-update-index` itself on the paths whose index\n+\tentries are different from those from the `HEAD` commit.\n+\n --unresolve::\n \tRestores the 'unmerged' or 'needs updating' state of a\n \tfile during a merge if it was cleared by accident.\ndiff --git a/t/t2101-update-index-reupdate.sh b/t/t2101-update-index-reupdate.sh\nnew file mode 100755\nindex 0000000..5c505c6\n--- /dev/null\n+++ b/t/t2101-update-index-reupdate.sh\n@@ -0,0 +1,73 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006 Junio C Hamano\n+#\n+\n+test_description='git-update-index --again test.\n+'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'update-index --add' \\\n+\t'echo hello world >file1 &&\n+\t echo goodbye people >file2 &&\n+\t git-update-index --add file1 file2 &&\n+\t git-ls-files -s >current &&\n+\t cmp current - <<\\EOF\n+100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0\tfile1\n+100644 9db8893856a8a02eaa73470054b7c1c5a7c82e47 0\tfile2\n+EOF'\n+\n+test_expect_success 'update-index --again' \\\n+\t'rm -f file1 &&\n+\techo hello everybody >file2 &&\n+\tif git-update-index --again\n+\tthen\n+\t\techo should have refused to remove file1\n+\t\texit 1\n+\telse\n+\t\techo happy - failed as expected\n+\tfi &&\n+\t git-ls-files -s >current &&\n+\t cmp current - <<\\EOF\n+100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0\tfile1\n+100644 9db8893856a8a02eaa73470054b7c1c5a7c82e47 0\tfile2\n+EOF'\n+\n+test_expect_success 'update-index --remove --again' \\\n+\t'git-update-index --remove --again &&\n+\t git-ls-files -s >current &&\n+\t cmp current - <<\\EOF\n+100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0\tfile2\n+EOF'\n+\n+test_expect_success 'first commit' 'git-commit -m initial'\n+\n+test_expect_success 'update-index again' \\\n+\t'mkdir -p dir1 &&\n+\techo hello world >dir1/file3 &&\n+\techo goodbye people >file2 &&\n+\tgit-update-index --add file2 dir1/file3 &&\n+\techo hello everybody >file2\n+\techo happy >dir1/file3 &&\n+\tgit-update-index --again &&\n+\tgit-ls-files -s >current &&\n+\tcmp current - <<\\EOF\n+100644 53ab446c3f4e42ce9bb728a0ccb283a101be4979 0\tdir1/file3\n+100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0\tfile2\n+EOF'\n+\n+test_expect_success 'update-index --update from subdir' \\\n+\t'echo not so happy >file2 &&\n+\tcd dir1 &&\n+\tcat ../file2 >file3 &&\n+\tgit-update-index --again &&\n+\tcd .. &&\n+\tgit-ls-files -s >current &&\n+\tcmp current - <<\\EOF\n+100644 d7fb3f695f06c759dbf3ab00046e7cc2da22d10f 0\tdir1/file3\n+100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0\tfile2\n+EOF'\n+\n+test_done\n+\ndiff --git a/update-index.c b/update-index.c\nindex 1870ac7..e6c460b 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -473,7 +473,7 @@ static void read_index_info(int line_ter\n }\n \n static const char update_index_usage[] =\n-\"git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--ignore-missing] [-z] [--verbose] [--] <file>...\";\n+\"git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--again] [--ignore-missing] [-z] [--verbose] [--] <file>...\";\n \n static unsigned char head_sha1[20];\n static unsigned char merge_head_sha1[20];\n@@ -488,11 +488,13 @@ static struct cache_entry *read_one_ent(\n \tstruct cache_entry *ce;\n \n \tif (get_tree_entry(ent, path, sha1, &mode)) {\n-\t\terror(\"%s: not in %s branch.\", path, which);\n+\t\tif (which)\n+\t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n \tif (mode == S_IFDIR) {\n-\t\terror(\"%s: not a blob in %s branch.\", path, which);\n+\t\tif (which)\n+\t\t\terror(\"%s: not a blob in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n \tsize = cache_entry_size(namelen);\n@@ -597,6 +599,47 @@ static int do_unresolve(int ac, const ch\n \treturn err;\n }\n \n+static int do_reupdate(int ac, const char **av,\n+\t\t       const char *prefix, int prefix_length)\n+{\n+\t/* Read HEAD and run update-index on paths that are\n+\t * merged and already different between index and HEAD.\n+\t */\n+\tint pos;\n+\tint has_head = 1;\n+\n+\tif (read_ref(git_path(\"HEAD\"), head_sha1))\n+\t\t/* If there is no HEAD, that means it is an initial\n+\t\t * commit.  Update everything in the index.\n+\t\t */\n+\t\thas_head = 0;\n+ redo:\n+\tfor (pos = 0; pos < active_nr; pos++) {\n+\t\tstruct cache_entry *ce = active_cache[pos];\n+\t\tstruct cache_entry *old = NULL;\n+\t\tint save_nr;\n+\t\tif (ce_stage(ce))\n+\t\t\tcontinue;\n+\t\tif (has_head)\n+\t\t\told = read_one_ent(NULL, head_sha1,\n+\t\t\t\t\t   ce->name, ce_namelen(ce), 0);\n+\t\tif (old && ce->ce_mode == old->ce_mode &&\n+\t\t    !memcmp(ce->sha1, old->sha1, 20)) {\n+\t\t\tfree(old);\n+\t\t\tcontinue; /* unchanged */\n+\t\t}\n+\t\t/* Be careful.  The working tree may not have the\n+\t\t * path anymore, in which case, under 'allow_remove',\n+\t\t * or worse yet 'allow_replace', active_nr may decrease.\n+\t\t */\n+\t\tsave_nr = active_nr;\n+\t\tupdate_one(ce->name + prefix_length, prefix, prefix_length);\n+\t\tif (save_nr != active_nr)\n+\t\t\tgoto redo;\n+\t}\n+\treturn 0;\n+}\n+\n int main(int argc, const char **argv)\n {\n \tint i, newfd, entries, has_errors = 0, line_termination = '\\n';\n@@ -714,6 +757,13 @@ int main(int argc, const char **argv)\n \t\t\t\t\tactive_cache_changed = 0;\n \t\t\t\tgoto finish;\n \t\t\t}\n+\t\t\tif (!strcmp(path, \"--again\")) {\n+\t\t\t\thas_errors = do_reupdate(argc - i, argv + i,\n+\t\t\t\t\t\t\t prefix, prefix_length);\n+\t\t\t\tif (has_errors)\n+\t\t\t\t\tactive_cache_changed = 0;\n+\t\t\t\tgoto finish;\n+\t\t\t}\n \t\t\tif (!strcmp(path, \"--ignore-missing\")) {\n \t\t\t\tnot_new = 1;\n \t\t\t\tcontinue;\n-- \n1.3.2.g2749\n"}]}