static void annotate_refs_with_symref_info(struct ref *ref) { struct string_list symref = STRING_LIST_INIT_DUP; const char *feature_list = server_capabilities; while (feature_list) { int len; const char *val; val = parse_feature_value(feature_list, "symref", &len); if (!val) break; parse_one_symref_info(&symref, val, len); feature_list = val + 1; } sort_string_list(&symref); for (; ref; ref = ref->next) { struct string_list_item *item; item = string_list_lookup(&symref, ref->name); if (!item) continue; ref->symref = xstrdup((char *)item->util); } string_list_clear(&symref, 0); }
int combine_notes_cat_sort_uniq(unsigned char *cur_sha1, const unsigned char *new_sha1) { struct string_list sort_uniq_list = STRING_LIST_INIT_DUP; struct strbuf buf = STRBUF_INIT; int ret = 1; /* read both note blob objects into unique_lines */ if (string_list_add_note_lines(&sort_uniq_list, cur_sha1)) goto out; if (string_list_add_note_lines(&sort_uniq_list, new_sha1)) goto out; string_list_remove_empty_items(&sort_uniq_list, 0); sort_string_list(&sort_uniq_list); string_list_remove_duplicates(&sort_uniq_list, 0); /* create a new blob object from sort_uniq_list */ if (for_each_string_list(&sort_uniq_list, string_list_join_lines_helper, &buf)) goto out; ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_sha1); out: strbuf_release(&buf); string_list_clear(&sort_uniq_list, 0); return ret; }
static int prepare_repo_cmd(struct cgit_context *ctx) { char *tmp; unsigned char sha1[20]; int nongit = 0; int rc; setenv("GIT_DIR", ctx->repo->path, 1); setup_git_directory_gently(&nongit); if (nongit) { rc = errno; ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, "config error"); tmp = fmt("Failed to open %s: %s", ctx->repo->name, rc ? strerror(rc) : "Not a valid git repository"); ctx->repo = NULL; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); cgit_print_error(tmp); cgit_print_docend(); return 1; } ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); if (!ctx->repo->defbranch) ctx->repo->defbranch = guess_defbranch(); if (!ctx->qry.head) { ctx->qry.nohead = 1; ctx->qry.head = find_default_branch(ctx->repo); } if (!ctx->qry.head) { cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); cgit_print_error("Repository seems to be empty"); cgit_print_docend(); return 1; } if (get_sha1(ctx->qry.head, sha1)) { tmp = xstrdup(ctx->qry.head); ctx->qry.head = ctx->repo->defbranch; ctx->page.status = 404; ctx->page.statusmsg = "Not found"; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); cgit_print_error(fmt("Invalid branch: %s", tmp)); cgit_print_docend(); return 1; } sort_string_list(&ctx->repo->submodules); cgit_prepare_repo_env(ctx->repo); return 0; }
static void check_aliased_updates(struct command *commands) { struct command *cmd; struct string_list ref_list = STRING_LIST_INIT_NODUP; for (cmd = commands; cmd; cmd = cmd->next) { struct string_list_item *item = string_list_append(&ref_list, cmd->ref_name); item->util = (void *)cmd; } sort_string_list(&ref_list); for (cmd = commands; cmd; cmd = cmd->next) check_aliased_update(cmd, &ref_list); string_list_clear(&ref_list, 0); }
/**************************************************************************** * Read an alignment from a file. Sort the sequences by sequence name if * requested. Remove all gap sequences if requested. ****************************************************************************/ ALIGNMENT_T* read_alignment_from_file (char *filename, BOOLEAN_T sort, BOOLEAN_T remove_allgap_seqs, int* ref_seq_index ) { int i; // Read the sequences. ALIGNMENT_T* alignment = read_alignment_from_clustalw_file(filename); if (sort) { // Create a temporary array to hold sorted sequence pointers. int num_sequences = get_num_aligned_sequences(alignment); SEQ_T** sequences = (SEQ_T**) mm_malloc(num_sequences * sizeof(SEQ_T*)); // Sort the sequences by name. STRING_LIST_T* alignment_species = get_species_names(alignment); // Store the name of the reference sequence. char *ref_name = get_nth_string(*ref_seq_index, alignment_species); sort_string_list(alignment_species); // keep species alphabetical for (i=0; i<num_sequences; i++) { char *name = get_nth_string(i, alignment_species); sequences[i] = get_alignment_sequence_by_name(name, alignment); } myfree(alignment->sequences); alignment->sequences = sequences; // Find the new index of the reference sequence. *ref_seq_index = get_index_in_string_list(ref_name, alignment_species); } if (remove_allgap_seqs) { ALIGNMENT_T* new_alignment = remove_allgap_sequences(alignment); if (new_alignment != alignment) { free_alignment(alignment); alignment = new_alignment; } } return(alignment); } // read_alignment_from_file
struct ref *fetch_pack(struct fetch_pack_args *args, int fd[], struct child_process *conn, const struct ref *ref, const char *dest, struct string_list *sought, char **pack_lockfile) { struct stat st; struct ref *ref_cpy; fetch_pack_setup(); if (args->depth > 0) { if (stat(git_path("shallow"), &st)) st.st_mtime = 0; } if (sought->nr) { sort_string_list(sought); string_list_remove_duplicates(sought, 0); } if (!ref) { packet_flush(fd[1]); die("no matching remote head"); } ref_cpy = do_fetch_pack(args, fd, ref, sought, pack_lockfile); if (args->depth > 0) { static struct lock_file lock; struct cache_time mtime; struct strbuf sb = STRBUF_INIT; char *shallow = git_path("shallow"); int fd; mtime.sec = st.st_mtime; mtime.nsec = ST_MTIME_NSEC(st); if (stat(shallow, &st)) { if (mtime.sec) die("shallow file was removed during fetch"); } else if (st.st_mtime != mtime.sec #ifdef USE_NSEC || ST_MTIME_NSEC(st) != mtime.nsec #endif ) die("shallow file was changed during fetch"); fd = hold_lock_file_for_update(&lock, shallow, LOCK_DIE_ON_ERROR); if (!write_shallow_commits(&sb, 0) || write_in_full(fd, sb.buf, sb.len) != sb.len) { unlink_or_warn(shallow); rollback_lock_file(&lock); } else { commit_lock_file(&lock); } strbuf_release(&sb); } reprepare_packed_git(); return ref_cpy; }