apply: simplify build_fake_ancestor()

The local variable sha1_ptr in the build_fake_ancestor() function used to either point at the null_sha1[] (if the ancestor did not have the path) or at sha1[] (if we read the object name into the local array), but 7a98869 (apply: get rid of --index-info in favor of --build-fake-ancestor, 2007-09-17) made the "missing in the ancestor" case unnecessary, hence sha1_ptr, when used, always points at the local array. Get rid of the unneeded variable, and restructure the if/else cascade a bit to make it easier to read. There should be no behaviour change. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 31, 2013 at 19:19 UTC e2afb0be9073fbe9f565ad9e952155c0bf7dd7c6
1 file changed +12 -14
builtin/apply.c
+12 -14
@@ -3598,7 +3598,6 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
3598 * worth showing the new sha1 prefix, but until then...
3599 */
3600 for (patch = list; patch; patch = patch->next) {
3601 - const unsigned char *sha1_ptr;
3601 unsigned char sha1[20];
3602 struct cache_entry *ce;
3603 const char *name;
@@ -3606,20 +3605,19 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
3605 name = patch->old_name ? patch->old_name : patch->new_name;
3606 if (0 < patch->is_new)
3607 continue;
3609 - else if (get_sha1_blob(patch->old_sha1_prefix, sha1))
3610 - /* git diff has no index line for mode/type changes */
3611 - if (!patch->lines_added && !patch->lines_deleted) {
3612 - if (get_current_sha1(patch->old_name, sha1))
3613 - die("mode change for %s, which is not "
3614 - "in current HEAD", name);
3615 - sha1_ptr = sha1;
3616 - } else
3617 - die("sha1 information is lacking or useless "
3618 - "(%s).", name);
3619 - else
3620 - sha1_ptr = sha1;
3608
3622 - ce = make_cache_entry(patch->old_mode, sha1_ptr, name, 0, 0);
3609 + if (!get_sha1_blob(patch->old_sha1_prefix, sha1)) {
3610 + ; /* ok */
3611 + } else if (!patch->lines_added && !patch->lines_deleted) {
3612 + /* mode-only change: update the current */
3613 + if (get_current_sha1(patch->old_name, sha1))
3614 + die("mode change for %s, which is not "
3615 + "in current HEAD", name);
3616 + } else
3617 + die("sha1 information is lacking or useless "
3618 + "(%s).", name);
3619 +
3620 + ce = make_cache_entry(patch->old_mode, sha1, name, 0, 0);
3621 if (!ce)
3622 die(_("make_cache_entry failed for path '%s'"), name);
3623 if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD))