dispatch_source_t create_source(dispatch_source_type_t type, int socket, int action) { log_detail("make source socket %d action %s\n", socket, action_name(action)); dispatch_source_t source = dispatch_source_create(type, socket, 0, queue); dispatch_source_set_event_handler(source, ^{ log_detail("source event socket %d action %s\n", socket, action_name(action)); curl_perform_action(socket, action); });
static int error_dirty_index(struct replay_opts *opts) { if (read_cache_unmerged()) return error_resolve_conflict(_(action_name(opts))); error(_("your local changes would be overwritten by %s."), _(action_name(opts))); if (advice_commit_before_merge) advise(_("commit your changes or stash them to proceed.")); return -1; }
static void read_and_refresh_cache(struct replay_opts *opts) { static struct lock_file index_lock; int index_fd = hold_locked_index(&index_lock, 0); if (read_index_preload(&the_index, NULL) < 0) die(_("git %s: failed to read the index"), action_name(opts)); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); if (the_index.cache_changed && index_fd >= 0) { if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die(_("git %s: failed to refresh the index"), action_name(opts)); } rollback_lock_file(&index_lock); }
static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) { int res; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit)); if (read_and_refresh_cache(opts)) return -1; while (todo_list->current < todo_list->nr) { struct todo_item *item = todo_list->items + todo_list->current; if (save_todo(todo_list, opts)) return -1; res = do_pick_commit(item->command, item->commit, opts); todo_list->current++; if (res) return res; } /* * Sequence of picks finished successfully; cleanup by * removing the .git/sequencer directory */ return sequencer_remove_state(opts); }
const char *pkgXmlNode::SourceArchiveName( unsigned long category ) { /* Applicable only for XML nodes designated as "release". * * Retrieve the source tarball name, if specified, from the * "tarname" property of the contained "source" element, within * an XML node designated as a "release" element. * * Returns a pointer to the text of the "tarname" property of the * contained "source" element, or NULL if the containing node does * not represent a "release", or if it does not have a contained * "source" element specifying a "tarname" property. */ const char *tag = "lic"; if( category != ACTION_LICENCE ) { /* We may have been asked to explicitly override the "source" * mapping, returning the "licence" reference instead; where * this special exception is NOT requested, then we enforce * the default case. */ category = ACTION_SOURCE; tag = "src"; } /* In either case, pkgResolvedName() determines the appropriate * archive name, which it automatically returns on the heap. */ return pkgResolvedName( this, action_name( category ), tag ); }
double UCTAgent::MCTS(const State& state, const int depth) //FIXME: no rollout phase! { if (state.absorbing() || depth > 1.0 / (1.0 - gamma)) { #if DEBUG std::cerr << "[" << state << "]"; #endif return 0.0; } if (state_counts_.count(state)) { Action action = UCB1(state, 10.0); std::pair<State, double> sample = TaxiEnv::Sample(state, action); #if DEBUG std::cerr << "[" << state << ", " << action_name(action) << "] -> "; #endif int n = state_action_counts_[state][action]; double u = qtable_[state][action]; double v = sample.second + gamma * MCTS(sample.first, depth + 1); double k = 1.0 / (n + 1); double w = u + k * (v - u); state_counts_[state] += 1; state_action_counts_[state][action] += 1; qtable_[state][action] = w; return v; } else { state_counts_[state] = 1; return Rollout(state, depth); } }
static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) { struct commit_list *cur; int res; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit)); read_and_refresh_cache(opts); for (cur = todo_list; cur; cur = cur->next) { save_todo(cur, opts); res = do_pick_commit(cur->item, opts); if (res) { if (!cur->next) /* * An error was encountered while * picking the last commit; the * sequencer state is useless now -- * the user simply needs to resolve * the conflict and commit */ remove_sequencer_state(0); return res; } } /* * Sequence of picks finished successfully; cleanup by * removing the .git/sequencer directory */ remove_sequencer_state(1); return 0; }
static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) { struct commit_list *cur; int res; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit)); read_and_refresh_cache(opts); for (cur = todo_list; cur; cur = cur->next) { save_todo(cur, opts); res = do_pick_commit(cur->item, opts); if (res) return res; } /* * Sequence of picks finished successfully; cleanup by * removing the .git/sequencer directory */ remove_sequencer_state(); return 0; }
static int fast_forward_to(const unsigned char *to, const unsigned char *from, int unborn, struct replay_opts *opts) { struct ref_transaction *transaction; struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; read_cache(); if (checkout_fast_forward(from, to, 1)) exit(128); /* the callee should have complained already */ strbuf_addf(&sb, _("%s: fast-forward"), action_name(opts)); transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, "HEAD", to, unborn ? null_sha1 : from, 0, sb.buf, &err) || ref_transaction_commit(transaction, &err)) { ref_transaction_free(transaction); error("%s", err.buf); strbuf_release(&sb); strbuf_release(&err); return -1; } strbuf_release(&sb); strbuf_release(&err); ref_transaction_free(transaction); return 0; }
static int do_recursive_merge(struct commit *base, struct commit *next, const char *base_label, const char *next_label, unsigned char *head, struct strbuf *msgbuf, struct replay_opts *opts) { struct merge_options o; struct tree *result, *next_tree, *base_tree, *head_tree; int clean, index_fd; const char **xopt; static struct lock_file index_lock; index_fd = hold_locked_index(&index_lock, 1); read_cache(); init_merge_options(&o); o.ancestor = base ? base_label : "(empty tree)"; o.branch1 = "HEAD"; o.branch2 = next ? next_label : "(empty tree)"; head_tree = parse_tree_indirect(head); next_tree = next ? next->tree : empty_tree(); base_tree = base ? base->tree : empty_tree(); for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++) parse_merge_opt(&o, *xopt); clean = merge_trees(&o, head_tree, next_tree, base_tree, &result); if (active_cache_changed && (write_cache(index_fd, active_cache, active_nr) || commit_locked_index(&index_lock))) /* TRANSLATORS: %s will be "revert" or "cherry-pick" */ die(_("%s: Unable to write new index file"), action_name(opts)); rollback_lock_file(&index_lock); if (opts->signoff) append_signoff(msgbuf, 0, 0); if (!clean) { int i; strbuf_addstr(msgbuf, "\nConflicts:\n"); for (i = 0; i < active_nr;) { const struct cache_entry *ce = active_cache[i++]; if (ce_stage(ce)) { strbuf_addch(msgbuf, '\t'); strbuf_addstr(msgbuf, ce->name); strbuf_addch(msgbuf, '\n'); while (i < active_nr && !strcmp(ce->name, active_cache[i]->name)) i++; } } } return !clean; }
/* Sets the action in ACTIONS for state STATE and the input symbol with index INPUT to VALUE. If a conflict occurs, prints an error message on stderr. */ static void set_action (unsigned char **actions, int state, int input, int value) { assert (actions != NULL); assert (state >= 0 && state < nC); assert (input >= 0 && input <= n_symbols); if (actions[state][input] != 0 && actions[state][input] != value) { char a[16], b[16]; action_name (a, value); action_name (b, actions[state][input]); fprintf (stderr, "Conflict for state %d, input %c: %s versus %s\n", state, input < n_symbols ? symbols[input].sym : '$', a, b); } actions[state][input] = value; }
static int single_pick(struct commit *cmit, struct replay_opts *opts) { int ret; setenv(GIT_REFLOG_ACTION, action_name(opts), 0); ret = do_pick_commit(cmit, opts); if (ret) return ret; finish(opts); return 0; }
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)); }
static int do_recursive_merge(struct commit *base, struct commit *next, const char *base_label, const char *next_label, unsigned char *head, struct strbuf *msgbuf, struct replay_opts *opts) { struct merge_options o; struct tree *result, *next_tree, *base_tree, *head_tree; int clean; char **xopt; static struct lock_file index_lock; hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); read_cache(); init_merge_options(&o); o.ancestor = base ? base_label : "(empty tree)"; o.branch1 = "HEAD"; o.branch2 = next ? next_label : "(empty tree)"; head_tree = parse_tree_indirect(head); next_tree = next ? next->tree : empty_tree(); base_tree = base ? base->tree : empty_tree(); for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++) parse_merge_opt(&o, *xopt); clean = merge_trees(&o, head_tree, next_tree, base_tree, &result); strbuf_release(&o.obuf); if (clean < 0) return clean; if (active_cache_changed && write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) /* TRANSLATORS: %s will be "revert" or "cherry-pick" */ return error(_("%s: Unable to write new index file"), _(action_name(opts))); rollback_lock_file(&index_lock); if (opts->signoff) append_signoff(msgbuf, 0, 0); if (!clean) append_conflicts_hint(msgbuf); return !clean; }
static int error_dirty_index(struct replay_opts *opts) { if (read_cache_unmerged()) return error_resolve_conflict(action_name(opts)); /* Different translation strings for cherry-pick and revert */ if (opts->action == REPLAY_PICK) error(_("Your local changes would be overwritten by cherry-pick.")); else error(_("Your local changes would be overwritten by revert.")); if (advice_commit_before_merge) advise(_("Commit your changes or stash them to proceed.")); return -1; }
static int fast_forward_to(const unsigned char *to, const unsigned char *from, int unborn, struct replay_opts *opts) { struct ref_lock *ref_lock; struct strbuf sb = STRBUF_INIT; int ret; read_cache(); if (checkout_fast_forward(from, to, 1)) exit(1); /* the callee should have complained already */ ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from, 0); strbuf_addf(&sb, "%s: fast-forward", action_name(opts)); ret = write_ref_sha1(ref_lock, to, sb.buf); strbuf_release(&sb); return ret; }
static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *opts) { unsigned char commit_sha1[20]; enum replay_action action; char *end_of_object_name; int saved, status, padding; if (starts_with(bol, "pick")) { action = REPLAY_PICK; bol += strlen("pick"); } else if (starts_with(bol, "revert")) { action = REPLAY_REVERT; bol += strlen("revert"); } else return NULL; /* Eat up extra spaces/ tabs before object name */ padding = strspn(bol, " \t"); if (!padding) return NULL; bol += padding; end_of_object_name = bol + strcspn(bol, " \t\n"); saved = *end_of_object_name; *end_of_object_name = '\0'; status = get_sha1(bol, commit_sha1); *end_of_object_name = saved; /* * Verify that the action matches up with the one in * opts; we don't support arbitrary instructions */ if (action != opts->action) { const char *action_str; action_str = action == REPLAY_REVERT ? "revert" : "cherry-pick"; error(_("Cannot %s during a %s"), action_str, action_name(opts)); return NULL; } if (status < 0) return NULL; return lookup_commit_reference(commit_sha1); }
void AddAgentActions(int num_actions, VariablesInfo* admissible_actions) { Variable* temp; string action_name("Action_"); temp = new Variable(action_name.append(1,'R'),1.0,GRID_SIZE); // Right ( value = 0) if (temp == NULL) { cerr << "main:AddAgentActions (R action) was NULL!" << endl; exit(NO_MEM_AVAILABLE); } temp->SetVarValue(0); admissible_actions->AddVariable(temp->Clone()); delete temp; action_name.clear(); action_name = "Action_"; temp = new Variable(action_name.append(1,'L'),1.0,GRID_SIZE); // Left (value = 1) if (temp == NULL) { cerr << "main:AddAgentActions (L action) was NULL!" << endl; exit(NO_MEM_AVAILABLE); } temp->SetVarValue(1); admissible_actions->AddVariable(temp->Clone()); delete temp; action_name.clear(); action_name = "Action_"; temp = new Variable(action_name.append(1,'U'),1.0,GRID_SIZE); // Up (value = 2) if (temp == NULL) { cerr << "main:AddAgentActions (U action) was NULL!" << endl; exit(NO_MEM_AVAILABLE); } temp->SetVarValue(2); admissible_actions->AddVariable(temp->Clone()); delete temp; action_name.clear(); action_name = "Action_"; temp = new Variable(action_name.append(1,'D'),1.0,GRID_SIZE); // Down (value = 3) if (temp == NULL) { cerr << "main:AddAgentActions (D action) was NULL!" << endl; exit(NO_MEM_AVAILABLE); } temp->SetVarValue(3); admissible_actions->AddVariable(temp->Clone()); delete temp; }
static struct commit *parse_insn_line(char *start, struct replay_opts *opts) { unsigned char commit_sha1[20]; char sha1_abbrev[40]; enum replay_action action; int insn_len = 0; char *p, *q; if (!prefixcmp(start, "pick ")) { action = CHERRY_PICK; insn_len = strlen("pick"); p = start + insn_len + 1; } else if (!prefixcmp(start, "revert ")) { action = REVERT; insn_len = strlen("revert"); p = start + insn_len + 1; } else return NULL; q = strchr(p, ' '); if (!q) return NULL; q++; strlcpy(sha1_abbrev, p, q - p); /* * Verify that the action matches up with the one in * opts; we don't support arbitrary instructions */ if (action != opts->action) { const char *action_str; action_str = action == REVERT ? "revert" : "cherry-pick"; error(_("Cannot %s during a %s"), action_str, action_name(opts)); return NULL; } if (get_sha1(sha1_abbrev, commit_sha1) < 0) return NULL; return lookup_commit_reference(commit_sha1); }
sequence_t::sequence_t( player_t* p, const std::string& sub_action_str ) : action_t( ACTION_SEQUENCE, "default", p ), waiting( false ), sequence_wait_on_ready( -1 ), current_action( -1 ), restarted( false ), last_restart( timespan_t::min() ) { trigger_gcd = timespan_t::zero(); std::vector<std::string> splits = util::string_split( sub_action_str, ":" ); if ( ! splits.empty() ) { option_t options[] = { opt_string( "name", name_str ), opt_null() }; parse_options( options, splits[ 0 ] ); } // First token is sequence options, so skip for ( size_t i = 1; i < splits.size(); ++i ) { std::string::size_type cut_pt = splits[ i ].find( ',' ); std::string action_name( splits[ i ], 0, cut_pt ); std::string action_options; if ( cut_pt != std::string::npos ) action_options.assign( splits[ i ], cut_pt + 1, std::string::npos ); action_t* a = p -> create_action( action_name, action_options ); if ( ! a ) { sim -> errorf( "Player %s has unknown sequence action: %s\n", p -> name(), splits[ i ].c_str() ); sim -> cancel(); continue; } a -> sequence = true; sub_actions.push_back( a ); } sequence_wait_on_ready = wait_on_ready; wait_on_ready = -1; }
/* Builds and outputs to stdout the action table for the parser, including enumerated types for actions and lexemes. */ static void build_action_table (void) { unsigned char **actions; int i; actions = xmalloc (sizeof *actions * nC); for (i = 0; i < nC; i++) { actions[i] = xmalloc (sizeof **actions * (n_symbols + 1)); memset (actions[i], 0, sizeof **actions * (n_symbols + 1)); } for (i = 0; i < nC; i++) { int j; for (j = 0; j < list_count (&C[i]); j++) { const struct item *item = list_item (&C[i], j); const struct production *prod = &G[item->prod]; const struct symbol *A = find_symbol (prod->left); if (item_n_after_dot (item) > 0) { struct symbol *a; a = find_symbol (item_symbol_after_dot (item)); if (!a->nonterminal) { struct list list; int k; calc_goto (&list, &C[i], a->sym); for (k = 0; k < nC; k++) if (list_equal (&list, &C[k])) set_action (actions, i, a - symbols, 2 + k); list_free (&list); } } else if (A->sym != G[0].left) { const struct set *follow_A = &A->follow; int k; for (k = 0; k < follow_A->n; k++) { int c; int index; c = follow_A->which[k]; if (c == '$') index = n_symbols; else index = find_symbol (c) - symbols; set_action (actions, i, index, 2 + nC + (prod - G)); } } if (list_contains (&C[i], 0, 1)) set_action (actions, i, n_symbols, 1); } } fputs ("/* Actions used in action_table[][] entries. */\n" "enum\n" " {\n" " err,\t/* Error. */\n" " acc,\t/* Accept. */\n" "\n" " /* Shift actions. */\n", stdout); print_enum_list ('s', 0, nC - 1); fputs ("\n" " /* Reduce actions. */\n", stdout); print_enum_list ('r', 1, n_grammar); printf ("\n" " n_states = %d,\n" " n_terminals = %d,\n" " n_nonterminals = %d,\n" " n_reductions = %d\n" " };\n" "\n" "/* Symbolic token names used in parse_table[][] second index. */\n" "enum\n" " {\n", nC, n_terminals + 1, n_nonterminals, n_grammar); for (i = 0; i < n_symbols; i++) { struct symbol *sym = &symbols[i]; int j; if (sym->nonterminal) continue; for (j = 0; j < n_tokens; j++) if (tokens[j].token == sym->sym) break; assert (j < n_tokens); printf (" %s,%*c/* %c */\n", tokens[j].name, 25 - (int) strlen (tokens[j].name), ' ', sym->sym); } fputs (" lex_stop /* $ */\n" " };\n" "\n" "/* Action table. This is action[][] from Fig. 4.30, \"LR parsing\n" " program\", in Aho, Sethi, and Ullman. */\n" "static const unsigned char action_table[n_states][n_terminals] =\n" " {\n" " /* ", stdout); for (i = 0; i < n_symbols; i++) if (!symbols[i].nonterminal) printf (" %c ", symbols[i].sym); fputs (" $ */\n", stdout); for (i = 0; i < nC; i++) { int j; printf (" /*%3d */ {", i); for (j = 0; j <= n_symbols; j++) if (j == n_symbols || !symbols[j].nonterminal) { char buf[16]; if (j != 0) putchar (','); action_name (buf, actions[i][j]); printf ("%3s", buf); } fputs ("},\n", stdout); } fputs (" };\n\n", stdout); for (i = 0; i < nC; i++) free (actions[i]); free (actions); }
static int single_pick(struct commit *cmit, struct replay_opts *opts) { setenv(GIT_REFLOG_ACTION, action_name(opts), 0); return do_pick_commit(cmit, opts); }
static void parse_args(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); int reset = 0; int contin = 0; struct option options[] = { OPT_BOOLEAN(0, "reset", &reset, "forget the current operation"), OPT_BOOLEAN(0, "continue", &contin, "continue the current operation"), OPT_BOOLEAN('n', "no-commit", &opts->no_commit, "don't automatically commit"), OPT_BOOLEAN('e', "edit", &opts->edit, "edit the commit message"), OPT_NOOP_NOARG('r', NULL), OPT_BOOLEAN('s', "signoff", &opts->signoff, "add Signed-off-by:"), OPT_INTEGER('m', "mainline", &opts->mainline, "parent number"), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), OPT_STRING(0, "strategy", &opts->strategy, "strategy", "merge strategy"), OPT_CALLBACK('X', "strategy-option", &opts, "option", "option for merge strategy", option_parse_x), OPT_END(), OPT_END(), OPT_END(), }; if (opts->action == CHERRY_PICK) { struct option cp_extra[] = { OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"), OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"), OPT_END(), }; if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra)) die(_("program error")); } opts->commit_argc = parse_options(argc, argv, NULL, options, usage_str, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); /* Check for incompatible subcommands */ verify_opt_mutually_compatible(me, "--reset", reset, "--continue", contin, NULL); /* Set the subcommand */ if (reset) opts->subcommand = REPLAY_RESET; else if (contin) opts->subcommand = REPLAY_CONTINUE; else opts->subcommand = REPLAY_NONE; /* Check for incompatible command line arguments */ if (opts->subcommand != REPLAY_NONE) { char *this_operation; if (opts->subcommand == REPLAY_RESET) this_operation = "--reset"; else this_operation = "--continue"; verify_opt_compatible(me, this_operation, "--no-commit", opts->no_commit, "--signoff", opts->signoff, "--mainline", opts->mainline, "--strategy", opts->strategy ? 1 : 0, "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, NULL); } else if (opts->commit_argc < 2) usage_with_options(usage_str, options); if (opts->allow_ff) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit, "-x", opts->record_origin, "--edit", opts->edit, NULL); opts->commit_argv = argv; }
static void parse_args(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); int cmd = 0; struct option options[] = { OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'), OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'), OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'), OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), OPT_NOOP_NOARG('r', NULL), OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")), OPT_INTEGER('m', "mainline", &opts->mainline, N_("parent number")), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")), OPT_CALLBACK('X', "strategy-option", &opts, N_("option"), N_("option for merge strategy"), option_parse_x), OPT_END(), OPT_END(), OPT_END(), OPT_END(), OPT_END(), OPT_END(), }; if (opts->action == REPLAY_PICK) { struct option cp_extra[] = { OPT_BOOL('x', NULL, &opts->record_origin, N_("append commit name")), OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")), OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")), OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")), OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")), OPT_END(), }; if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra)) die(_("program error")); } argc = parse_options(argc, argv, NULL, options, usage_str, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); /* implies allow_empty */ if (opts->keep_redundant_commits) opts->allow_empty = 1; /* Set the subcommand */ if (cmd == 'q') opts->subcommand = REPLAY_REMOVE_STATE; else if (cmd == 'c') opts->subcommand = REPLAY_CONTINUE; else if (cmd == 'a') opts->subcommand = REPLAY_ROLLBACK; else opts->subcommand = REPLAY_NONE; /* Check for incompatible command line arguments */ if (opts->subcommand != REPLAY_NONE) { char *this_operation; if (opts->subcommand == REPLAY_REMOVE_STATE) this_operation = "--quit"; else if (opts->subcommand == REPLAY_CONTINUE) this_operation = "--continue"; else { assert(opts->subcommand == REPLAY_ROLLBACK); this_operation = "--abort"; } verify_opt_compatible(me, this_operation, "--no-commit", opts->no_commit, "--signoff", opts->signoff, "--mainline", opts->mainline, "--strategy", opts->strategy ? 1 : 0, "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, NULL); } if (opts->allow_ff) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit, "-x", opts->record_origin, "--edit", opts->edit, NULL); if (opts->subcommand != REPLAY_NONE) { opts->revs = NULL; } else { struct setup_revision_opt s_r_opt; opts->revs = xmalloc(sizeof(*opts->revs)); init_revisions(opts->revs, NULL); opts->revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED; if (argc < 2) usage_with_options(usage_str, options); if (!strcmp(argv[1], "-")) argv[1] = "@{-1}"; memset(&s_r_opt, 0, sizeof(s_r_opt)); s_r_opt.assume_dashdash = 1; argc = setup_revisions(argc, argv, opts->revs, &s_r_opt); } if (argc > 1) usage_with_options(usage_str, options); }
static int do_pick_commit(struct commit *commit, struct replay_opts *opts) { unsigned char head[20]; struct commit *base, *next, *parent; const char *base_label, *next_label; struct commit_message msg = { NULL, NULL, NULL, NULL }; struct strbuf msgbuf = STRBUF_INIT; int res, unborn = 0, allow; if (opts->no_commit) { /* * We do not intend to commit immediately. We just want to * merge the differences in, so let's compute the tree * that represents the "current" state for merge-recursive * to work on. */ if (write_cache_as_tree(head, 0, NULL)) die (_("Your index file is unmerged.")); } else { unborn = get_sha1("HEAD", head); if (unborn) hashcpy(head, EMPTY_TREE_SHA1_BIN); if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0)) return error_dirty_index(opts); } discard_cache(); if (!commit->parents) { parent = NULL; } else if (commit->parents->next) { /* Reverting or cherry-picking a merge commit */ int cnt; struct commit_list *p; if (!opts->mainline) return error(_("Commit %s is a merge but no -m option was given."), oid_to_hex(&commit->object.oid)); for (cnt = 1, p = commit->parents; cnt != opts->mainline && p; cnt++) p = p->next; if (cnt != opts->mainline || !p) return error(_("Commit %s does not have parent %d"), oid_to_hex(&commit->object.oid), opts->mainline); parent = p->item; } else if (0 < opts->mainline) return error(_("Mainline was specified but commit %s is not a merge."), oid_to_hex(&commit->object.oid)); else parent = commit->parents->item; if (opts->allow_ff && ((parent && !hashcmp(parent->object.oid.hash, head)) || (!parent && unborn))) return fast_forward_to(commit->object.oid.hash, head, unborn, opts); if (parent && parse_commit(parent) < 0) /* TRANSLATORS: The first %s will be "revert" or "cherry-pick", the second %s a SHA1 */ return error(_("%s: cannot parse parent commit %s"), action_name(opts), oid_to_hex(&parent->object.oid)); if (get_message(commit, &msg) != 0) return error(_("Cannot get commit message for %s"), oid_to_hex(&commit->object.oid)); /* * "commit" is an existing commit. We would want to apply * the difference it introduces since its first parent "prev" * on top of the current HEAD if we are cherry-pick. Or the * reverse of it if we are revert. */ if (opts->action == REPLAY_REVERT) { base = commit; base_label = msg.label; next = parent; next_label = msg.parent_label; strbuf_addstr(&msgbuf, "Revert \""); strbuf_addstr(&msgbuf, msg.subject); strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit "); strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid)); if (commit->parents && commit->parents->next) { strbuf_addstr(&msgbuf, ", reversing\nchanges made to "); strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid)); } strbuf_addstr(&msgbuf, ".\n"); } else { const char *p; base = parent; base_label = msg.parent_label; next = commit; next_label = msg.label; /* * Append the commit log message to msgbuf; it starts * after the tree, parent, author, committer * information followed by "\n\n". */ p = strstr(msg.message, "\n\n"); if (p) strbuf_addstr(&msgbuf, skip_blank_lines(p + 2)); if (opts->record_origin) { if (!has_conforming_footer(&msgbuf, NULL, 0)) strbuf_addch(&msgbuf, '\n'); strbuf_addstr(&msgbuf, cherry_picked_prefix); strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid)); strbuf_addstr(&msgbuf, ")\n"); } } if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REPLAY_REVERT) { res = do_recursive_merge(base, next, base_label, next_label, head, &msgbuf, opts); write_message(&msgbuf, git_path_merge_msg()); } else { struct commit_list *common = NULL; struct commit_list *remotes = NULL; write_message(&msgbuf, git_path_merge_msg()); commit_list_insert(base, &common); commit_list_insert(next, &remotes); res = try_merge_command(opts->strategy, opts->xopts_nr, opts->xopts, common, sha1_to_hex(head), remotes); free_commit_list(common); free_commit_list(remotes); } /* * If the merge was clean or if it failed due to conflict, we write * CHERRY_PICK_HEAD for the subsequent invocation of commit to use. * However, if the merge did not even start, then we don't want to * write it at all. */ if (opts->action == REPLAY_PICK && !opts->no_commit && (res == 0 || res == 1)) update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); if (opts->action == REPLAY_REVERT && ((opts->no_commit && res == 0) || res == 1)) update_ref(NULL, "REVERT_HEAD", commit->object.oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); if (res) { error(opts->action == REPLAY_REVERT ? _("could not revert %s... %s") : _("could not apply %s... %s"), find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), msg.subject); print_advice(res == 1, opts); rerere(opts->allow_rerere_auto); goto leave; } allow = allow_empty(opts, commit); if (allow < 0) { res = allow; goto leave; } if (!opts->no_commit) res = run_git_commit(git_path_merge_msg(), opts, allow); leave: free_message(commit, &msg); return res; }
static void parse_args(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); int remove_state = 0; int contin = 0; int rollback = 0; struct option options[] = { OPT_BOOLEAN(0, "quit", &remove_state, "end revert or cherry-pick sequence"), OPT_BOOLEAN(0, "continue", &contin, "resume revert or cherry-pick sequence"), OPT_BOOLEAN(0, "abort", &rollback, "cancel revert or cherry-pick sequence"), OPT_BOOLEAN('n', "no-commit", &opts->no_commit, "don't automatically commit"), OPT_BOOLEAN('e', "edit", &opts->edit, "edit the commit message"), OPT_NOOP_NOARG('r', NULL), OPT_BOOLEAN('s', "signoff", &opts->signoff, "add Signed-off-by:"), OPT_INTEGER('m', "mainline", &opts->mainline, "parent number"), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), OPT_STRING(0, "strategy", &opts->strategy, "strategy", "merge strategy"), OPT_CALLBACK('X', "strategy-option", &opts, "option", "option for merge strategy", option_parse_x), OPT_END(), OPT_END(), OPT_END(), }; if (opts->action == CHERRY_PICK) { struct option cp_extra[] = { OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"), OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"), OPT_END(), }; if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra)) die(_("program error")); } argc = parse_options(argc, argv, NULL, options, usage_str, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); /* Check for incompatible subcommands */ verify_opt_mutually_compatible(me, "--quit", remove_state, "--continue", contin, "--abort", rollback, NULL); /* Set the subcommand */ if (remove_state) opts->subcommand = REPLAY_REMOVE_STATE; else if (contin) opts->subcommand = REPLAY_CONTINUE; else if (rollback) opts->subcommand = REPLAY_ROLLBACK; else opts->subcommand = REPLAY_NONE; /* Check for incompatible command line arguments */ if (opts->subcommand != REPLAY_NONE) { char *this_operation; if (opts->subcommand == REPLAY_REMOVE_STATE) this_operation = "--quit"; else if (opts->subcommand == REPLAY_CONTINUE) this_operation = "--continue"; else { assert(opts->subcommand == REPLAY_ROLLBACK); this_operation = "--abort"; } verify_opt_compatible(me, this_operation, "--no-commit", opts->no_commit, "--signoff", opts->signoff, "--mainline", opts->mainline, "--strategy", opts->strategy ? 1 : 0, "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, NULL); } if (opts->allow_ff) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit, "-x", opts->record_origin, "--edit", opts->edit, NULL); if (opts->subcommand != REPLAY_NONE) { opts->revs = NULL; } else { opts->revs = xmalloc(sizeof(*opts->revs)); init_revisions(opts->revs, NULL); opts->revs->no_walk = 1; if (argc < 2) usage_with_options(usage_str, options); argc = setup_revisions(argc, argv, opts->revs, NULL); } if (argc > 1) usage_with_options(usage_str, options); }
int sandbox_excute(sandbox_t *psbox) { pid_t child; child = fork(); if(child < 0) { psbox->result = INTERNAL_ERROR; __TRACE_LN(__TRACE_KEY, "Error : fork target process failed"); return -1; } else if(child == 0) { _exit(_sandbox_excute(&psbox->task)); } else { __TRACE_LN(__TRACE_DBG, "child pid : %d", child); pid_t wait_result = 0; int wait_status = 0; proc_t proc_data = { 0 }; int in_syscall = 1; event_t e = { 0 }; action_t action = { 0 }; /* Have signals kill the prisoner but not self (if possible). */ /* In fact, I have deleted the '-' before "child" so this may not be necessary */ sig_t terminate_signal; sig_t interrupt_signal; sig_t quit_signal; terminate_signal = signal(SIGTERM, SIG_IGN); interrupt_signal = signal(SIGINT, SIG_IGN); quit_signal = signal(SIGQUIT, SIG_IGN); /* Get wallclock start time */ gettimeofday(&psbox->stat.start_timestamp, NULL); /* get initial resource usage */ wait_result = wait4(child, &wait_status, 0, &psbox->stat.ru); memcpy(&psbox->stat.init_ru, &psbox->stat.ru, sizeof(struct rusage)); /* trace loop */ __TRACE_LN(__TRACE_DBG, "Enter trace loop"); bool internal_error = false; do{ if(!wait_result) /* wait_result == 0 : noting happent */ { goto cont; } memset(&e, 0, sizeof(event_t)); memset(&action, 0, sizeof(action_t)); if(WIFSTOPPED(wait_status)) { switch(WSTOPSIG(wait_status)) { case SIGALRM: POST_EVENT(e, EVENT_QUOTA, QUOTA_WALLCLOCK); break; case SIGXCPU: case SIGPROF: case SIGVTALRM: POST_EVENT(e, EVENT_QUOTA, QUOTA_CPUTIME); break; case SIGML: POST_EVENT(e, EVENT_QUOTA, QUOTA_MEMORY); break; case SIGXFSZ: POST_EVENT(e, EVENT_QUOTA, QUOTA_OUTPUT); break; case SIGTRAP: if(!proc_probe(child, &proc_data)) { /* error */ internal_error = true; psbox->result = INTERNAL_ERROR; kill(child, SIGKILL); __TRACE_LN(__TRACE_KEY, "Internal Error : porc_probe() failed"); break; } if(psbox->stat.vsize_peak < proc_data.vsize) { psbox->stat.vsize_peak = proc_data.vsize; if(psbox->stat.vsize_peak > psbox->task.quota[QUOTA_MEMORY]) { kill(child, SIGML); } } /* system call or system call return */ if(in_syscall) { in_syscall = 0; POST_EVENT(e, EVENT_SYSTEM_CALL_RETURN, SYSCALL_NO(&proc_data), SYSCALL_RETVAL(&proc_data)); } else { in_syscall = 1; POST_EVENT(e, EVENT_SYSTEM_CALL, SYSCALL_NO(&proc_data), SYSCALL_ARG1(&proc_data), SYSCALL_ARG2(&proc_data), SYSCALL_ARG3(&proc_data), SYSCALL_ARG4(&proc_data), SYSCALL_ARG5(&proc_data)); } break; default: POST_EVENT(e, EVENT_SIGNAL, WSTOPSIG(wait_status)); } } else if(WIFSIGNALED(wait_status)) { POST_EVENT(e, EVENT_SIGNAL, WTERMSIG(wait_status)); } else if(WIFEXITED(wait_status)) { psbox->stat.data.exitcode = WEXITSTATUS(wait_status); POST_EVENT(e, EVENT_EXIT, WEXITSTATUS(wait_status)); } /* sink event */ psbox->policy(&e, &action); __TRACE(__TRACE_DBG, "Event type : %s", event_name(e.type)); __TRACE_LN(__TRACE_DBG, "\tEvent data : %ld %ld %ld %ld %ld %ld", e.data._bitmap_.a, e.data._bitmap_.b, e.data._bitmap_.c, e.data._bitmap_.d, e.data._bitmap_.e, e.data._bitmap_.f); __TRACE(__TRACE_DBG, "Action type : %s", action_name(action.type)); __TRACE_LN(__TRACE_DBG, "\tAction data : %ld %ld", action.data._bitmap_.a, action.data._bitmap_.b); /* action */ switch(action.type) { case ACTION_CONTINUE: if(!trace_next(&proc_data)) { internal_error = true; psbox->result = INTERNAL_ERROR; kill(child, SIGKILL); __TRACE_LN(__TRACE_KEY, "Internal Error : trace_next() failed"); break; } goto cont; case ACTION_KILL: trace_kill(&proc_data, 0); psbox->result = action.data._kill.result; if(psbox->result == RUNTIME_ERROR) { psbox->stat.data.signo = action.data._kill.data; } else if(psbox->result == RESTRICTED_FUNCTION) { psbox->stat.data.rf = action.data._kill.data; } kill(child, SIGKILL); break; case ACTION_EXIT: psbox->stat.data.exitcode = action.data._exit.code; if(psbox->stat.data.exitcode) { __TRACE_LN(__TRACE_DBG, "exit code : %ld", psbox->stat.data.exitcode); psbox->result = ABNORMAL_TERMINATION; } /* else { psbox->result = PENDED; } */ break; } break; cont: /* trace infomation */ __TRACE_LN(__TRACE_DBG, "----------------------wait4()----------------------"); }while(!internal_error && (wait_result = wait4(child, &wait_status, 0, &psbox->stat.ru)) >= 0); /* if the sandbox's result is PENDED, the prisoned process is exited nomally */ /* Get wallclock stop time (call a second time to compensate overhead) */ gettimeofday(&psbox->stat.end_timestamp, NULL); /* Restore signal handlers */ signal(SIGTERM, interrupt_signal); signal(SIGINT, interrupt_signal); signal(SIGQUIT, quit_signal); } return 0; }
static int single_pick(struct commit *cmit, struct replay_opts *opts) { setenv(GIT_REFLOG_ACTION, action_name(opts), 0); return do_pick_commit(opts->action == REPLAY_PICK ? TODO_PICK : TODO_REVERT, cmit, opts); }
static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); int cmd = 0; struct option base_options[] = { OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'), OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'), OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'), OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), OPT_NOOP_NOARG('r', NULL), OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")), OPT_CALLBACK('m', "mainline", opts, N_("parent-number"), N_("select mainline parent"), option_parse_m), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")), OPT_CALLBACK('X', "strategy-option", &opts, N_("option"), N_("option for merge strategy"), option_parse_x), { OPTION_STRING, 'S', "gpg-sign", &opts->gpg_sign, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, OPT_END() }; struct option *options = base_options; if (opts->action == REPLAY_PICK) { struct option cp_extra[] = { OPT_BOOL('x', NULL, &opts->record_origin, N_("append commit name")), OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")), OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")), OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")), OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")), OPT_END(), }; options = parse_options_concat(options, cp_extra); } argc = parse_options(argc, argv, NULL, options, usage_str, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); /* implies allow_empty */ if (opts->keep_redundant_commits) opts->allow_empty = 1; /* Check for incompatible command line arguments */ if (cmd) { char *this_operation; if (cmd == 'q') this_operation = "--quit"; else if (cmd == 'c') this_operation = "--continue"; else { assert(cmd == 'a'); this_operation = "--abort"; } verify_opt_compatible(me, this_operation, "--no-commit", opts->no_commit, "--signoff", opts->signoff, "--mainline", opts->mainline, "--strategy", opts->strategy ? 1 : 0, "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, "--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE, "--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE, NULL); } if (opts->allow_ff) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, "--no-commit", opts->no_commit, "-x", opts->record_origin, "--edit", opts->edit, NULL); if (cmd) { opts->revs = NULL; } else { struct setup_revision_opt s_r_opt; opts->revs = xmalloc(sizeof(*opts->revs)); init_revisions(opts->revs, NULL); opts->revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED; if (argc < 2) usage_with_options(usage_str, options); if (!strcmp(argv[1], "-")) argv[1] = "@{-1}"; memset(&s_r_opt, 0, sizeof(s_r_opt)); s_r_opt.assume_dashdash = 1; argc = setup_revisions(argc, argv, opts->revs, &s_r_opt); } if (argc > 1) usage_with_options(usage_str, options); /* These option values will be free()d */ opts->gpg_sign = xstrdup_or_null(opts->gpg_sign); opts->strategy = xstrdup_or_null(opts->strategy); if (cmd == 'q') { int ret = sequencer_remove_state(opts); if (!ret) remove_branch_state(); return ret; } if (cmd == 'c') return sequencer_continue(opts); if (cmd == 'a') return sequencer_rollback(opts); return sequencer_pick_revisions(opts); }
static action_name get_name() { return action_name(NAME); }