static void clear_parser_state(http_subtransport *t) { unsigned i; char *entry; http_parser_init(&t->parser, HTTP_RESPONSE); gitno_buffer_setup(&t->socket, &t->parse_buffer, t->parse_buffer_data, sizeof(t->parse_buffer_data)); t->last_cb = NONE; t->parse_error = 0; t->parse_finished = 0; git_buf_free(&t->parse_header_name); git_buf_init(&t->parse_header_name, 0); git_buf_free(&t->parse_header_value); git_buf_init(&t->parse_header_value, 0); git__free(t->content_type); t->content_type = NULL; git__free(t->location); t->location = NULL; git_vector_foreach(&t->www_authenticate, i, entry) git__free(entry); git_vector_free(&t->www_authenticate); }
/* * Note: this test was flaky prior to fixing #4101 -- run it several * times to get a failure. The issues is that whether the fast * (stat-only) codepath is used inside stash's diff operation depends * on whether files are "racily clean", and there doesn't seem to be * an easy way to force the exact required state. */ void test_stash_save__untracked_regression(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; const char *paths[] = {"what", "where", "how", "why"}; git_reference *head; git_commit *head_commit; git_buf untracked_dir; const char* workdir = git_repository_workdir(repo); git_buf_init(&untracked_dir, 0); git_buf_printf(&untracked_dir, "%sz", workdir); cl_assert(!p_mkdir(untracked_dir.ptr, 0777)); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJ_COMMIT)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; opts.paths.strings = (char **)paths; opts.paths.count = 4; cl_git_pass(git_checkout_tree(repo, (git_object*)head_commit, &opts)); cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); assert_commit_message_contains("refs/stash", "WIP on master"); git_reference_free(head); git_commit_free(head_commit); git_buf_dispose(&untracked_dir); }
void git_diff_find_context_init( git_diff_find_context_fn *findfn_out, git_diff_find_context_payload *payload_out, git_diff_driver *driver) { *findfn_out = driver ? diff_context_find : NULL; memset(payload_out, 0, sizeof(*payload_out)); if (driver) { payload_out->driver = driver; payload_out->match_line = (driver->type == DIFF_DRIVER_PATTERNLIST) ? diff_context_line__pattern_match : diff_context_line__simple; git_buf_init(&payload_out->line, 0); } }
/* * At one point, there was a loose object format that was intended to * mimic the format used in pack-files. This was to allow easy copying * of loose object data into packs. This format is no longer used, but * we must still read it. */ static int read_loose_packlike(git_rawobj *out, git_buf *obj) { git_buf body = GIT_BUF_INIT; const unsigned char *obj_data; obj_hdr hdr; size_t obj_len, head_len, alloc_size; int error; obj_data = (unsigned char *)obj->ptr; obj_len = obj->size; /* * read the object header, which is an (uncompressed) * binary encoding of the object type and size. */ if ((error = parse_header_packlike(&hdr, &head_len, obj_data, obj_len)) < 0) goto done; if (!git_object_typeisloose(hdr.type) || head_len > obj_len) { giterr_set(GITERR_ODB, "failed to inflate loose object"); error = -1; goto done; } obj_data += head_len; obj_len -= head_len; /* * allocate a buffer and inflate the data into it */ if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) || git_buf_init(&body, alloc_size) < 0) { error = -1; goto done; } if ((error = git_zstream_inflatebuf(&body, obj_data, obj_len)) < 0) goto done; out->len = hdr.size; out->type = hdr.type; out->data = git_buf_detach(&body); done: git_buf_dispose(&body); return error; }
git_global_st *git__global_state(void) { git_global_st *ptr; assert(git_atomic_get(&git__n_inits) > 0); if ((ptr = pthread_getspecific(_tls_key)) != NULL) return ptr; ptr = git__calloc(1, sizeof(git_global_st)); if (!ptr) return NULL; git_buf_init(&ptr->error_buf, 0); pthread_setspecific(_tls_key, ptr); return ptr; }
git_global_st *git__global_state(void) { git_global_st *ptr; assert(git_atomic_get(&git__n_inits) > 0); if ((ptr = TlsGetValue(_tls_index)) != NULL) return ptr; ptr = git__calloc(1, sizeof(git_global_st)); if (!ptr) return NULL; git_buf_init(&ptr->error_buf, 0); TlsSetValue(_tls_index, ptr); return ptr; }
static int update_head_to_remote(git_repository *repo, git_remote *remote) { int retcode = -1; git_refspec dummy_spec; git_remote_head *remote_head; struct head_info head_info; git_buf remote_master_name = GIT_BUF_INIT; /* Did we just clone an empty repository? */ if (remote->refs.length == 0) { return setup_tracking_config( repo, "master", GIT_REMOTE_ORIGIN, GIT_REFS_HEADS_MASTER_FILE); } /* Get the remote's HEAD. This is always the first ref in remote->refs. */ remote_head = NULL; if (!remote->transport->ls(remote->transport, get_head_callback, &remote_head)) return -1; assert(remote_head); git_oid_cpy(&head_info.remote_head_oid, &remote_head->oid); git_buf_init(&head_info.branchname, 16); head_info.repo = repo; head_info.refspec = git_remote__matching_refspec(remote, GIT_REFS_HEADS_MASTER_FILE); head_info.found = 0; if (head_info.refspec == NULL) { memset(&dummy_spec, 0, sizeof(git_refspec)); head_info.refspec = &dummy_spec; } /* Determine the remote tracking reference name from the local master */ if (git_refspec_transform_r( &remote_master_name, head_info.refspec, GIT_REFS_HEADS_MASTER_FILE) < 0) return -1; /* Check to see if the remote HEAD points to the remote master */ if (reference_matches_remote_head(git_buf_cstr(&remote_master_name), &head_info) < 0) goto cleanup; if (head_info.found) { retcode = update_head_to_new_branch( repo, &head_info.remote_head_oid, git_buf_cstr(&head_info.branchname)); goto cleanup; } /* Not master. Check all the other refs. */ if (git_reference_foreach_name( repo, reference_matches_remote_head, &head_info) < 0) goto cleanup; if (head_info.found) { retcode = update_head_to_new_branch( repo, &head_info.remote_head_oid, git_buf_cstr(&head_info.branchname)); goto cleanup; } else { retcode = git_repository_set_head_detached( repo, &head_info.remote_head_oid); goto cleanup; } cleanup: git_buf_free(&remote_master_name); git_buf_free(&head_info.branchname); return retcode; }
int git_path_iconv_init_precompose(git_path_iconv_t *ic) { git_buf_init(&ic->buf, 0); ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING); return 0; }
void test_refs_branches_upstreamname__initialize(void) { cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); git_buf_init(&upstream_name, 0); }