From: Junio C Hamano Date: Tue, 11 Oct 2016 21:18:32 +0000 (-0700) Subject: Merge branch 'rs/copy-array' into maint X-Git-Tag: v2.10.2~37 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/a813b19190a75e44b6ebd1ea5317ef5ed914cde0?hp=-c Merge branch 'rs/copy-array' into maint Code cleanup. * rs/copy-array: use COPY_ARRAY add COPY_ARRAY --- a813b19190a75e44b6ebd1ea5317ef5ed914cde0 diff --combined builtin/mv.c index 446a316738,c13e49bf47..2f43877bc9 --- a/builtin/mv.c +++ b/builtin/mv.c @@@ -26,7 -26,7 +26,7 @@@ static const char **internal_copy_paths int i; const char **result; ALLOC_ARRAY(result, count + 1); - memcpy(result, pathspec, count * sizeof(const char *)); + COPY_ARRAY(result, pathspec, count); result[count] = NULL; for (i = 0; i < count; i++) { int length = strlen(result[i]); @@@ -104,7 -104,7 +104,7 @@@ static int index_range_of_same_dir(cons int cmd_mv(int argc, const char **argv, const char *prefix) { - int i, gitmodules_modified = 0; + int i, flags, gitmodules_modified = 0; int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), @@@ -134,13 -134,10 +134,13 @@@ modes = xcalloc(argc, sizeof(enum update_mode)); /* * Keep trailing slash, needed to let - * "git mv file no-such-dir/" error out. + * "git mv file no-such-dir/" error out, except in the case + * "git mv directory no-such-dir/". */ - dest_path = internal_copy_pathspec(prefix, argv + argc, 1, - KEEP_TRAILING_SLASH); + flags = KEEP_TRAILING_SLASH; + if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1])) + flags = 0; + dest_path = internal_copy_pathspec(prefix, argv + argc, 1, flags); submodule_gitfile = xcalloc(argc, sizeof(char *)); if (dest_path[0][0] == '\0') diff --combined commit.c index ba6dee37aa,9d3d7119e0..aada266f9a --- a/commit.c +++ b/commit.c @@@ -931,7 -931,7 +931,7 @@@ static int remove_redundant(struct comm } /* Now collect the result */ - memcpy(work, array, sizeof(*array) * cnt); + COPY_ARRAY(work, array, cnt); for (i = filled = 0; i < cnt; i++) if (!redundant[i]) array[filled++] = work[i]; @@@ -1576,15 -1576,6 +1576,15 @@@ int commit_tree_extended(const char *ms return result; } +void set_merge_remote_desc(struct commit *commit, + const char *name, struct object *obj) +{ + struct merge_remote_desc *desc; + FLEX_ALLOC_STR(desc, name, name); + desc->obj = obj; + commit->util = desc; +} + struct commit *get_merge_parent(const char *name) { struct object *obj; @@@ -1594,8 -1585,13 +1594,8 @@@ return NULL; obj = parse_object(oid.hash); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); - if (commit && !commit->util) { - struct merge_remote_desc *desc; - desc = xmalloc(sizeof(*desc)); - desc->obj = obj; - desc->name = strdup(name); - commit->util = desc; - } + if (commit && !commit->util) + set_merge_remote_desc(commit, name, obj); return commit; } @@@ -1626,6 -1622,16 +1626,6 @@@ struct commit_list **commit_list_append return &new->next; } -void print_commit_list(struct commit_list *list, - const char *format_cur, - const char *format_last) -{ - for ( ; list; list = list->next) { - const char *format = list->next ? format_cur : format_last; - printf(format, oid_to_hex(&list->item->object.oid)); - } -} - const char *find_commit_header(const char *msg, const char *key, size_t *out_len) { int key_len = strlen(key); diff --combined git-compat-util.h index 2c949983dc,4662d0d3c4..aec8cc9890 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -436,7 -436,6 +436,7 @@@ static inline int const_error(void return -1; } #define error(...) (error(__VA_ARGS__), const_error()) +#define error_errno(...) (error_errno(__VA_ARGS__), const_error()) #endif extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); @@@ -664,22 -663,10 +664,22 @@@ void *gitmemmem(const void *haystack, s const void *needle, size_t needlelen); #endif +#ifdef OVERRIDE_STRDUP +#ifdef strdup +#undef strdup +#endif +#define strdup gitstrdup +char *gitstrdup(const char *s); +#endif + #ifdef NO_GETPAGESIZE #define getpagesize() sysconf(_SC_PAGESIZE) #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + #ifdef FREAD_READS_DIRECTORIES #ifdef fopen #undef fopen @@@ -798,6 -785,14 +798,14 @@@ extern FILE *fopen_for_writing(const ch #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc))) #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc))) + #define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \ + BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src)))) + static inline void copy_array(void *dst, const void *src, size_t n, size_t size) + { + if (n) + memcpy(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: @@@ -828,7 -823,7 +836,7 @@@ * you can do: * * struct foo *f; - * FLEX_ALLOC_STR(f, name, src); + * FLEXPTR_ALLOC_STR(f, name, src); * * and "name" will point to a block of memory after the struct, which will be * freed along with the struct (but the pointer can be repointed anywhere). @@@ -974,19 -969,6 +982,19 @@@ void git_qsort(void *base, size_t nmemb #define qsort git_qsort #endif +#ifndef REG_STARTEND +#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd" +#endif + +static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size, + size_t nmatch, regmatch_t pmatch[], int eflags) +{ + assert(nmatch > 0 && pmatch); + pmatch[0].rm_so = 0; + pmatch[0].rm_eo = size; + return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); +} + #ifndef DIR_HAS_BSD_GROUP_SEMANTICS # define FORCE_DIR_SET_GID S_ISGID #else @@@ -1088,5 -1070,3 +1096,5 @@@ struct tm *git_gmtime_r(const time_t * #endif #endif + +extern int cmd_main(int, const char **);