Skip to content

Commit

Permalink
apply: simplify build_fake_ancestor()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 1, 2013
1 parent 4ae6d46 commit e2afb0b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3598,28 +3598,26 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
* worth showing the new sha1 prefix, but until then...
*/
for (patch = list; patch; patch = patch->next) {
const unsigned char *sha1_ptr;
unsigned char sha1[20];
struct cache_entry *ce;
const char *name;

name = patch->old_name ? patch->old_name : patch->new_name;
if (0 < patch->is_new)
continue;
else if (get_sha1_blob(patch->old_sha1_prefix, sha1))
/* git diff has no index line for mode/type changes */
if (!patch->lines_added && !patch->lines_deleted) {
if (get_current_sha1(patch->old_name, sha1))
die("mode change for %s, which is not "
"in current HEAD", name);
sha1_ptr = sha1;
} else
die("sha1 information is lacking or useless "
"(%s).", name);
else
sha1_ptr = sha1;

ce = make_cache_entry(patch->old_mode, sha1_ptr, name, 0, 0);
if (!get_sha1_blob(patch->old_sha1_prefix, sha1)) {
; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */
if (get_current_sha1(patch->old_name, sha1))
die("mode change for %s, which is not "
"in current HEAD", name);
} else
die("sha1 information is lacking or useless "
"(%s).", name);

ce = make_cache_entry(patch->old_mode, sha1, name, 0, 0);
if (!ce)
die(_("make_cache_entry failed for path '%s'"), name);
if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD))
Expand Down

0 comments on commit e2afb0b

Please sign in to comment.