From: Junio C Hamano Date: Fri, 19 Sep 2014 18:38:35 +0000 (-0700) Subject: Merge branch 'da/styles' X-Git-Tag: v2.2.0-rc0~113 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/83510ef3fda0df6acd6680410698a1762042a8af?hp=-c Merge branch 'da/styles' * da/styles: stylefix: asterisks stick to the variable, not the type --- 83510ef3fda0df6acd6680410698a1762042a8af diff --combined builtin/clone.c index dd4092b050,315969d4e7..3927edfb6e --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -685,9 -685,10 +685,10 @@@ static void write_config(struct string_ } } - static void write_refspec_config(const char* src_ref_prefix, - const struct ref* our_head_points_at, - const struct ref* remote_head_points_at, struct strbuf* branch_top) + static void write_refspec_config(const char *src_ref_prefix, + const struct ref *our_head_points_at, + const struct ref *remote_head_points_at, + struct strbuf *branch_top) { struct strbuf key = STRBUF_INIT; struct strbuf value = STRBUF_INIT; @@@ -1004,7 -1005,5 +1005,7 @@@ int cmd_clone(int argc, const char **ar strbuf_release(&key); strbuf_release(&value); junk_mode = JUNK_LEAVE_ALL; + + free(refspec); return err; } diff --combined commit.c index 9416d842c6,4de6be4107..9c4439fed6 --- a/commit.c +++ b/commit.c @@@ -584,19 -584,25 +584,19 @@@ define_commit_slab(author_date_slab, un static void record_author_date(struct author_date_slab *author_date, struct commit *commit) { - const char *buf, *line_end, *ident_line; const char *buffer = get_commit_buffer(commit, NULL); struct ident_split ident; + const char *ident_line; + size_t ident_len; char *date_end; unsigned long date; - for (buf = buffer; buf; buf = line_end + 1) { - line_end = strchrnul(buf, '\n'); - if (!skip_prefix(buf, "author ", &ident_line)) { - if (!line_end[0] || line_end[1] == '\n') - return; /* end of header */ - continue; - } - if (split_ident_line(&ident, - ident_line, line_end - ident_line) || - !ident.date_begin || !ident.date_end) - goto fail_exit; /* malformed "author" line */ - break; - } + ident_line = find_commit_header(buffer, "author", &ident_len); + if (!ident_line) + goto fail_exit; /* no author line */ + if (split_ident_line(&ident, ident_line, ident_len) || + !ident.date_begin || !ident.date_end) + goto fail_exit; /* malformed "author" line */ date = strtoul(ident.date_begin, &date_end, 10); if (date_end != ident.date_end) @@@ -1250,7 -1256,7 +1250,7 @@@ static void parse_gpg_output(struct sig } } - void check_commit_signature(const struct commit* commit, struct signature_check *sigc) + void check_commit_signature(const struct commit *commit, struct signature_check *sigc) { struct strbuf payload = STRBUF_INIT; struct strbuf signature = STRBUF_INIT; @@@ -1654,25 -1660,3 +1654,25 @@@ void print_commit_list(struct commit_li printf(format, sha1_to_hex(list->item->object.sha1)); } } + +const char *find_commit_header(const char *msg, const char *key, size_t *out_len) +{ + int key_len = strlen(key); + const char *line = msg; + + while (line) { + const char *eol = strchrnul(line, '\n'); + + if (line == eol) + return NULL; + + if (eol - line > key_len && + !strncmp(line, key, key_len) && + line[key_len] == ' ') { + *out_len = eol - line - key_len - 1; + return line + key_len + 1; + } + line = *eol ? eol + 1 : NULL; + } + return NULL; +} diff --combined commit.h index 470c74569f,268c9d7cac..bc68ccbe69 --- a/commit.h +++ b/commit.h @@@ -26,25 -26,13 +26,25 @@@ extern int save_commit_buffer extern const char *commit_type; /* While we can decorate any object with a name, it's only used for commits.. */ -extern struct decoration name_decoration; struct name_decoration { struct name_decoration *next; int type; - char name[1]; + char name[FLEX_ARRAY]; }; +enum decoration_type { + DECORATION_NONE = 0, + DECORATION_REF_LOCAL, + DECORATION_REF_REMOTE, + DECORATION_REF_TAG, + DECORATION_REF_STASH, + DECORATION_REF_HEAD, + DECORATION_GRAFTED, +}; + +void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); +const struct name_decoration *get_name_decoration(const struct object *obj); + struct commit *lookup_commit(const unsigned char *sha1); struct commit *lookup_commit_reference(const unsigned char *sha1); struct commit *lookup_commit_reference_gently(const unsigned char *sha1, @@@ -171,7 -159,6 +171,7 @@@ extern void get_commit_format(const cha extern const char *format_subject(struct strbuf *sb, const char *msg, const char *line_separator); extern void userformat_find_requirements(const char *fmt, struct userformat_want *w); +extern int commit_format_is_empty(enum cmit_fmt); extern void format_commit_message(const struct commit *commit, const char *format, struct strbuf *sb, const struct pretty_print_context *context); @@@ -326,17 -313,6 +326,17 @@@ extern struct commit_extra_header *read extern void free_commit_extra_headers(struct commit_extra_header *extra); +/* + * Search the commit object contents given by "msg" for the header "key". + * Returns a pointer to the start of the header contents, or NULL. The length + * of the header, up to the first newline, is returned via out_len. + * + * Note that some headers (like mergetag) may be multi-line. It is the caller's + * responsibility to parse further in this case! + */ +extern const char *find_commit_header(const char *msg, const char *key, + size_t *out_len); + typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra, void *cb_data); @@@ -370,7 -346,7 +370,7 @@@ extern void print_commit_list(struct co * at all. This may allocate memory for sig->gpg_output, sig->gpg_status, * sig->signer and sig->key. */ - extern void check_commit_signature(const struct commit* commit, struct signature_check *sigc); + extern void check_commit_signature(const struct commit *commit, struct signature_check *sigc); int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused); diff --combined refs.h index 68c5770164,00f209a138..10fc3a2634 --- a/refs.h +++ b/refs.h @@@ -10,38 -10,6 +10,38 @@@ struct ref_lock int force_write; }; +/* + * A ref_transaction represents a collection of ref updates + * that should succeed or fail together. + * + * Calling sequence + * ---------------- + * - Allocate and initialize a `struct ref_transaction` by calling + * `ref_transaction_begin()`. + * + * - List intended ref updates by calling functions like + * `ref_transaction_update()` and `ref_transaction_create()`. + * + * - Call `ref_transaction_commit()` to execute the transaction. + * If this succeeds, the ref updates will have taken place and + * the transaction cannot be rolled back. + * + * - At any time call `ref_transaction_free()` to discard the + * transaction and free associated resources. In particular, + * this rolls back the transaction if it has not been + * successfully committed. + * + * Error handling + * -------------- + * + * On error, transaction functions append a message about what + * went wrong to the 'err' argument. The message mentions what + * ref was being updated (if any) when the error occurred so it + * can be passed to 'die' or 'error' as-is. + * + * The message is appended to err without first clearing err. + * err will not be '\n' terminated. + */ struct ref_transaction; /* @@@ -109,7 -77,7 +109,7 @@@ static inline const char *has_glob_spec extern int for_each_rawref(each_ref_fn, void *); extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname); - extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list* refnames); + extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames); /* * Lock the packed-refs file for writing. Flags is passed to @@@ -173,17 -141,14 +173,17 @@@ extern int is_branch(const char *refnam extern int peel_ref(const char *refname, unsigned char *sha1); /* - * Locks a "refs/" ref returning the lock on success and NULL on failure. - * On failure errno is set to something meaningful. + * Flags controlling lock_any_ref_for_update(), ref_transaction_update(), + * ref_transaction_create(), etc. + * REF_NODEREF: act on the ref directly, instead of dereferencing + * symbolic references. + * + * Flags >= 0x100 are reserved for internal use. */ -extern struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1); - -/** Locks any ref (for 'HEAD' type refs). */ #define REF_NODEREF 0x01 -/* errno is set to something meaningful on failure */ +/* + * This function sets errno to something meaningful on failure. + */ extern struct ref_lock *lock_any_ref_for_update(const char *refname, const unsigned char *old_sha1, int flags, int *type_p); @@@ -267,7 -232,7 +267,7 @@@ enum action_on_err * Begin a reference transaction. The reference transaction must * be freed by calling ref_transaction_free(). */ -struct ref_transaction *ref_transaction_begin(void); +struct ref_transaction *ref_transaction_begin(struct strbuf *err); /* * The following functions add a reference check or update to a @@@ -285,7 -250,7 +285,7 @@@ * it must not have existed beforehand. * Function returns 0 on success and non-zero on failure. A failure to update * means that the transaction as a whole has failed and will need to be - * rolled back. On failure the err buffer will be updated. + * rolled back. */ int ref_transaction_update(struct ref_transaction *transaction, const char *refname, @@@ -299,34 -264,28 +299,34 @@@ * that the reference should have after the update; it must not be the * null SHA-1. It is verified that the reference does not exist * already. + * Function returns 0 on success and non-zero on failure. A failure to create + * means that the transaction as a whole has failed and will need to be + * rolled back. */ -void ref_transaction_create(struct ref_transaction *transaction, - const char *refname, - const unsigned char *new_sha1, - int flags); +int ref_transaction_create(struct ref_transaction *transaction, + const char *refname, + const unsigned char *new_sha1, + int flags, + struct strbuf *err); /* * Add a reference deletion to transaction. If have_old is true, then * old_sha1 holds the value that the reference should have had before * the update (which must not be the null SHA-1). + * Function returns 0 on success and non-zero on failure. A failure to delete + * means that the transaction as a whole has failed and will need to be + * rolled back. */ -void ref_transaction_delete(struct ref_transaction *transaction, - const char *refname, - const unsigned char *old_sha1, - int flags, int have_old); +int ref_transaction_delete(struct ref_transaction *transaction, + const char *refname, + const unsigned char *old_sha1, + int flags, int have_old, + struct strbuf *err); /* * Commit all of the changes that have been queued in transaction, as * atomically as possible. Return a nonzero value if there is a * problem. - * If err is non-NULL we will add an error string to it to explain why - * the transaction failed. The string does not end in newline. */ int ref_transaction_commit(struct ref_transaction *transaction, const char *msg, struct strbuf *err); diff --combined remote-curl.c index 645872a4f2,d2229e0efd..cd626d15e5 --- a/remote-curl.c +++ b/remote-curl.c @@@ -221,7 -221,7 +221,7 @@@ static int show_http_message(struct str return 0; } - static struct discovery* discover_refs(const char *service, int for_push) + static struct discovery *discover_refs(const char *service, int for_push) { struct strbuf exp = STRBUF_INIT; struct strbuf type = STRBUF_INIT; @@@ -623,9 -623,10 +623,9 @@@ static int rpc_service(struct rpc_stat const char *svc = rpc->service_name; struct strbuf buf = STRBUF_INIT; struct strbuf *preamble = rpc->stdin_preamble; - struct child_process client; + struct child_process client = CHILD_PROCESS_INIT; int err = 0; - memset(&client, 0, sizeof(client)); client.in = -1; client.out = -1; client.git_cmd = 1; @@@ -862,7 -863,6 +862,7 @@@ static int push_git(struct discovery *h int i, err; struct argv_array args; struct string_list_item *cas_option; + struct strbuf preamble = STRBUF_INIT; argv_array_init(&args); argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", @@@ -880,22 -880,17 +880,22 @@@ for_each_string_list_item(cas_option, &cas_options) argv_array_push(&args, cas_option->string); argv_array_push(&args, url.buf); + + argv_array_push(&args, "--stdin"); for (i = 0; i < nr_spec; i++) - argv_array_push(&args, specs[i]); + packet_buf_write(&preamble, "%s\n", specs[i]); + packet_buf_flush(&preamble); memset(&rpc, 0, sizeof(rpc)); rpc.service_name = "git-receive-pack", rpc.argv = args.argv; + rpc.stdin_preamble = &preamble; err = rpc_service(&rpc, heads); if (rpc.result.len) write_or_die(1, rpc.result.buf, rpc.result.len); strbuf_release(&rpc.result); + strbuf_release(&preamble); argv_array_clear(&args); return err; }