static int pick_revisions(struct replay_opts *opts) { struct commit_list *todo_list = NULL; unsigned char sha1[20]; read_and_refresh_cache(opts); /* * Decide what to do depending on the arguments; a fresh * cherry-pick should be handled differently from an existing * one that is being continued */ if (opts->subcommand == REPLAY_RESET) { remove_sequencer_state(1); return 0; } else if (opts->subcommand == REPLAY_CONTINUE) { if (!file_exists(git_path(SEQ_TODO_FILE))) goto error; read_populate_opts(&opts); read_populate_todo(&todo_list, opts); /* Verify that the conflict has been resolved */ if (!index_differs_from("HEAD", 0)) todo_list = todo_list->next; } else { /* * Start a new cherry-pick/ revert sequence; but * first, make sure that an existing one isn't in * progress */ walk_revs_populate_todo(&todo_list, opts); if (create_seq_dir() < 0) { error(_("A cherry-pick or revert is in progress.")); advise(_("Use --continue to continue the operation")); advise(_("or --reset to forget about it")); return -1; } if (get_sha1("HEAD", sha1)) { if (opts->action == REVERT) return error(_("Can't revert as initial commit")); return error(_("Can't cherry-pick into empty head")); } save_head(sha1_to_hex(sha1)); save_opts(opts); } return pick_commits(todo_list, opts); error: return error(_("No %s in progress"), action_name(opts)); }
/****** save_tab ************************************************************** PROTO void save_tab(catstruct *cat, tabstruct *tab) PURPOSE Save a FITS table. INPUT pointer to the catalog structure, pointer to the table structure. OUTPUT -. NOTES -. AUTHOR E. Bertin (IAP & Leiden observatory) VERSION 09/09/2003 ***/ void save_tab(catstruct *cat, tabstruct *tab) { catstruct *tabcat; keystruct *key; tabstruct *keytab; KINGSIZE_T tabsize; KINGLONG size; int b,j,k,o, nbytes,nkey,nobj,spoonful, tabflag, larrayin,larrayout; char *buf, *inbuf, *outbuf, *fptr,*ptr; int esize; /* Make the table parameters reflect its content*/ update_tab(tab); /* The header itself*/ tabflag = save_head(cat, tab)==RETURN_OK?1:0; /* Allocate memory for the output buffer */ tabsize = 0; tabcat = NULL; /* to satisfy gcc -Wall */ inbuf = NULL; /* to satisfy gcc -Wall */ if (tabflag) { /*-- If segment is a binary table, save it row by row */ QMALLOC(outbuf, char, (larrayout = tab->naxisn[0])); nkey = tab->nkey; tabsize = larrayin = 0; for (j=tab->nseg; j--;) { update_tab(tab); /*---- Scan keys to find the reference tab and other things*/ keytab = NULL; key = tab->key; for (k=nkey; k--; key = key->nextkey) if (!key->ptr) { keytab = key->tab; tabcat = keytab->cat; } /*---- If table contains some keys with no ptrs, we have to access a file */ if (keytab) { QMALLOC(inbuf, char, (larrayin = keytab->naxisn[0])); if (open_cat(tabcat, READ_ONLY) != RETURN_OK) error(EXIT_FAILURE, "*Error*: Cannot access ", tabcat->filename); QFSEEK(tabcat->file, keytab->bodypos, SEEK_SET, tabcat->filename); } nobj = tab->naxisn[1]; for (o=0; o<nobj; o++) { if (keytab) QFREAD(inbuf, larrayin, tabcat->file, tabcat->filename); fptr = outbuf; for (k=nkey; k--; key = key->nextkey) { nbytes = key->nbytes; ptr = key->ptr? (char *)key->ptr+nbytes*o:inbuf+key->pos; for (b=nbytes; b--;) *(fptr++) = *(ptr++); if (bswapflag) if (key->ptr) { esize = t_size[key->ttype]; swapbytes(fptr-nbytes, esize, nbytes/esize); } } QFWRITE(outbuf, larrayout, cat->file, cat->filename); } if (keytab) { free(inbuf); if (close_cat(tabcat) != RETURN_OK) error(EXIT_FAILURE, "*Error*: Problem while closing", tabcat->filename); } tabsize += tab->tabsize; tab = tab->nexttab; } free(outbuf); } else {
int sequencer_pick_revisions(struct replay_opts *opts) { struct commit_list *todo_list = NULL; unsigned char sha1[20]; if (opts->subcommand == REPLAY_NONE) assert(opts->revs); read_and_refresh_cache(opts); /* * Decide what to do depending on the arguments; a fresh * cherry-pick should be handled differently from an existing * one that is being continued */ if (opts->subcommand == REPLAY_REMOVE_STATE) { remove_sequencer_state(); return 0; } if (opts->subcommand == REPLAY_ROLLBACK) return sequencer_rollback(opts); if (opts->subcommand == REPLAY_CONTINUE) return sequencer_continue(opts); /* * If we were called as "git cherry-pick <commit>", just * cherry-pick/revert it, set CHERRY_PICK_HEAD / * REVERT_HEAD, and don't touch the sequencer state. * This means it is possible to cherry-pick in the middle * of a cherry-pick sequence. */ if (opts->revs->cmdline.nr == 1 && opts->revs->cmdline.rev->whence == REV_CMD_REV && opts->revs->no_walk && !opts->revs->cmdline.rev->flags) { struct commit *cmit; if (prepare_revision_walk(opts->revs)) die(_("revision walk setup failed")); cmit = get_revision(opts->revs); if (!cmit || get_revision(opts->revs)) die("BUG: expected exactly one commit from walk"); return single_pick(cmit, opts); } /* * Start a new cherry-pick/ revert sequence; but * first, make sure that an existing one isn't in * progress */ walk_revs_populate_todo(&todo_list, opts); if (create_seq_dir() < 0) return -1; if (get_sha1("HEAD", sha1)) { if (opts->action == REPLAY_REVERT) return error(_("Can't revert as initial commit")); return error(_("Can't cherry-pick into empty head")); } save_head(sha1_to_hex(sha1)); save_opts(opts); return pick_commits(todo_list, opts); }