static int verify_one_pack(char *arg, int verbose) { int len = strlen(arg); struct packed_git *g; while (1) { /* Should name foo.idx, but foo.pack may be named; * convert it to foo.idx */ if (!strcmp(arg + len - 5, ".pack")) { strcpy(arg + len - 5, ".idx"); len--; } /* Should name foo.idx now */ if ((g = add_packed_git(arg, len, 1))) break; /* No? did you name just foo? */ strcpy(arg + len, ".idx"); len += 4; if ((g = add_packed_git(arg, len, 1))) break; return error("packfile %s not found.", arg); } return verify_pack(g, verbose); }
static int verify_one_pack(const char *path, unsigned int flags) { char arg[PATH_MAX]; int len; int verbose = flags & VERIFY_PACK_VERBOSE; int stat_only = flags & VERIFY_PACK_STAT_ONLY; struct packed_git *pack; int err; len = strlcpy(arg, path, PATH_MAX); if (len >= PATH_MAX) return error("name too long: %s", path); /* * In addition to "foo.idx" we accept "foo.pack" and "foo"; * normalize these forms to "foo.idx" for add_packed_git(). */ if (has_extension(arg, ".pack")) { strcpy(arg + len - 5, ".idx"); len--; } else if (!has_extension(arg, ".idx")) { if (len + 4 >= PATH_MAX) return error("name too long: %s.idx", arg); strcpy(arg + len, ".idx"); len += 4; } /* * add_packed_git() uses our buffer (containing "foo.idx") to * build the pack filename ("foo.pack"). Make sure it fits. */ if (len + 1 >= PATH_MAX) { arg[len - 4] = '\0'; return error("name too long: %s.pack", arg); } pack = add_packed_git(arg, len, 1); if (!pack) return error("packfile %s not found.", arg); install_packed_git(pack); if (!stat_only) err = verify_pack(pack); else err = open_pack_index(pack); if (verbose || stat_only) { if (err) printf("%s: bad\n", pack->pack_name); else { show_pack_info(pack, flags); if (!stat_only) printf("%s: ok\n", pack->pack_name); } } return err; }
static void dft_apply(dofft_closure *k_, bench_complex *in, bench_complex *out) { dofft_dft_closure *k = (dofft_dft_closure *)k_; bench_problem *p = k->p; bench_tensor *totalsz, *pckdsz; bench_tensor *totalsz_swap, *pckdsz_swap; bench_real *ri, *ii, *ro, *io; int totalscale; totalsz = tensor_append(p->vecsz, p->sz); pckdsz = verify_pack(totalsz, 2); ri = (bench_real *) p->in; ro = (bench_real *) p->out; totalsz_swap = tensor_copy_swapio(totalsz); pckdsz_swap = tensor_copy_swapio(pckdsz); /* confusion: the stride is the distance between complex elements when using interleaved format, but it is the distance between real elements when using split format */ if (p->split) { ii = p->ini ? (bench_real *) p->ini : ri + p->iphyssz; io = p->outi ? (bench_real *) p->outi : ro + p->ophyssz; totalscale = 1; } else { ii = p->ini ? (bench_real *) p->ini : ri + 1; io = p->outi ? (bench_real *) p->outi : ro + 1; totalscale = 2; } cpy(&c_re(in[0]), &c_im(in[0]), pckdsz, 1, ri, ii, totalsz, totalscale); after_problem_ccopy_from(p, ri, ii); doit(1, p); after_problem_ccopy_to(p, ro, io); if (k->k.recopy_input) cpy(ri, ii, totalsz_swap, totalscale, &c_re(in[0]), &c_im(in[0]), pckdsz_swap, 1); cpy(ro, io, totalsz, totalscale, &c_re(out[0]), &c_im(out[0]), pckdsz, 1); tensor_destroy(totalsz); tensor_destroy(pckdsz); tensor_destroy(totalsz_swap); tensor_destroy(pckdsz_swap); }
void verify_r2r(bench_problem *p, int rounds, double tol, errors *e) { R *inA, *inB, *inC, *outA, *outB, *outC, *tmp; info nfo; int n, vecn, N; double impulse_amp = 1.0; dim_stuff *d; int i; if (rounds == 0) rounds = 20; /* default value */ n = tensor_sz(p->sz); vecn = tensor_sz(p->vecsz); N = n * vecn; d = (dim_stuff *) bench_malloc(sizeof(dim_stuff) * p->sz->rnk); for (i = 0; i < p->sz->rnk; ++i) { int n0, i0, k0; trigfun ti, ts; d[i].n = n0 = p->sz->dims[i].n; if (p->k[i] > R2R_DHT) n0 = 2 * (n0 + (p->k[i] == R2R_REDFT00 ? -1 : (p->k[i] == R2R_RODFT00 ? 1 : 0))); switch (p->k[i]) { case R2R_R2HC: i0 = k0 = 0; ti = realhalf; ts = coshalf; break; case R2R_DHT: i0 = k0 = 0; ti = unity; ts = cos00; break; case R2R_HC2R: i0 = k0 = 0; ti = unity; ts = cos00; break; case R2R_REDFT00: i0 = k0 = 0; ti = ts = cos00; break; case R2R_REDFT01: i0 = k0 = 0; ti = ts = cos01; break; case R2R_REDFT10: i0 = k0 = 0; ti = cos10; impulse_amp *= 2.0; ts = cos00; break; case R2R_REDFT11: i0 = k0 = 0; ti = cos11; impulse_amp *= 2.0; ts = cos01; break; case R2R_RODFT00: i0 = k0 = 1; ti = sin00; impulse_amp *= 2.0; ts = cos00; break; case R2R_RODFT01: i0 = 1; k0 = 0; ti = sin01; impulse_amp *= n == 1 ? 1.0 : 2.0; ts = cos01; break; case R2R_RODFT10: i0 = 0; k0 = 1; ti = sin10; impulse_amp *= 2.0; ts = cos00; break; case R2R_RODFT11: i0 = k0 = 0; ti = sin11; impulse_amp *= 2.0; ts = cos01; break; default: BENCH_ASSERT(0); return; } d[i].n0 = n0; d[i].i0 = i0; d[i].k0 = k0; d[i].ti = ti; d[i].ts = ts; } inA = (R *) bench_malloc(N * sizeof(R)); inB = (R *) bench_malloc(N * sizeof(R)); inC = (R *) bench_malloc(N * sizeof(R)); outA = (R *) bench_malloc(N * sizeof(R)); outB = (R *) bench_malloc(N * sizeof(R)); outC = (R *) bench_malloc(N * sizeof(R)); tmp = (R *) bench_malloc(N * sizeof(R)); nfo.p = p; nfo.probsz = p->sz; nfo.totalsz = tensor_append(p->vecsz, nfo.probsz); nfo.pckdsz = verify_pack(nfo.totalsz, 1); nfo.pckdvecsz = verify_pack(p->vecsz, tensor_sz(nfo.probsz)); e->i = rimpulse(d, impulse_amp, n, vecn, &nfo, inA, inB, inC, outA, outB, outC, tmp, rounds, tol); e->l = rlinear(N, &nfo, inA, inB, inC, outA, outB, outC, tmp, rounds,tol); e->s = t_shift(n, vecn, &nfo, inA, inB, outA, outB, tmp, rounds, tol, d); /* grr, verify-lib.c:preserves_input() only works for complex */ if (!p->in_place && !p->destroy_input) { bench_tensor *totalsz_swap, *pckdsz_swap; totalsz_swap = tensor_copy_swapio(nfo.totalsz); pckdsz_swap = tensor_copy_swapio(nfo.pckdsz); for (i = 0; i < rounds; ++i) { rarand(inA, N); dofft(&nfo, inA, outB); cpyr((R *) nfo.p->in, totalsz_swap, inB, pckdsz_swap); racmp(inB, inA, N, "preserves_input", 0.0); } tensor_destroy(totalsz_swap); tensor_destroy(pckdsz_swap); } tensor_destroy(nfo.totalsz); tensor_destroy(nfo.pckdsz); tensor_destroy(nfo.pckdvecsz); bench_free(tmp); bench_free(outC); bench_free(outB); bench_free(outA); bench_free(inC); bench_free(inB); bench_free(inA); bench_free(d); }
static void rdft2_apply(dofft_closure *k_, bench_complex *in, bench_complex *out) { dofft_rdft2_closure *k = (dofft_rdft2_closure *)k_; bench_problem *p = k->p; bench_tensor *totalsz, *pckdsz, *totalsz_swap, *pckdsz_swap; bench_tensor *probsz2, *totalsz2, *pckdsz2; bench_tensor *probsz2_swap, *totalsz2_swap, *pckdsz2_swap; bench_real *ri, *ii, *ro, *io; int n2, totalscale; totalsz = tensor_append(p->vecsz, p->sz); pckdsz = verify_pack(totalsz, 2); n2 = tensor_sz(totalsz); if (FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0) n2 = (n2 / p->sz->dims[p->sz->rnk - 1].n) * (p->sz->dims[p->sz->rnk - 1].n / 2 + 1); ri = (bench_real *) p->in; ro = (bench_real *) p->out; if (FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0 && n2 > 0) { probsz2 = tensor_copy_sub(p->sz, p->sz->rnk - 1, 1); totalsz2 = tensor_copy_sub(totalsz, 0, totalsz->rnk - 1); pckdsz2 = tensor_copy_sub(pckdsz, 0, pckdsz->rnk - 1); } else { probsz2 = mktensor(0); totalsz2 = tensor_copy(totalsz); pckdsz2 = tensor_copy(pckdsz); } totalsz_swap = tensor_copy_swapio(totalsz); pckdsz_swap = tensor_copy_swapio(pckdsz); totalsz2_swap = tensor_copy_swapio(totalsz2); pckdsz2_swap = tensor_copy_swapio(pckdsz2); probsz2_swap = tensor_copy_swapio(probsz2); /* confusion: the stride is the distance between complex elements when using interleaved format, but it is the distance between real elements when using split format */ if (p->split) { ii = p->ini ? (bench_real *) p->ini : ri + n2; io = p->outi ? (bench_real *) p->outi : ro + n2; totalscale = 1; } else { ii = p->ini ? (bench_real *) p->ini : ri + 1; io = p->outi ? (bench_real *) p->outi : ro + 1; totalscale = 2; } if (p->sign < 0) { /* R2HC */ int N, vN, i; cpyr(&c_re(in[0]), pckdsz, ri, totalsz); after_problem_rcopy_from(p, ri); doit(1, p); after_problem_hccopy_to(p, ro, io); if (k->k.recopy_input) cpyr(ri, totalsz_swap, &c_re(in[0]), pckdsz_swap); cpyhc2(ro, io, probsz2, totalsz2, totalscale, &c_re(out[0]), &c_im(out[0]), pckdsz2); N = tensor_sz(p->sz); vN = tensor_sz(p->vecsz); for (i = 0; i < vN; ++i) mkhermitian(out + i*N, p->sz->rnk, p->sz->dims, 1); } else { /* HC2R */ icpyhc2(ri, ii, probsz2, totalsz2, totalscale, &c_re(in[0]), &c_im(in[0]), pckdsz2); after_problem_hccopy_from(p, ri, ii); doit(1, p); after_problem_rcopy_to(p, ro); if (k->k.recopy_input) cpyhc2(ri, ii, probsz2_swap, totalsz2_swap, totalscale, &c_re(in[0]), &c_im(in[0]), pckdsz2_swap); mkreal(out, tensor_sz(pckdsz)); cpyr(ro, totalsz, &c_re(out[0]), pckdsz); } tensor_destroy(totalsz); tensor_destroy(pckdsz); tensor_destroy(totalsz_swap); tensor_destroy(pckdsz_swap); tensor_destroy(probsz2); tensor_destroy(totalsz2); tensor_destroy(pckdsz2); tensor_destroy(probsz2_swap); tensor_destroy(totalsz2_swap); tensor_destroy(pckdsz2_swap); }
int cmd_fsck(int argc, const char **argv, const char *prefix) { int i; struct alternate_object_database *alt; /* fsck knows how to handle missing promisor objects */ fetch_if_missing = 0; errors_found = 0; check_replace_refs = 0; argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0); fsck_walk_options.walk = mark_object; fsck_obj_options.walk = mark_used; fsck_obj_options.error_func = fsck_error_func; if (check_strict) fsck_obj_options.strict = 1; if (show_progress == -1) show_progress = isatty(2); if (verbose) show_progress = 0; if (write_lost_and_found) { check_full = 1; include_reflogs = 0; } if (name_objects) fsck_walk_options.object_names = xcalloc(1, sizeof(struct decoration)); git_config(fsck_config, NULL); fsck_head_link(); if (connectivity_only) { for_each_loose_object(mark_loose_for_connectivity, NULL, 0); for_each_packed_object(mark_packed_for_connectivity, NULL, 0); } else { struct alternate_object_database *alt_odb_list; fsck_object_dir(get_object_directory()); prepare_alt_odb(the_repository); alt_odb_list = the_repository->objects->alt_odb_list; for (alt = alt_odb_list; alt; alt = alt->next) fsck_object_dir(alt->path); if (check_full) { struct packed_git *p; uint32_t total = 0, count = 0; struct progress *progress = NULL; if (show_progress) { for (p = get_packed_git(the_repository); p; p = p->next) { if (open_pack_index(p)) continue; total += p->num_objects; } progress = start_progress(_("Checking objects"), total); } for (p = get_packed_git(the_repository); p; p = p->next) { /* verify gives error messages itself */ if (verify_pack(p, fsck_obj_buffer, progress, count)) errors_found |= ERROR_PACK; count += p->num_objects; } stop_progress(&progress); } } for (i = 0; i < argc; i++) { const char *arg = argv[i]; struct object_id oid; if (!get_oid(arg, &oid)) { struct object *obj = lookup_object(oid.hash); if (!obj || !(obj->flags & HAS_OBJ)) { if (is_promisor_object(&oid)) continue; error("%s: object missing", oid_to_hex(&oid)); errors_found |= ERROR_OBJECT; continue; } obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, xstrdup(arg)); mark_object_reachable(obj); continue; } error("invalid parameter: expected sha1, got '%s'", arg); errors_found |= ERROR_OBJECT; } /* * If we've not been given any explicit head information, do the * default ones from .git/refs. We also consider the index file * in this case (ie this implies --cache). */ if (!argc) { get_default_heads(); keep_cache_objects = 1; } if (keep_cache_objects) { verify_index_checksum = 1; verify_ce_order = 1; read_cache(); for (i = 0; i < active_nr; i++) { unsigned int mode; struct blob *blob; struct object *obj; mode = active_cache[i]->ce_mode; if (S_ISGITLINK(mode)) continue; blob = lookup_blob(&active_cache[i]->oid); if (!blob) continue; obj = &blob->object; obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, xstrfmt(":%s", active_cache[i]->name)); mark_object_reachable(obj); } if (active_cache_tree) fsck_cache_tree(active_cache_tree); } check_connectivity(); return errors_found; }
static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1) { char *url; struct packed_git *target; struct packed_git **lst; FILE *packfile; char *filename; char tmpfile[PATH_MAX]; int ret; long prev_posn = 0; char range[RANGE_HEADER_SIZE]; struct curl_slist *range_header = NULL; struct walker_data *data = walker->data; struct active_request_slot *slot; struct slot_results results; if (fetch_indices(walker, repo)) return -1; target = find_sha1_pack(sha1, repo->packs); if (!target) return -1; if (walker->get_verbosely) { fprintf(stderr, "Getting pack %s\n", sha1_to_hex(target->sha1)); fprintf(stderr, " which contains %s\n", sha1_to_hex(sha1)); } url = xmalloc(strlen(repo->base) + 65); sprintf(url, "%s/objects/pack/pack-%s.pack", repo->base, sha1_to_hex(target->sha1)); filename = sha1_pack_name(target->sha1); snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename); packfile = fopen(tmpfile, "a"); if (!packfile) return error("Unable to open local file %s for pack", tmpfile); slot = get_active_slot(); slot->results = &results; curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile); curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite); curl_easy_setopt(slot->curl, CURLOPT_URL, url); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header); slot->local = packfile; /* If there is data present from a previous transfer attempt, resume where it left off */ prev_posn = ftell(packfile); if (prev_posn>0) { if (walker->get_verbosely) fprintf(stderr, "Resuming fetch of pack %s at byte %ld\n", sha1_to_hex(target->sha1), prev_posn); sprintf(range, "Range: bytes=%ld-", prev_posn); range_header = curl_slist_append(range_header, range); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header); } if (start_active_slot(slot)) { run_active_slot(slot); if (results.curl_result != CURLE_OK) { fclose(packfile); return error("Unable to get pack file %s\n%s", url, curl_errorstr); } } else { fclose(packfile); return error("Unable to start request"); } target->pack_size = ftell(packfile); fclose(packfile); ret = move_temp_to_file(tmpfile, filename); if (ret) return ret; lst = &repo->packs; while (*lst != target) lst = &((*lst)->next); *lst = (*lst)->next; if (verify_pack(target)) return -1; install_packed_git(target); return 0; }