From: Junio C Hamano Date: Fri, 11 Aug 2017 20:26:57 +0000 (-0700) Subject: Merge branch 'rs/move-array' X-Git-Tag: v2.15.0-rc0~209 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/32f90258bd510d84dfe8970211ec1427e9e327dc?hp=-c Merge branch 'rs/move-array' Code clean-up. * rs/move-array: ls-files: don't try to prune an empty index apply: use COPY_ARRAY and MOVE_ARRAY in update_image() use MOVE_ARRAY add MOVE_ARRAY --- 32f90258bd510d84dfe8970211ec1427e9e327dc diff --combined apply.c index 9889b47d6a,40707ca50c..41ee63e1db --- a/apply.c +++ b/apply.c @@@ -2809,13 -2809,10 +2809,10 @@@ static void update_image(struct apply_s img->line_allocated = img->line; } if (preimage_limit != postimage->nr) - memmove(img->line + applied_pos + postimage->nr, - img->line + applied_pos + preimage_limit, - (img->nr - (applied_pos + preimage_limit)) * - sizeof(*img->line)); - memcpy(img->line + applied_pos, - postimage->line, - postimage->nr * sizeof(*img->line)); + MOVE_ARRAY(img->line + applied_pos + postimage->nr, + img->line + applied_pos + preimage_limit, + img->nr - (applied_pos + preimage_limit)); + COPY_ARRAY(img->line + applied_pos, postimage->line, postimage->nr); if (!state->allow_overlap) for (i = 0; i < postimage->nr; i++) img->line[applied_pos + i].flag |= LINE_PATCHED; @@@ -3551,7 -3548,7 +3548,7 @@@ static int try_threeway(struct apply_st /* Preimage the patch was prepared for */ if (patch->is_new) write_sha1_file("", 0, blob_type, pre_oid.hash); - else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) || + else if (get_oid(patch->old_sha1_prefix, &pre_oid) || read_blob_object(&buf, &pre_oid, patch->old_mode)) return error(_("repository lacks the necessary blob to fall back on 3-way merge.")); @@@ -4075,7 -4072,7 +4072,7 @@@ static int build_fake_ancestor(struct a else return error(_("sha1 information is lacking or " "useless for submodule %s"), name); - } else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) { + } else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) { ; /* ok */ } else if (!patch->lines_added && !patch->lines_deleted) { /* mode-only change: update the current */ diff --combined commit.c index b0bb356731,d3150d6270..8b28415939 --- a/commit.c +++ b/commit.c @@@ -59,7 -59,7 +59,7 @@@ struct commit *lookup_commit_reference_ struct object_id oid; struct commit *commit; - if (get_sha1_committish(name, oid.hash)) + if (get_oid_committish(name, &oid)) return NULL; commit = lookup_commit_reference(&oid); if (parse_commit(commit)) @@@ -199,11 -199,11 +199,11 @@@ static void prepare_commit_graft(void commit_graft_prepared = 1; } -struct commit_graft *lookup_commit_graft(const unsigned char *sha1) +struct commit_graft *lookup_commit_graft(const struct object_id *oid) { int pos; prepare_commit_graft(); - pos = commit_graft_pos(sha1); + pos = commit_graft_pos(oid->hash); if (pos < 0) return NULL; return commit_graft[pos]; @@@ -223,9 -223,8 +223,8 @@@ int unregister_shallow(const struct obj if (pos < 0) return -1; if (pos + 1 < commit_graft_nr) - memmove(commit_graft + pos, commit_graft + pos + 1, - sizeof(struct commit_graft *) - * (commit_graft_nr - pos - 1)); + MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1, + commit_graft_nr - pos - 1); commit_graft_nr--; return 0; } @@@ -335,7 -334,7 +334,7 @@@ int parse_commit_buffer(struct commit * bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; - graft = lookup_commit_graft(item->object.oid.hash); + graft = lookup_commit_graft(&item->object.oid); while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { struct commit *new_parent; @@@ -1587,7 -1586,7 +1586,7 @@@ struct commit *get_merge_parent(const c struct object *obj; struct commit *commit; struct object_id oid; - if (get_sha1(name, oid.hash)) + if (get_oid(name, &oid)) return NULL; obj = parse_object(&oid); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); diff --combined git-compat-util.h index db9c22de76,159f82154a..7d2c0ca759 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -189,9 -189,6 +189,9 @@@ #include #endif +#if defined(__CYGWIN__) +#include "compat/cygwin.h" +#endif #if defined(__MINGW32__) /* pull in Windows compatibility stuff */ #include "compat/mingw.h" @@@ -828,6 -825,14 +828,14 @@@ static inline void copy_array(void *dst memcpy(dst, src, st_mult(size, n)); } + #define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \ + BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src)))) + static inline void move_array(void *dst, const void *src, size_t n, size_t size) + { + if (n) + memmove(dst, src, st_mult(size, n)); + } + /* * These functions help you allocate structs with flex arrays, and copy * the data directly into the array. For example, if you had: