aboutsummaryrefslogtreecommitdiff
path: root/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-05-05 17:40:47 -0700
committerJunio C Hamano <junkio@cox.net>2006-05-05 22:57:27 -0700
commit83e77a25dc194933c0fb7908ab6d9fb84a5045e2 (patch)
tree37764549596cbbeb323a7afb5da8fb77eba93fd8 /update-index.c
parentfb69a760cc9103d1f8341a3c8ea09bd15a8a412d (diff)
downloadgit-83e77a25dc194933c0fb7908ab6d9fb84a5045e2.tar.gz
git-83e77a25dc194933c0fb7908ab6d9fb84a5045e2.tar.xz
update-index --again
After running 'git-update-index' for some paths, you may want to do the update on the same set of paths again. The new flag --again checks the paths whose index entries are are different from the HEAD commit and updates them from the working tree contents. This was brought up by Carl Worth on #git. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r--update-index.c56
1 files changed, 53 insertions, 3 deletions
diff --git a/update-index.c b/update-index.c
index d63f8ac99..5496d68ae 100644
--- a/update-index.c
+++ b/update-index.c
@@ -476,7 +476,7 @@ static void read_index_info(int line_termination)
}
static const char update_index_usage[] =
-"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>...";
+"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>...";
static unsigned char head_sha1[20];
static unsigned char merge_head_sha1[20];
@@ -491,11 +491,13 @@ static struct cache_entry *read_one_ent(const char *which,
struct cache_entry *ce;
if (get_tree_entry(ent, path, sha1, &mode)) {
- error("%s: not in %s branch.", path, which);
+ if (which)
+ error("%s: not in %s branch.", path, which);
return NULL;
}
if (mode == S_IFDIR) {
- error("%s: not a blob in %s branch.", path, which);
+ if (which)
+ error("%s: not a blob in %s branch.", path, which);
return NULL;
}
size = cache_entry_size(namelen);
@@ -600,6 +602,47 @@ static int do_unresolve(int ac, const char **av,
return err;
}
+static int do_reupdate(int ac, const char **av,
+ const char *prefix, int prefix_length)
+{
+ /* Read HEAD and run update-index on paths that are
+ * merged and already different between index and HEAD.
+ */
+ int pos;
+ int has_head = 1;
+
+ if (read_ref(git_path("HEAD"), head_sha1))
+ /* If there is no HEAD, that means it is an initial
+ * commit. Update everything in the index.
+ */
+ has_head = 0;
+ redo:
+ for (pos = 0; pos < active_nr; pos++) {
+ struct cache_entry *ce = active_cache[pos];
+ struct cache_entry *old = NULL;
+ int save_nr;
+ if (ce_stage(ce))
+ continue;
+ if (has_head)
+ old = read_one_ent(NULL, head_sha1,
+ ce->name, ce_namelen(ce), 0);
+ if (old && ce->ce_mode == old->ce_mode &&
+ !memcmp(ce->sha1, old->sha1, 20)) {
+ free(old);
+ continue; /* unchanged */
+ }
+ /* Be careful. The working tree may not have the
+ * path anymore, in which case, under 'allow_remove',
+ * or worse yet 'allow_replace', active_nr may decrease.
+ */
+ save_nr = active_nr;
+ update_one(ce->name + prefix_length, prefix, prefix_length);
+ if (save_nr != active_nr)
+ goto redo;
+ }
+ return 0;
+}
+
int main(int argc, const char **argv)
{
int i, newfd, entries, has_errors = 0, line_termination = '\n';
@@ -717,6 +760,13 @@ int main(int argc, const char **argv)
active_cache_changed = 0;
goto finish;
}
+ if (!strcmp(path, "--again")) {
+ has_errors = do_reupdate(argc - i, argv + i,
+ prefix, prefix_length);
+ if (has_errors)
+ active_cache_changed = 0;
+ goto finish;
+ }
if (!strcmp(path, "--ignore-missing")) {
not_new = 1;
continue;