apply: split load_preimage() helper function out

Given a patch for a single path, the function apply_data() reads the preimage in core, and applies the change represented in the patch. Separate out the first part that reads the preimage into a separate helper function load_preimage(). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 8, 2012 at 13:35 UTC 37b9c903eb825ca741ea0eddc942309f892b682f
1 file changed +12 -3
builtin/apply.c
+12 -3
@@ -3046,10 +3046,10 @@ static int checkout_target(struct cache_entry *ce, struct stat *st)
3046 return 0;
3047 }
3048
3049 -static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
3049 +static int load_preimage(struct image *image,
3050 + struct patch *patch, struct stat *st, struct cache_entry *ce)
3051 {
3052 struct strbuf buf = STRBUF_INIT;
3052 - struct image image;
3053 size_t len;
3054 char *img;
3055 struct patch *tpatch;
@@ -3086,7 +3086,16 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *
3086 }
3087
3088 img = strbuf_detach(&buf, &len);
3089 - prepare_image(&image, img, len, !patch->is_binary);
3089 + prepare_image(image, img, len, !patch->is_binary);
3090 + return 0;
3091 +}
3092 +
3093 +static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
3094 +{
3095 + struct image image;
3096 +
3097 + if (load_preimage(&image, patch, st, ce) < 0)
3098 + return -1;
3099
3100 if (apply_fragments(&image, patch) < 0)
3101 return -1; /* note with --reject this succeeds. */