@@ -108,7 +108,7 @@ struct am_state {
108108 size_t msg_len ;
109109
110110 /* when --rebasing, records the original commit the patch came from */
111- unsigned char orig_commit [ GIT_SHA1_RAWSZ ] ;
111+ struct object_id orig_commit ;
112112
113113 /* number of digits in patch filename */
114114 int prec ;
@@ -428,8 +428,8 @@ static void am_load(struct am_state *state)
428428 read_commit_msg (state );
429429
430430 if (read_state_file (& sb , state , "original-commit" , 1 ) < 0 )
431- hashclr ( state -> orig_commit );
432- else if (get_sha1_hex (sb .buf , state -> orig_commit ) < 0 )
431+ oidclr ( & state -> orig_commit );
432+ else if (get_oid_hex (sb .buf , & state -> orig_commit ) < 0 )
433433 die (_ ("could not parse %s" ), am_path (state , "original-commit" ));
434434
435435 read_state_file (& sb , state , "threeway" , 1 );
@@ -555,14 +555,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
555555 fp = xfopen (am_path (state , "rewritten" ), "r" );
556556
557557 while (!strbuf_getline_lf (& sb , fp )) {
558- unsigned char from_obj [ GIT_SHA1_RAWSZ ] , to_obj [ GIT_SHA1_RAWSZ ] ;
558+ struct object_id from_obj , to_obj ;
559559
560560 if (sb .len != GIT_SHA1_HEXSZ * 2 + 1 ) {
561561 ret = error (invalid_line , sb .buf );
562562 goto finish ;
563563 }
564564
565- if (get_sha1_hex (sb .buf , from_obj )) {
565+ if (get_oid_hex (sb .buf , & from_obj )) {
566566 ret = error (invalid_line , sb .buf );
567567 goto finish ;
568568 }
@@ -572,14 +572,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
572572 goto finish ;
573573 }
574574
575- if (get_sha1_hex (sb .buf + GIT_SHA1_HEXSZ + 1 , to_obj )) {
575+ if (get_oid_hex (sb .buf + GIT_SHA1_HEXSZ + 1 , & to_obj )) {
576576 ret = error (invalid_line , sb .buf );
577577 goto finish ;
578578 }
579579
580- if (copy_note_for_rewrite (c , from_obj , to_obj ))
580+ if (copy_note_for_rewrite (c , from_obj . hash , to_obj . hash ))
581581 ret = error (_ ("Failed to copy notes from '%s' to '%s'" ),
582- sha1_to_hex ( from_obj ), sha1_to_hex ( to_obj ));
582+ oid_to_hex ( & from_obj ), oid_to_hex ( & to_obj ));
583583 }
584584
585585finish :
@@ -985,7 +985,7 @@ static int split_mail(struct am_state *state, enum patch_format patch_format,
985985static void am_setup (struct am_state * state , enum patch_format patch_format ,
986986 const char * * paths , int keep_cr )
987987{
988- unsigned char curr_head [ GIT_SHA1_RAWSZ ] ;
988+ struct object_id curr_head ;
989989 const char * str ;
990990 struct strbuf sb = STRBUF_INIT ;
991991
@@ -1053,10 +1053,10 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10531053 else
10541054 write_state_text (state , "applying" , "" );
10551055
1056- if (!get_sha1 ("HEAD" , curr_head )) {
1057- write_state_text (state , "abort-safety" , sha1_to_hex ( curr_head ));
1056+ if (!get_oid ("HEAD" , & curr_head )) {
1057+ write_state_text (state , "abort-safety" , oid_to_hex ( & curr_head ));
10581058 if (!state -> rebasing )
1059- update_ref ("am" , "ORIG_HEAD" , curr_head , NULL , 0 ,
1059+ update_ref_oid ("am" , "ORIG_HEAD" , & curr_head , NULL , 0 ,
10601060 UPDATE_REFS_DIE_ON_ERR );
10611061 } else {
10621062 write_state_text (state , "abort-safety" , "" );
@@ -1081,7 +1081,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10811081 */
10821082static void am_next (struct am_state * state )
10831083{
1084- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1084+ struct object_id head ;
10851085
10861086 free (state -> author_name );
10871087 state -> author_name = NULL ;
@@ -1099,11 +1099,11 @@ static void am_next(struct am_state *state)
10991099 unlink (am_path (state , "author-script" ));
11001100 unlink (am_path (state , "final-commit" ));
11011101
1102- hashclr ( state -> orig_commit );
1102+ oidclr ( & state -> orig_commit );
11031103 unlink (am_path (state , "original-commit" ));
11041104
1105- if (!get_sha1 ("HEAD" , head ))
1106- write_state_text (state , "abort-safety" , sha1_to_hex ( head ));
1105+ if (!get_oid ("HEAD" , & head ))
1106+ write_state_text (state , "abort-safety" , oid_to_hex ( & head ));
11071107 else
11081108 write_state_text (state , "abort-safety" , "" );
11091109
@@ -1145,17 +1145,17 @@ static void refresh_and_write_cache(void)
11451145 */
11461146static int index_has_changes (struct strbuf * sb )
11471147{
1148- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1148+ struct object_id head ;
11491149 int i ;
11501150
1151- if (!get_sha1_tree ("HEAD" , head )) {
1151+ if (!get_sha1_tree ("HEAD" , head . hash )) {
11521152 struct diff_options opt ;
11531153
11541154 diff_setup (& opt );
11551155 DIFF_OPT_SET (& opt , EXIT_WITH_STATUS );
11561156 if (!sb )
11571157 DIFF_OPT_SET (& opt , QUICK );
1158- do_diff_cache (head , & opt );
1158+ do_diff_cache (head . hash , & opt );
11591159 diffcore_std (& opt );
11601160 for (i = 0 ; sb && i < diff_queued_diff .nr ; i ++ ) {
11611161 if (i )
@@ -1362,7 +1362,7 @@ static int parse_mail(struct am_state *state, const char *mail)
13621362 * Sets commit_id to the commit hash where the mail was generated from.
13631363 * Returns 0 on success, -1 on failure.
13641364 */
1365- static int get_mail_commit_sha1 ( unsigned char * commit_id , const char * mail )
1365+ static int get_mail_commit_oid ( struct object_id * commit_id , const char * mail )
13661366{
13671367 struct strbuf sb = STRBUF_INIT ;
13681368 FILE * fp = xfopen (mail , "r" );
@@ -1374,7 +1374,7 @@ static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)
13741374 if (!skip_prefix (sb .buf , "From " , & x ))
13751375 return -1 ;
13761376
1377- if (get_sha1_hex (x , commit_id ) < 0 )
1377+ if (get_oid_hex (x , commit_id ) < 0 )
13781378 return -1 ;
13791379
13801380 strbuf_release (& sb );
@@ -1464,12 +1464,12 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
14641464static void write_index_patch (const struct am_state * state )
14651465{
14661466 struct tree * tree ;
1467- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1467+ struct object_id head ;
14681468 struct rev_info rev_info ;
14691469 FILE * fp ;
14701470
1471- if (!get_sha1_tree ("HEAD" , head ))
1472- tree = lookup_tree (head );
1471+ if (!get_sha1_tree ("HEAD" , head . hash ))
1472+ tree = lookup_tree (head . hash );
14731473 else
14741474 tree = lookup_tree (EMPTY_TREE_SHA1_BIN );
14751475
@@ -1499,19 +1499,19 @@ static void write_index_patch(const struct am_state *state)
14991499static int parse_mail_rebase (struct am_state * state , const char * mail )
15001500{
15011501 struct commit * commit ;
1502- unsigned char commit_sha1 [ GIT_SHA1_RAWSZ ] ;
1502+ struct object_id commit_oid ;
15031503
1504- if (get_mail_commit_sha1 ( commit_sha1 , mail ) < 0 )
1504+ if (get_mail_commit_oid ( & commit_oid , mail ) < 0 )
15051505 die (_ ("could not parse %s" ), mail );
15061506
1507- commit = lookup_commit_or_die (commit_sha1 , mail );
1507+ commit = lookup_commit_or_die (commit_oid . hash , mail );
15081508
15091509 get_commit_info (state , commit );
15101510
15111511 write_commit_patch (state , commit );
15121512
1513- hashcpy ( state -> orig_commit , commit_sha1 );
1514- write_state_text (state , "original-commit" , sha1_to_hex ( commit_sha1 ));
1513+ oidcpy ( & state -> orig_commit , & commit_oid );
1514+ write_state_text (state , "original-commit" , oid_to_hex ( & commit_oid ));
15151515
15161516 return 0 ;
15171517}
@@ -1665,24 +1665,23 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16651665 */
16661666static void do_commit (const struct am_state * state )
16671667{
1668- unsigned char tree [GIT_SHA1_RAWSZ ], parent [GIT_SHA1_RAWSZ ],
1669- commit [GIT_SHA1_RAWSZ ];
1670- unsigned char * ptr ;
1668+ struct object_id tree , parent , commit ;
1669+ const struct object_id * old_oid ;
16711670 struct commit_list * parents = NULL ;
16721671 const char * reflog_msg , * author ;
16731672 struct strbuf sb = STRBUF_INIT ;
16741673
16751674 if (run_hook_le (NULL , "pre-applypatch" , NULL ))
16761675 exit (1 );
16771676
1678- if (write_cache_as_tree (tree , 0 , NULL ))
1677+ if (write_cache_as_tree (tree . hash , 0 , NULL ))
16791678 die (_ ("git write-tree failed to write a tree" ));
16801679
1681- if (!get_sha1_commit ("HEAD" , parent )) {
1682- ptr = parent ;
1683- commit_list_insert (lookup_commit (parent ), & parents );
1680+ if (!get_sha1_commit ("HEAD" , parent . hash )) {
1681+ old_oid = & parent ;
1682+ commit_list_insert (lookup_commit (parent . hash ), & parents );
16841683 } else {
1685- ptr = NULL ;
1684+ old_oid = NULL ;
16861685 say (state , stderr , _ ("applying to an empty history" ));
16871686 }
16881687
@@ -1694,7 +1693,7 @@ static void do_commit(const struct am_state *state)
16941693 setenv ("GIT_COMMITTER_DATE" ,
16951694 state -> ignore_date ? "" : state -> author_date , 1 );
16961695
1697- if (commit_tree (state -> msg , state -> msg_len , tree , parents , commit ,
1696+ if (commit_tree (state -> msg , state -> msg_len , tree . hash , parents , commit . hash ,
16981697 author , state -> sign_commit ))
16991698 die (_ ("failed to write commit object" ));
17001699
@@ -1705,14 +1704,15 @@ static void do_commit(const struct am_state *state)
17051704 strbuf_addf (& sb , "%s: %.*s" , reflog_msg , linelen (state -> msg ),
17061705 state -> msg );
17071706
1708- update_ref (sb .buf , "HEAD" , commit , ptr , 0 , UPDATE_REFS_DIE_ON_ERR );
1707+ update_ref_oid (sb .buf , "HEAD" , & commit , old_oid , 0 ,
1708+ UPDATE_REFS_DIE_ON_ERR );
17091709
17101710 if (state -> rebasing ) {
17111711 FILE * fp = xfopen (am_path (state , "rewritten" ), "a" );
17121712
1713- assert (!is_null_sha1 ( state -> orig_commit ));
1714- fprintf (fp , "%s " , sha1_to_hex ( state -> orig_commit ));
1715- fprintf (fp , "%s\n" , sha1_to_hex ( commit ));
1713+ assert (!is_null_oid ( & state -> orig_commit ));
1714+ fprintf (fp , "%s " , oid_to_hex ( & state -> orig_commit ));
1715+ fprintf (fp , "%s\n" , oid_to_hex ( & commit ));
17161716 fclose (fp );
17171717 }
17181718
@@ -2033,30 +2033,30 @@ static int merge_tree(struct tree *tree)
20332033 * Clean the index without touching entries that are not modified between
20342034 * `head` and `remote`.
20352035 */
2036- static int clean_index (const unsigned char * head , const unsigned char * remote )
2036+ static int clean_index (const struct object_id * head , const struct object_id * remote )
20372037{
20382038 struct tree * head_tree , * remote_tree , * index_tree ;
2039- unsigned char index [ GIT_SHA1_RAWSZ ] ;
2039+ struct object_id index ;
20402040
2041- head_tree = parse_tree_indirect (head );
2041+ head_tree = parse_tree_indirect (head -> hash );
20422042 if (!head_tree )
2043- return error (_ ("Could not parse object '%s'." ), sha1_to_hex (head ));
2043+ return error (_ ("Could not parse object '%s'." ), oid_to_hex (head ));
20442044
2045- remote_tree = parse_tree_indirect (remote );
2045+ remote_tree = parse_tree_indirect (remote -> hash );
20462046 if (!remote_tree )
2047- return error (_ ("Could not parse object '%s'." ), sha1_to_hex (remote ));
2047+ return error (_ ("Could not parse object '%s'." ), oid_to_hex (remote ));
20482048
20492049 read_cache_unmerged ();
20502050
20512051 if (fast_forward_to (head_tree , head_tree , 1 ))
20522052 return -1 ;
20532053
2054- if (write_cache_as_tree (index , 0 , NULL ))
2054+ if (write_cache_as_tree (index . hash , 0 , NULL ))
20552055 return -1 ;
20562056
2057- index_tree = parse_tree_indirect (index );
2057+ index_tree = parse_tree_indirect (index . hash );
20582058 if (!index_tree )
2059- return error (_ ("Could not parse object '%s'." ), sha1_to_hex ( index ));
2059+ return error (_ ("Could not parse object '%s'." ), oid_to_hex ( & index ));
20602060
20612061 if (fast_forward_to (index_tree , remote_tree , 0 ))
20622062 return -1 ;
@@ -2084,14 +2084,14 @@ static void am_rerere_clear(void)
20842084 */
20852085static void am_skip (struct am_state * state )
20862086{
2087- unsigned char head [ GIT_SHA1_RAWSZ ] ;
2087+ struct object_id head ;
20882088
20892089 am_rerere_clear ();
20902090
2091- if (get_sha1 ("HEAD" , head ))
2092- hashcpy (head , EMPTY_TREE_SHA1_BIN );
2091+ if (get_oid ("HEAD" , & head ))
2092+ hashcpy (head . hash , EMPTY_TREE_SHA1_BIN );
20932093
2094- if (clean_index (head , head ))
2094+ if (clean_index (& head , & head ))
20952095 die (_ ("failed to clean index" ));
20962096
20972097 am_next (state );
@@ -2109,21 +2109,21 @@ static void am_skip(struct am_state *state)
21092109static int safe_to_abort (const struct am_state * state )
21102110{
21112111 struct strbuf sb = STRBUF_INIT ;
2112- unsigned char abort_safety [ GIT_SHA1_RAWSZ ] , head [ GIT_SHA1_RAWSZ ] ;
2112+ struct object_id abort_safety , head ;
21132113
21142114 if (file_exists (am_path (state , "dirtyindex" )))
21152115 return 0 ;
21162116
21172117 if (read_state_file (& sb , state , "abort-safety" , 1 ) > 0 ) {
2118- if (get_sha1_hex (sb .buf , abort_safety ))
2118+ if (get_oid_hex (sb .buf , & abort_safety ))
21192119 die (_ ("could not parse %s" ), am_path (state , "abort_safety" ));
21202120 } else
2121- hashclr ( abort_safety );
2121+ oidclr ( & abort_safety );
21222122
2123- if (get_sha1 ("HEAD" , head ))
2124- hashclr ( head );
2123+ if (get_oid ("HEAD" , & head ))
2124+ oidclr ( & head );
21252125
2126- if (!hashcmp ( head , abort_safety ))
2126+ if (!oidcmp ( & head , & abort_safety ))
21272127 return 1 ;
21282128
21292129 error (_ ("You seem to have moved HEAD since the last 'am' failure.\n"
@@ -2137,7 +2137,7 @@ static int safe_to_abort(const struct am_state *state)
21372137 */
21382138static void am_abort (struct am_state * state )
21392139{
2140- unsigned char curr_head [ GIT_SHA1_RAWSZ ] , orig_head [ GIT_SHA1_RAWSZ ] ;
2140+ struct object_id curr_head , orig_head ;
21412141 int has_curr_head , has_orig_head ;
21422142 char * curr_branch ;
21432143
@@ -2148,20 +2148,20 @@ static void am_abort(struct am_state *state)
21482148
21492149 am_rerere_clear ();
21502150
2151- curr_branch = resolve_refdup ("HEAD" , 0 , curr_head , NULL );
2152- has_curr_head = !is_null_sha1 ( curr_head );
2151+ curr_branch = resolve_refdup ("HEAD" , 0 , curr_head . hash , NULL );
2152+ has_curr_head = !is_null_oid ( & curr_head );
21532153 if (!has_curr_head )
2154- hashcpy (curr_head , EMPTY_TREE_SHA1_BIN );
2154+ hashcpy (curr_head . hash , EMPTY_TREE_SHA1_BIN );
21552155
2156- has_orig_head = !get_sha1 ("ORIG_HEAD" , orig_head );
2156+ has_orig_head = !get_oid ("ORIG_HEAD" , & orig_head );
21572157 if (!has_orig_head )
2158- hashcpy (orig_head , EMPTY_TREE_SHA1_BIN );
2158+ hashcpy (orig_head . hash , EMPTY_TREE_SHA1_BIN );
21592159
2160- clean_index (curr_head , orig_head );
2160+ clean_index (& curr_head , & orig_head );
21612161
21622162 if (has_orig_head )
2163- update_ref ("am --abort" , "HEAD" , orig_head ,
2164- has_curr_head ? curr_head : NULL , 0 ,
2163+ update_ref_oid ("am --abort" , "HEAD" , & orig_head ,
2164+ has_curr_head ? & curr_head : NULL , 0 ,
21652165 UPDATE_REFS_DIE_ON_ERR );
21662166 else if (curr_branch )
21672167 delete_ref (curr_branch , NULL , REF_NODEREF );
0 commit comments