From: Junio C Hamano Date: Mon, 3 Oct 2016 20:30:33 +0000 (-0700) Subject: Merge branch 'rs/copy-array' X-Git-Tag: v2.11.0-rc0~95 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b1f0a856605981363053941b8210f3cc9389607a?ds=inline;hp=-c Merge branch 'rs/copy-array' Code cleanup. * rs/copy-array: use COPY_ARRAY add COPY_ARRAY --- b1f0a856605981363053941b8210f3cc9389607a 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 8eb17075f7,9d3d7119e0..856fd4aeef --- 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]; @@@ -1511,9 -1511,9 +1511,9 @@@ static int verify_utf8(struct strbuf *b } static const char commit_utf8_warn[] = -"Warning: commit message did not conform to UTF-8.\n" -"You may want to amend it after fixing the message, or set the config\n" -"variable i18n.commitencoding to the encoding your project uses.\n"; +N_("Warning: commit message did not conform to UTF-8.\n" + "You may want to amend it after fixing the message, or set the config\n" + "variable i18n.commitencoding to the encoding your project uses.\n"); int commit_tree_extended(const char *msg, size_t msg_len, const unsigned char *tree, @@@ -1566,7 -1566,7 +1566,7 @@@ /* And check the encoding */ if (encoding_is_utf8 && !verify_utf8(&buffer)) - fprintf(stderr, commit_utf8_warn); + fprintf(stderr, _(commit_utf8_warn)); if (sign_commit && do_sign_commit(&buffer, sign_commit)) return -1; @@@ -1576,15 -1576,6 +1576,15 @@@ 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 8aab0c3047,4662d0d3c4..0ce2cdfb98 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -436,14 -436,10 +436,14 @@@ 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)); extern void set_error_routine(void (*routine)(const char *err, va_list params)); +extern void (*get_error_routine(void))(const char *err, va_list params); +extern void set_warn_routine(void (*routine)(const char *warn, va_list params)); +extern void (*get_warn_routine(void))(const char *warn, va_list params); extern void set_die_is_recursing_routine(int (*routine)(void)); extern void set_error_handle(FILE *); @@@ -667,22 -663,10 +667,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 @@@ -801,6 -785,14 +801,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: @@@ -831,7 -823,7 +839,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). @@@ -977,19 -969,6 +985,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 @@@ -1091,5 -1070,3 +1099,5 @@@ struct tm *git_gmtime_r(const time_t * #endif #endif + +extern int cmd_main(int, const char **);