void hit_notes(int column){ int note_hit_height = 20; for(int i=0;i<n_notes;i++){ if(notes[i].column == column){ int difference = abs(notes[i].y - 40 + note_sprite->height); if(difference < 4){ accuracy_feedback = accuracy_perfect; score_perfect++; score_combo++; score_greatest_combo = MAX(score_greatest_combo, score_combo); feedback_counter = 20; remove_note(i--); }else if(difference < 10){ accuracy_feedback = accuracy_great; score_combo++; score_greatest_combo = MAX(score_greatest_combo, score_combo); score_great++; feedback_counter = 20; remove_note(i--); }else if(difference < 20){ accuracy_feedback = accuracy_OK; score_OK++; score_combo++; score_greatest_combo = MAX(score_greatest_combo, score_combo); feedback_counter = 20; remove_note(i--); } } } }
static int remove_cmd(int argc, const char **argv, const char *prefix) { struct option options[] = { OPT_END() }; const char *object_ref; struct notes_tree *t; unsigned char object[20]; argc = parse_options(argc, argv, prefix, options, git_notes_remove_usage, 0); if (1 < argc) { error("too many parameters"); usage_with_options(git_notes_remove_usage, options); } object_ref = argc ? argv[0] : "HEAD"; if (get_sha1(object_ref, object)) die("Failed to resolve '%s' as a valid ref.", object_ref); t = init_notes_check("remove"); fprintf(stderr, "Removing note for object %s\n", sha1_to_hex(object)); remove_note(t, object); commit_notes(t, "Notes removed by 'git notes remove'"); free_notes(t); return 0; }
void add_note (guint day, guint month, guint year, gchar *color_str, gchar *text_note, GUI *appGUI) { struct note *a; if (text_note != NULL) { a = g_malloc(sizeof(struct note)); g_assert (a != NULL); a->day = day; a->month = month; a->year = year; if (color_str != NULL) { a->color = g_strdup(color_str); } else { a->color = NULL; } a->note = g_strdup(text_note); remove_note (day, month, year, appGUI); /* FIXME: check STACK here! */ appGUI->cal->notes_list = g_slist_append (appGUI->cal->notes_list, a); } }
void remove_article(player *p,char *str) { note *article,*prev,*scan; char *oldstack; oldstack=stack; article=find_news_article(atoi(str)); if (!article) { sprintf(stack,"No such news article '%s'\n",str); stack=end_string(stack); tell_player(p,oldstack); stack=oldstack; return; } strcpy(stack,article->name); lower_case(stack); if (!(p->residency&(LOWER_ADMIN|ADMIN)) && strcmp(stack,p->lower_name)) { tell_player(p,"You can't remove an article that isn't yours.\n"); return; } scan=find_note(news_start); if (scan==article) news_start=article->next_sent; else { do { prev=scan; scan=find_note(scan->next_sent); } while(scan!=article); prev->next_sent=article->next_sent; } news_count--; remove_note(article); tell_player(p,"Article removed.\n"); stack=oldstack; }
static void init_label_info (rtx f) { rtx insn; for (insn = f; insn; insn = NEXT_INSN (insn)) { if (LABEL_P (insn)) LABEL_NUSES (insn) = (LABEL_PRESERVE_P (insn) != 0); /* REG_LABEL_TARGET notes (including the JUMP_LABEL field) are sticky and not reset here; that way we won't lose association with a label when e.g. the source for a target register disappears out of reach for targets that may use jump-target registers. Jump transformations are supposed to transform any REG_LABEL_TARGET notes. The target label reference in a branch may disappear from the branch (and from the instruction before it) for other reasons, like register allocation. */ if (INSN_P (insn)) { rtx note, next; for (note = REG_NOTES (insn); note; note = next) { next = XEXP (note, 1); if (REG_NOTE_KIND (note) == REG_LABEL_OPERAND && ! reg_mentioned_p (XEXP (note, 0), PATTERN (insn))) remove_note (insn, note); } } } }
static int merge_one_change_manual(struct notes_merge_options *o, struct notes_merge_pair *p, struct notes_tree *t) { const char *lref = o->local_ref ? o->local_ref : "local version"; const char *rref = o->remote_ref ? o->remote_ref : "remote version"; trace_printf("\t\t\tmerge_one_change_manual(obj = %.7s, base = %.7s, " "local = %.7s, remote = %.7s)\n", oid_to_hex(&p->obj), oid_to_hex(&p->base), oid_to_hex(&p->local), oid_to_hex(&p->remote)); /* add "Conflicts:" section to commit message first time through */ if (!o->has_worktree) strbuf_addstr(&(o->commit_msg), "\n\nConflicts:\n"); strbuf_addf(&(o->commit_msg), "\t%s\n", oid_to_hex(&p->obj)); if (o->verbosity >= 2) printf("Auto-merging notes for %s\n", oid_to_hex(&p->obj)); check_notes_merge_worktree(o); if (is_null_oid(&p->local)) { /* D/F conflict, checkout p->remote */ assert(!is_null_oid(&p->remote)); if (o->verbosity >= 1) printf("CONFLICT (delete/modify): Notes for object %s " "deleted in %s and modified in %s. Version from %s " "left in tree.\n", oid_to_hex(&p->obj), lref, rref, rref); write_note_to_worktree(&p->obj, &p->remote); } else if (is_null_oid(&p->remote)) { /* D/F conflict, checkout p->local */ assert(!is_null_oid(&p->local)); if (o->verbosity >= 1) printf("CONFLICT (delete/modify): Notes for object %s " "deleted in %s and modified in %s. Version from %s " "left in tree.\n", oid_to_hex(&p->obj), rref, lref, lref); write_note_to_worktree(&p->obj, &p->local); } else { /* "regular" conflict, checkout result of ll_merge() */ const char *reason = "content"; if (is_null_oid(&p->base)) reason = "add/add"; assert(!is_null_oid(&p->local)); assert(!is_null_oid(&p->remote)); if (o->verbosity >= 1) printf("CONFLICT (%s): Merge conflict in notes for " "object %s\n", reason, oid_to_hex(&p->obj)); ll_merge_in_worktree(o, p); } trace_printf("\t\t\tremoving from partial merge result\n"); remove_note(t, p->obj.hash); return 1; }
static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag) { int status; unsigned char sha1[20]; if (get_sha1(name, sha1)) return error(_("Failed to resolve '%s' as a valid ref."), name); status = remove_note(t, sha1); if (status) fprintf(stderr, _("Object %s has no note\n"), name); else fprintf(stderr, _("Removing note for object %s\n"), name); return (flag & IGNORE_MISSING) ? 0 : status; }
void prune_notes(struct notes_tree *t) { struct note_delete_list *l = NULL; if (!t) t = &default_notes_tree; assert(t->initialized); for_each_note(t, 0, prune_notes_helper, &l); while (l) { remove_note(t, l->sha1); l = l->next; } }
void prune_notes(struct notes_tree *t, int flags) { struct note_delete_list *l = NULL; if (!t) t = &default_notes_tree; assert(t->initialized); for_each_note(t, 0, prune_notes_helper, &l); while (l) { if (flags & NOTES_PRUNE_VERBOSE) printf("%s\n", sha1_to_hex(l->sha1)); if (!(flags & NOTES_PRUNE_DRYRUN)) remove_note(t, l->sha1); l = l->next; } }
void remove_any_note(note *n) { saved_player *sp; note *scan=0; char *oldstack; int *change; int recursive=0; oldstack=stack; if (n->flags&NEWS_ARTICLE) { scan=find_note(news_start); change=&news_start; while(scan && scan!=n) { change=&(scan->next_sent); scan=find_note(scan->next_sent); } if (scan==n) news_count--; } else { strcpy(stack,n->name); lower_case(stack); stack=end_string(stack); sp=find_saved_player(oldstack); if (!sp) { log("error","Bad owner name in mail(1)"); log("error",oldstack); recursive=n->next_sent; scan=0; } else { change=&(sp->mail_sent); scan=find_note(sp->mail_sent); while(scan && scan!=n) { change=&(scan->next_sent); scan=find_note(scan->next_sent); } } } if (scan==n) (*change)=n->next_sent; remove_note(n); if (recursive) unlink_mail(find_note(recursive)); stack=oldstack; }
static void purge_reg_equiv_notes (void) { rtx insn; for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) { while (1) { rtx note = find_reg_note (insn, REG_EQUIV, 0); if (note) { /* Remove the note and keep looking at the notes for this insn. */ remove_note (insn, note); continue; } break; } } }
static void state_resume(){ total_notes = 0; eeds_set_leds(0xAA); score_OK = 0; score_perfect = 0; score_great = 0; score_combo = 0; score_greatest_combo = 0; song = songs[active_selection]; elapsed_time_in_ms = -song->offset_in_ms - 43; beat = 0; measure = 0; beats_per_measure = 4; ms_since_last_beat = 0; current_bpm_index = 1; current_bpm = song->BPMs[current_bpm_index]; need_to_draw_song_bg = 1; ms_per_measure = 4*60000000 / current_bpm; while(n_notes > 0) remove_note(0); char path_to_bg[256]; sprintf(path_to_bg, "res/Songs/%s/%s.bmp", song->basename, song->basename); /* load song background */ FILE* fp = fopen(path_to_bg, "rb"); song_bg = eeds_load_bmp(fp); fclose(fp); /* load background overlay */ fp = fopen("res/game_bg.bmp", "rb"); game_bg = eeds_load_bmp(fp); fclose(fp); /* merge song and background overlay */ merge_bgs(); char path_to_song[256]; sprintf(path_to_song, "res/Songs/%s/%s.raw", song->basename, song->basename); audio_play(path_to_song); }
void unlink_mail(note *m) { char *oldstack,*temp; saved_player *sp; int *change,recursive=0; note *scan,*tmp; if (!m) return; oldstack=stack; strcpy(stack,m->name); lower_case(stack); stack=end_string(stack); sp=find_saved_player(oldstack); if (!sp) { temp=stack; sprintf(stack,"(2) mail: %s - current: %s",m->name, current_player->name); stack=end_string(stack); log("error",temp); stack=temp; recursive=m->next_sent; } else { change=&(sp->mail_sent); scan=find_note(sp->mail_sent); while(scan && scan!=m) { change=&(scan->next_sent); scan=find_note(scan->next_sent); } tmp=find_note(m->next_sent); if (tmp) *change=tmp->id; else *change=0; } remove_note(m); if (recursive) unlink_mail(find_note(recursive)); stack=oldstack; }
static int append_edit(int argc, const char **argv, const char *prefix) { const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; const unsigned char *note; char logmsg[100]; const char * const *usage; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, "MSG", "note contents as a string", PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, "FILE", "note contents in a file", PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, "OBJECT", "reuse and edit specified note object", PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, "OBJECT", "reuse specified note object", PARSE_OPT_NONEG, parse_reuse_arg}, OPT_END() }; int edit = !strcmp(argv[0], "edit"); usage = edit ? git_notes_edit_usage : git_notes_append_usage; argc = parse_options(argc, argv, prefix, options, usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error("too many parameters"); usage_with_options(usage, options); } if (msg.given && edit) fprintf(stderr, "The -m/-F/-c/-C options have been deprecated " "for the 'edit' subcommand.\n" "Please use 'git notes add -f -m/-F/-c/-C' instead.\n"); object_ref = 1 < argc ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die("Failed to resolve '%s' as a valid ref.", object_ref); t = init_notes_check(argv[0]); note = get_note(t, object); create_note(object, &msg, !edit, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else add_note(t, object, new_note, combine_notes_overwrite); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", argv[0]); commit_notes(t, logmsg); free_notes(t); strbuf_release(&(msg.buf)); return 0; }
static void state_update(){ old_audio_time = audio_time; audio_time = audio_progress; audio_dt += audio_time - old_audio_time; while(audio_dt >= 441*2){ audio_dt -= 441*2; ms_since_last_beat += 5; for(int i=0;i<n_notes;i++){ notes[i].y--; if(notes[i].done || notes[i].y < -30){ score_greatest_combo = MAX(score_greatest_combo, score_combo); score_combo = 0; remove_note(i); i--; } } } redraw_required = 1; if(key[KEY_ESC]){ State_change(MainMenuState); } if(key[KEY_A]){ hit_notes(0); } if(key[KEY_S]){ hit_notes(1); } if(key[KEY_D]){ hit_notes(2); } if(key[KEY_F]){ hit_notes(3); } if(feedback_counter > 0){ feedback_counter--; } int ms_per_beat = ms_per_measure / beats_per_measure; while(ms_since_last_beat > ms_per_beat){ ms_since_last_beat -= ms_per_beat; beat++; if(beat > beats_per_measure){ beat -= beats_per_measure; measure++; if(song->measures[measure] == NULL){ State_change(ScoreScreenState); return; } beats_per_measure = song->measures[measure]->n_rows; if(measure == song->BPMs[current_bpm_index + 1]){ current_bpm_index += 2; current_bpm = song->BPMs[current_bpm_index]; ms_per_measure = 4*60000000 / current_bpm; } } for(int i=0;i<4;i++){ if(song->measures[measure]->rows[beat][i] == '1'){ add_note(i, 244); total_notes++; } } } }
static int add(int argc, const char **argv, const char *prefix) { int retval = 0, force = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; char logmsg[100]; const unsigned char *note; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, N_("message"), N_("note contents as a string"), PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, N_("file"), N_("note contents in a file"), PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, N_("object"), N_("reuse and edit specified note object"), PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, N_("object"), N_("reuse specified note object"), PARSE_OPT_NONEG, parse_reuse_arg}, OPT__FORCE(&force, N_("replace existing notes")), OPT_END() }; argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error(_("too many parameters")); usage_with_options(git_notes_add_usage, options); } object_ref = argc > 1 ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("add"); note = get_note(t, object); if (note) { if (!force) { if (!msg.given) { /* * Redirect to "edit" subcommand. * * We only end up here if none of -m/-F/-c/-C * or -f are given. The original args are * therefore still in argv[0-1]. */ argv[0] = "edit"; free_notes(t); return append_edit(argc, argv, prefix); } retval = error(_("Cannot add notes. Found existing notes " "for object %s. Use '-f' to overwrite " "existing notes"), sha1_to_hex(object)); goto out; } fprintf(stderr, _("Overwriting existing notes for object %s\n"), sha1_to_hex(object)); } create_note(object, &msg, 0, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else if (add_note(t, object, new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", "add"); commit_notes(t, logmsg); out: free_notes(t); strbuf_release(&(msg.buf)); return retval; }
void quit_post(player *p) { tell_player(p,"Article NOT posted.\n"); remove_note((note *)p->edit_info->misc); }
void end_mail(player *p,char *str) { note *mail; char *oldstack,*name_list,*body,*tcpy,*comp,*text; saved_player **player_list,**pscan,**pfill; player *on; int receipt_count,n,m,*received_lists,*r; oldstack=stack; mail=(note *)p->edit_info->misc; align(stack); player_list=(saved_player **)stack; receipt_count=saved_tag(p,mail->text.where); if (mail->text.where) FREE(mail->text.where); mail->text.where=0; if (!receipt_count) { tell_player(p,"No one to send the letter to !\n"); remove_note(mail); stack=oldstack; if (p->edit_info->input_copy==mail_command) do_prompt(p,"Mail Mode >"); return; } if (!p->saved) { tell_player(p,"Eeek, no save file !\n"); remove_note(mail); stack=oldstack; if (p->edit_info->input_copy==mail_command) do_prompt(p,"Mail Mode >"); return; } pscan=player_list; pfill=player_list; m=receipt_count; for(n=0;n<m;n++) if (((*pscan)->residency==STANDARD_ROOMS) || ((*pscan)->residency==BANISHED)) { tell_player(p,"You can't send mail to a room, or someone who is banished.\n"); receipt_count--; pscan++; } else { if ((mail->flags&ANONYMOUS) && ((*pscan)->saved_flags&NO_ANONYMOUS)) { text=stack; sprintf(stack,"%s is not receiving anonymous mail.\n",(*pscan)->lower_name); stack=end_string(stack); tell_player(p,text); stack=text; receipt_count--; pscan++; } else *pfill++=*pscan++; } if (receipt_count>0) { pscan=player_list; name_list=stack; if (mail->flags&SUPRESS_NAME) { strcpy(stack,"Anonymous"); stack=end_string(stack); } else { strcpy(stack,(*pscan)->lower_name); stack=strchr(stack,0); if (receipt_count>1) { pscan++; for(n=2;n<receipt_count;n++,pscan++) { sprintf(stack,", %s",(*pscan)->lower_name); stack=strchr(stack,0); } sprintf(stack," and %s",(*pscan)->lower_name); stack=strchr(stack,0); } *stack++=0; } body=stack; sprintf(stack,"Sending mail to %s.\n",name_list); stack=end_string(stack); tell_player(p,body); stack=body; if (mail->flags&ANONYMOUS) sprintf(stack,"Anonymous mail dated %s.\nSubject: %s\nTo: %s\n\n", convert_time(mail->date),mail->header,name_list); else sprintf(stack,"Mail dated %s.\nSubject: %s\nTo: %s\nFrom: %s\n\n", convert_time(mail->date),mail->header,name_list,mail->name); stack=strchr(stack,0); tcpy=p->edit_info->buffer; for(n=0;n<p->edit_info->size;n++) *stack++=*tcpy++; comp=stack; stack=store_string(stack,body); mail->text.length=(int)stack-(int)comp; mail->text.where=(char *)MALLOC(mail->text.length); memcpy(mail->text.where,comp,mail->text.length); mail->next_sent=p->saved->mail_sent; p->saved->mail_sent=mail->id; text=stack; command_type |= HIGHLIGHT; if (mail->flags&ANONYMOUS) sprintf(stack," -=> New mail, '%s' sent anonymously\n\n", mail->header); else sprintf(stack," -=> New mail, '%s' from %s.\n\n", mail->header,mail->name); stack=end_string(stack); align(stack); received_lists=(int *)stack; pscan=player_list; for(n=0;n<receipt_count;n++,pscan++) { stack=(char *)received_lists; r=(*pscan)->mail_received; if (!r) m=2*sizeof(int); else { for(m=2*sizeof(int);*r;r++,m+=sizeof(int)) { *(int *)stack=*r; stack+=sizeof(int); } } *(int *)stack=mail->id; stack+=sizeof(int); *(int *)stack=0; if ((*pscan)->mail_received) FREE((*pscan)->mail_received); r=(int *)MALLOC(m); memcpy(r,received_lists,m); (*pscan)->mail_received=r; on=find_player_absolute_quiet((*pscan)->lower_name); if (on && on->saved_flags&MAIL_INFORM) { tell_player(on,"\007\n"); tell_player(on,text); } else (*pscan)->saved_flags |= NEW_MAIL; } command_type &= ~HIGHLIGHT; mail->read_count=receipt_count; mail->flags &= ~NOT_READY; tell_player(p,"Mail posted....\n"); } else tell_player(p,"No mail posted.\n"); if (p->edit_info->input_copy==mail_command) do_prompt(p,"Mail Mode >"); stack=oldstack; }
void quit_mail(player *p) { tell_player(p,"Letter NOT posted.\n"); remove_note((note *)p->edit_info->misc); }
static int add(int argc, const char **argv, const char *prefix) { int force = 0, allow_empty = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; const unsigned char *note; struct note_data d = { 0, 0, NULL, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &d, N_("message"), N_("note contents as a string"), PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &d, N_("file"), N_("note contents in a file"), PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"), N_("reuse and edit specified note object"), PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"), N_("reuse specified note object"), PARSE_OPT_NONEG, parse_reuse_arg}, OPT_BOOL(0, "allow-empty", &allow_empty, N_("allow storing empty note")), OPT__FORCE(&force, N_("replace existing notes")), OPT_END() }; argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error(_("too many parameters")); usage_with_options(git_notes_add_usage, options); } object_ref = argc > 1 ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("add"); note = get_note(t, object); if (note) { if (!force) { free_notes(t); if (d.given) { free_note_data(&d); return error(_("Cannot add notes. " "Found existing notes for object %s. " "Use '-f' to overwrite existing notes"), sha1_to_hex(object)); } /* * Redirect to "edit" subcommand. * * We only end up here if none of -m/-F/-c/-C or -f are * given. The original args are therefore still in * argv[0-1]. */ argv[0] = "edit"; return append_edit(argc, argv, prefix); } fprintf(stderr, _("Overwriting existing notes for object %s\n"), sha1_to_hex(object)); } prepare_note_data(object, &d, note); if (d.buf.len || allow_empty) { write_note_data(&d, new_note); if (add_note(t, object, new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); commit_notes(t, "Notes added by 'git notes add'"); } else { fprintf(stderr, _("Removing note for object %s\n"), sha1_to_hex(object)); remove_note(t, object); commit_notes(t, "Notes removed by 'git notes add'"); } free_note_data(&d); free_notes(t); return 0; }
static int append_edit(int argc, const char **argv, const char *prefix) { int allow_empty = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; const unsigned char *note; char logmsg[100]; const char * const *usage; struct note_data d = { 0, 0, NULL, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &d, N_("message"), N_("note contents as a string"), PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &d, N_("file"), N_("note contents in a file"), PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"), N_("reuse and edit specified note object"), PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"), N_("reuse specified note object"), PARSE_OPT_NONEG, parse_reuse_arg}, OPT_BOOL(0, "allow-empty", &allow_empty, N_("allow storing empty note")), OPT_END() }; int edit = !strcmp(argv[0], "edit"); usage = edit ? git_notes_edit_usage : git_notes_append_usage; argc = parse_options(argc, argv, prefix, options, usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error(_("too many parameters")); usage_with_options(usage, options); } if (d.given && edit) fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated " "for the 'edit' subcommand.\n" "Please use 'git notes add -f -m/-F/-c/-C' instead.\n")); object_ref = 1 < argc ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check(argv[0]); note = get_note(t, object); prepare_note_data(object, &d, edit ? note : NULL); if (note && !edit) { /* Append buf to previous note contents */ unsigned long size; enum object_type type; char *prev_buf = read_sha1_file(note, &type, &size); strbuf_grow(&d.buf, size + 1); if (d.buf.len && prev_buf && size) strbuf_insert(&d.buf, 0, "\n", 1); if (prev_buf && size) strbuf_insert(&d.buf, 0, prev_buf, size); free(prev_buf); } if (d.buf.len || allow_empty) { write_note_data(&d, new_note); if (add_note(t, object, new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); snprintf(logmsg, sizeof(logmsg), "Notes added by 'git notes %s'", argv[0]); } else { fprintf(stderr, _("Removing note for object %s\n"), sha1_to_hex(object)); remove_note(t, object); snprintf(logmsg, sizeof(logmsg), "Notes removed by 'git notes %s'", argv[0]); } commit_notes(t, logmsg); free_note_data(&d); free_notes(t); return 0; }
static int add(int argc, const char **argv, const char *prefix) { int retval = 0, force = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; char logmsg[100]; const unsigned char *note; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, "MSG", "note contents as a string", PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, "FILE", "note contents in a file", PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, "OBJECT", "reuse and edit specified note object", PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, "OBJECT", "reuse specified note object", PARSE_OPT_NONEG, parse_reuse_arg}, OPT_BOOLEAN('f', "force", &force, "replace existing notes"), OPT_END() }; argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, 0); if (1 < argc) { error("too many parameters"); usage_with_options(git_notes_add_usage, options); } object_ref = argc ? argv[0] : "HEAD"; if (get_sha1(object_ref, object)) die("Failed to resolve '%s' as a valid ref.", object_ref); t = init_notes_check("add"); note = get_note(t, object); if (note) { if (!force) { retval = error("Cannot add notes. Found existing notes " "for object %s. Use '-f' to overwrite " "existing notes", sha1_to_hex(object)); goto out; } fprintf(stderr, "Overwriting existing notes for object %s\n", sha1_to_hex(object)); } create_note(object, &msg, 0, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else add_note(t, object, new_note, combine_notes_overwrite); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", "add"); commit_notes(t, logmsg); out: free_notes(t); strbuf_release(&(msg.buf)); return retval; }