diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-06 14:33:11 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-06 14:33:11 -0700 |
commit | 451322512f2f72fe07461a8aeae0df4cfce7fda1 (patch) | |
tree | e28e1450fe4e803c86532819d7e58e59fbb8d330 /read-tree.c | |
parent | d723c690637f2918d9861e8d602e592c5fa0bc5b (diff) | |
download | git-451322512f2f72fe07461a8aeae0df4cfce7fda1.tar.gz |
git-read-tree: some "final" cleanups
Looking good, but hey, it's not like I even have a real testcase for any
of this. But unlike the mess that this was yerstday, today read-cache
is pretty readable and understandable. Which is always a good sign.
Diffstat (limited to 'read-tree.c')
-rw-r--r-- | read-tree.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/read-tree.c b/read-tree.c index 4acbb6b3f2..2fb27e9743 100644 --- a/read-tree.c +++ b/read-tree.c @@ -221,7 +221,9 @@ static void check_updates(struct cache_entry **src, int nr) } } -static void merge_cache(struct cache_entry **src, int nr, int (*fn)(struct cache_entry **, struct cache_entry **)) +typedef int (*merge_fn_t)(struct cache_entry **, struct cache_entry **); + +static void merge_cache(struct cache_entry **src, int nr, merge_fn_t fn) { struct cache_entry **dst = src; @@ -296,20 +298,14 @@ int main(int argc, char **argv) stage++; } if (merge) { - switch (stage) { - case 4: /* Three-way merge */ - merge_cache(active_cache, active_nr, threeway_merge); - break; - case 3: /* Update from one tree to another */ - merge_cache(active_cache, active_nr, twoway_merge); - check_updates(active_cache, active_nr); - break; - case 2: /* Just read a tree, merge with old cache contents */ - merge_cache(active_cache, active_nr, oneway_merge); - break; - default: + static const merge_fn_t merge_function[] = { + [1] = oneway_merge, + [2] = twoway_merge, + [3] = threeway_merge, + }; + if (stage < 2 || stage > 4) die("just how do you expect me to merge %d trees?", stage-1); - } + merge_cache(active_cache, active_nr, merge_function[stage-1]); } if (write_cache(newfd, active_cache, active_nr) || commit_index_file(&cache_file)) |