@@ -29,7 +29,7 @@ static const char * const git_notes_usage[] = {
2929 "git notes [--ref <notes_ref>] merge [-v | -q] [-s <strategy> ] <notes_ref>" ,
3030 "git notes merge --commit [-v | -q]" ,
3131 "git notes merge --abort [-v | -q]" ,
32- "git notes [--ref <notes_ref>] remove [<object>]" ,
32+ "git notes [--ref <notes_ref>] remove [<object>... ]" ,
3333 "git notes [--ref <notes_ref>] prune [-n | -v]" ,
3434 "git notes [--ref <notes_ref>] get-ref" ,
3535 NULL
@@ -953,40 +953,60 @@ static int merge(int argc, const char **argv, const char *prefix)
953953 return result < 0 ; /* return non-zero on conflicts */
954954}
955955
956+ #define IGNORE_MISSING 1
957+
958+ static int remove_one_note (struct notes_tree * t , const char * name , unsigned flag )
959+ {
960+ int status ;
961+ unsigned char sha1 [20 ];
962+ if (get_sha1 (name , sha1 ))
963+ return error (_ ("Failed to resolve '%s' as a valid ref." ), name );
964+ status = remove_note (t , sha1 );
965+ if (status )
966+ fprintf (stderr , _ ("Object %s has no note\n" ), name );
967+ else
968+ fprintf (stderr , _ ("Removing note for object %s\n" ), name );
969+ return (flag & IGNORE_MISSING ) ? 0 : status ;
970+ }
971+
956972static int remove_cmd (int argc , const char * * argv , const char * prefix )
957973{
974+ unsigned flag = 0 ;
975+ int from_stdin = 0 ;
958976 struct option options [] = {
977+ OPT_BIT (0 , "ignore-missing" , & flag ,
978+ "attempt to remove non-existent note is not an error" ,
979+ IGNORE_MISSING ),
980+ OPT_BOOLEAN (0 , "stdin" , & from_stdin ,
981+ "read object names from the standard input" ),
959982 OPT_END ()
960983 };
961- const char * object_ref ;
962984 struct notes_tree * t ;
963- unsigned char object [20 ];
964- int retval ;
985+ int retval = 0 ;
965986
966987 argc = parse_options (argc , argv , prefix , options ,
967988 git_notes_remove_usage , 0 );
968989
969- if (1 < argc ) {
970- error (_ ("too many parameters" ));
971- usage_with_options (git_notes_remove_usage , options );
972- }
973-
974- object_ref = argc ? argv [0 ] : "HEAD" ;
975-
976- if (get_sha1 (object_ref , object ))
977- die (_ ("Failed to resolve '%s' as a valid ref." ), object_ref );
978-
979990 t = init_notes_check ("remove" );
980991
981- retval = remove_note (t , object );
982- if (retval )
983- fprintf (stderr , _ ("Object %s has no note\n" ), sha1_to_hex (object ));
984- else {
985- fprintf (stderr , _ ("Removing note for object %s\n" ),
986- sha1_to_hex (object ));
987-
988- commit_notes (t , "Notes removed by 'git notes remove'" );
992+ if (!argc && !from_stdin ) {
993+ retval = remove_one_note (t , "HEAD" , flag );
994+ } else {
995+ while (* argv ) {
996+ retval |= remove_one_note (t , * argv , flag );
997+ argv ++ ;
998+ }
989999 }
1000+ if (from_stdin ) {
1001+ struct strbuf sb = STRBUF_INIT ;
1002+ while (strbuf_getwholeline (& sb , stdin , '\n' ) != EOF ) {
1003+ strbuf_rtrim (& sb );
1004+ retval |= remove_one_note (t , sb .buf , flag );
1005+ }
1006+ strbuf_release (& sb );
1007+ }
1008+ if (!retval )
1009+ commit_notes (t , "Notes removed by 'git notes remove'" );
9901010 free_notes (t );
9911011 return retval ;
9921012}
0 commit comments