void OS_make_pipe (Tchannel * readerp, Tchannel * writerp) { HFILE hread; HFILE hwrite; STD_API_CALL (dos_create_pipe, ((&hread), (&hwrite), 4096)); transaction_begin (); OS2_handle_close_on_abort (hwrite); (*readerp) = (OS2_make_channel (hread, CHANNEL_READ)); transaction_commit (); transaction_begin (); OS_channel_close_on_abort (*readerp); (*writerp) = (OS2_make_channel (hwrite, CHANNEL_WRITE)); transaction_commit (); }
Tchannel OS_server_connection_accept (Tchannel channel, void * peer_host, unsigned int * peer_port) { static struct sockaddr_in address; SOCKET s; { unsigned long nonblockp = (CHANNEL_NONBLOCKING (channel)); VOID_SOCKET_CALL (ioctlsocket, ((CHANNEL_SOCKET (channel)), FIONBIO, (&nonblockp))); } { int address_length = (sizeof (struct sockaddr_in)); s = (accept ((CHANNEL_SOCKET (channel)), ((struct sockaddr *) (&address)), (&address_length))); } if (s == INVALID_SOCKET) { DWORD code = (WSAGetLastError ()); if (code == WSAEWOULDBLOCK) return (NO_CHANNEL); NT_error_api_call (code, apicall_accept); } transaction_begin (); socket_close_on_abort (s); if (peer_host != 0) memcpy (peer_host, (& (address . sin_addr)), (sizeof (address . sin_addr))); if (peer_port != 0) (*peer_port) = (address . sin_port); RETURN_SOCKET (s, NT_channel_class_tcp_stream_socket); }
Tchannel OS_create_tcp_server_socket (void) { SOCKET s; transaction_begin (); SOCKET_SOCKET_CALL (socket, (PF_INET, SOCK_STREAM, 0), s); RETURN_SOCKET (s, NT_channel_class_tcp_server_socket); }
Tchannel OS_open_append_file (const char * filename) { Tchannel channel = (open_file (filename, FILE_NORMAL, (OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW), CHANNEL_WRITE)); transaction_begin (); OS_channel_close_on_abort (channel); (void) set_file_pointer (channel, FILE_END, 0); transaction_commit (); return (channel); }
transition_result_t handle_mail(context_t *context) { buffer_t *in_buf = &context->in_message; size_t reverse_path_length; const char *reverse_path = parse_mail(in_buf, &reverse_path_length); if (NULL == reverse_path) { if (buffer_shift_read_after(&context->in_message, CRLF, sizeof(CRLF) - 1) < 0) { return TRANSITION_ERROR; } if (BUFFER_TAILQ_PUSH_BACK_STRING(&context->out_message_queue, "555 Syntax error in reverse-path or not present" CRLF) < 0) { return TRANSITION_ERROR; } return TRANSITION_FAILED; } if (transaction_begin(&context->transaction) < 0) { return TRANSITION_ERROR; } if (transaction_set_reverse_path(&context->transaction, reverse_path, reverse_path_length) < 0) { CALL_ERR("transaction_set_reverse_path"); return TRANSITION_ERROR; } if (buffer_shift_read_after(&context->in_message, CRLF, sizeof(CRLF) - 1) < 0) { return TRANSITION_ERROR; } if (buffer_space(&context->in_message) == 0) { buffer_drop_read(&context->in_message); } if (BUFFER_TAILQ_PUSH_BACK_STRING(&context->out_message_queue, "250 Ok" CRLF) < 0) { return TRANSITION_ERROR; } log_write(context->log, "[%s] begin transaction", context->uuid); return TRANSITION_SUCCEED; }
Tchannel OS_open_tcp_stream_socket (void * host, unsigned int port) { SOCKET s; struct sockaddr_in address; SOCKET_SOCKET_CALL (socket, (PF_INET, SOCK_STREAM, 0), s); transaction_begin (); socket_close_on_abort (s); memset ((&address), 0, (sizeof (address))); (address . sin_family) = AF_INET; memcpy ((& (address . sin_addr)), host, (sizeof (address . sin_addr))); (address . sin_port) = port; VOID_SOCKET_CALL (connect, (s, ((struct sockaddr *) (&address)), (sizeof (address)))); RETURN_SOCKET (s, NT_channel_class_tcp_stream_socket); }
int walker_fetch(struct walker *walker, int targets, char **target, const char **write_ref, const char *write_ref_log_details) { struct strbuf refname = STRBUF_INIT; struct strbuf err = STRBUF_INIT; struct transaction *transaction = NULL; unsigned char *sha1 = xmalloc(targets * 20); char *msg = NULL; int i, ret = -1; save_commit_buffer = 0; if (write_ref) { transaction = transaction_begin(&err); if (!transaction) { error("%s", err.buf); goto done; } } if (!walker->get_recover) { for_each_ref(mark_complete, NULL); commit_list_sort_by_date(&complete); } for (i = 0; i < targets; i++) { if (interpret_target(walker, target[i], &sha1[20 * i])) { error("Could not interpret response from server '%s' as something to pull", target[i]); goto done; } if (process(walker, lookup_unknown_object(&sha1[20 * i]))) goto done; } if (loop(walker)) goto done; if (!write_ref) { ret = 0; goto done; } if (write_ref_log_details) { msg = xstrfmt("fetch from %s", write_ref_log_details); } else { msg = NULL; } for (i = 0; i < targets; i++) { if (!write_ref[i]) continue; strbuf_reset(&refname); strbuf_addf(&refname, "refs/%s", write_ref[i]); if (transaction_update_ref(transaction, refname.buf, &sha1[20 * i], NULL, 0, 0, msg ? msg : "fetch (unknown)", &err)) { error("%s", err.buf); goto done; } } if (transaction_commit(transaction, &err)) { error("%s", err.buf); goto done; } ret = 0; done: transaction_free(transaction); free(msg); free(sha1); strbuf_release(&err); strbuf_release(&refname); return ret; }
void create_branch(const char *head, const char *name, const char *start_name, int force, int reflog, int clobber_head, int quiet, enum branch_track track) { struct commit *commit; unsigned char sha1[20]; char *real_ref, msg[PATH_MAX + 20]; struct strbuf ref = STRBUF_INIT; int forcing = 0; int dont_change_ref = 0; int explicit_tracking = 0; if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE) explicit_tracking = 1; if (validate_new_branchname(name, &ref, force, track == BRANCH_TRACK_OVERRIDE || clobber_head)) { if (!force) dont_change_ref = 1; else forcing = 1; } real_ref = NULL; if (get_sha1(start_name, sha1)) { if (explicit_tracking) { if (advice_set_upstream_failure) { error(_(upstream_missing), start_name); advise(_(upstream_advice)); exit(1); } die(_(upstream_missing), start_name); } die(_("Not a valid object name: '%s'."), start_name); } switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) { case 0: /* Not branching from any existing branch */ if (explicit_tracking) die(_(upstream_not_branch), start_name); break; case 1: /* Unique completion -- good, only if it is a real branch */ if (!starts_with(real_ref, "refs/heads/") && validate_remote_tracking_branch(real_ref)) { if (explicit_tracking) die(_(upstream_not_branch), start_name); else real_ref = NULL; } break; default: die(_("Ambiguous object name: '%s'."), start_name); break; } if ((commit = lookup_commit_reference(sha1)) == NULL) die(_("Not a valid branch point: '%s'."), start_name); hashcpy(sha1, commit->object.sha1); if (forcing) snprintf(msg, sizeof msg, "branch: Reset to %s", start_name); else if (!dont_change_ref) snprintf(msg, sizeof msg, "branch: Created from %s", start_name); if (reflog) log_all_ref_updates = 1; if (!dont_change_ref) { struct transaction *transaction; struct strbuf err = STRBUF_INIT; transaction = transaction_begin(&err); if (!transaction || transaction_update_ref(transaction, ref.buf, sha1, null_sha1, 0, !forcing, msg, &err) || transaction_commit(transaction, &err)) die("%s", err.buf); transaction_free(transaction); } if (real_ref && track) setup_tracking(ref.buf + 11, real_ref, track, quiet); strbuf_release(&ref); free(real_ref); }