@@ -110,7 +110,7 @@ struct am_state {
110110 size_t msg_len ;
111111
112112 /* when --rebasing, records the original commit the patch came from */
113- unsigned char orig_commit [ GIT_SHA1_RAWSZ ] ;
113+ struct object_id orig_commit ;
114114
115115 /* number of digits in patch filename */
116116 int prec ;
@@ -416,8 +416,8 @@ static void am_load(struct am_state *state)
416416 read_commit_msg (state );
417417
418418 if (read_state_file (& sb , state , "original-commit" , 1 ) < 0 )
419- hashclr ( state -> orig_commit );
420- else if (get_sha1_hex (sb .buf , state -> orig_commit ) < 0 )
419+ oidclr ( & state -> orig_commit );
420+ else if (get_oid_hex (sb .buf , & state -> orig_commit ) < 0 )
421421 die (_ ("could not parse %s" ), am_path (state , "original-commit" ));
422422
423423 read_state_file (& sb , state , "threeway" , 1 );
@@ -543,14 +543,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
543543 fp = xfopen (am_path (state , "rewritten" ), "r" );
544544
545545 while (!strbuf_getline_lf (& sb , fp )) {
546- unsigned char from_obj [ GIT_SHA1_RAWSZ ] , to_obj [ GIT_SHA1_RAWSZ ] ;
546+ struct object_id from_obj , to_obj ;
547547
548548 if (sb .len != GIT_SHA1_HEXSZ * 2 + 1 ) {
549549 ret = error (invalid_line , sb .buf );
550550 goto finish ;
551551 }
552552
553- if (get_sha1_hex (sb .buf , from_obj )) {
553+ if (get_oid_hex (sb .buf , & from_obj )) {
554554 ret = error (invalid_line , sb .buf );
555555 goto finish ;
556556 }
@@ -560,14 +560,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
560560 goto finish ;
561561 }
562562
563- if (get_sha1_hex (sb .buf + GIT_SHA1_HEXSZ + 1 , to_obj )) {
563+ if (get_oid_hex (sb .buf + GIT_SHA1_HEXSZ + 1 , & to_obj )) {
564564 ret = error (invalid_line , sb .buf );
565565 goto finish ;
566566 }
567567
568- if (copy_note_for_rewrite (c , from_obj , to_obj ))
568+ if (copy_note_for_rewrite (c , from_obj . hash , to_obj . hash ))
569569 ret = error (_ ("Failed to copy notes from '%s' to '%s'" ),
570- sha1_to_hex ( from_obj ), sha1_to_hex ( to_obj ));
570+ oid_to_hex ( & from_obj ), oid_to_hex ( & to_obj ));
571571 }
572572
573573finish :
@@ -973,7 +973,7 @@ static int split_mail(struct am_state *state, enum patch_format patch_format,
973973static void am_setup (struct am_state * state , enum patch_format patch_format ,
974974 const char * * paths , int keep_cr )
975975{
976- unsigned char curr_head [ GIT_SHA1_RAWSZ ] ;
976+ struct object_id curr_head ;
977977 const char * str ;
978978 struct strbuf sb = STRBUF_INIT ;
979979
@@ -1041,10 +1041,10 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10411041 else
10421042 write_state_text (state , "applying" , "" );
10431043
1044- if (!get_sha1 ("HEAD" , curr_head )) {
1045- write_state_text (state , "abort-safety" , sha1_to_hex ( curr_head ));
1044+ if (!get_oid ("HEAD" , & curr_head )) {
1045+ write_state_text (state , "abort-safety" , oid_to_hex ( & curr_head ));
10461046 if (!state -> rebasing )
1047- update_ref ("am" , "ORIG_HEAD" , curr_head , NULL , 0 ,
1047+ update_ref_oid ("am" , "ORIG_HEAD" , & curr_head , NULL , 0 ,
10481048 UPDATE_REFS_DIE_ON_ERR );
10491049 } else {
10501050 write_state_text (state , "abort-safety" , "" );
@@ -1069,7 +1069,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10691069 */
10701070static void am_next (struct am_state * state )
10711071{
1072- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1072+ struct object_id head ;
10731073
10741074 free (state -> author_name );
10751075 state -> author_name = NULL ;
@@ -1087,11 +1087,11 @@ static void am_next(struct am_state *state)
10871087 unlink (am_path (state , "author-script" ));
10881088 unlink (am_path (state , "final-commit" ));
10891089
1090- hashclr ( state -> orig_commit );
1090+ oidclr ( & state -> orig_commit );
10911091 unlink (am_path (state , "original-commit" ));
10921092
1093- if (!get_sha1 ("HEAD" , head ))
1094- write_state_text (state , "abort-safety" , sha1_to_hex ( head ));
1093+ if (!get_oid ("HEAD" , & head ))
1094+ write_state_text (state , "abort-safety" , oid_to_hex ( & head ));
10951095 else
10961096 write_state_text (state , "abort-safety" , "" );
10971097
@@ -1133,17 +1133,17 @@ static void refresh_and_write_cache(void)
11331133 */
11341134static int index_has_changes (struct strbuf * sb )
11351135{
1136- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1136+ struct object_id head ;
11371137 int i ;
11381138
1139- if (!get_sha1_tree ("HEAD" , head )) {
1139+ if (!get_sha1_tree ("HEAD" , head . hash )) {
11401140 struct diff_options opt ;
11411141
11421142 diff_setup (& opt );
11431143 DIFF_OPT_SET (& opt , EXIT_WITH_STATUS );
11441144 if (!sb )
11451145 DIFF_OPT_SET (& opt , QUICK );
1146- do_diff_cache (head , & opt );
1146+ do_diff_cache (head . hash , & opt );
11471147 diffcore_std (& opt );
11481148 for (i = 0 ; sb && i < diff_queued_diff .nr ; i ++ ) {
11491149 if (i )
@@ -1350,7 +1350,7 @@ static int parse_mail(struct am_state *state, const char *mail)
13501350 * Sets commit_id to the commit hash where the mail was generated from.
13511351 * Returns 0 on success, -1 on failure.
13521352 */
1353- static int get_mail_commit_sha1 ( unsigned char * commit_id , const char * mail )
1353+ static int get_mail_commit_oid ( struct object_id * commit_id , const char * mail )
13541354{
13551355 struct strbuf sb = STRBUF_INIT ;
13561356 FILE * fp = xfopen (mail , "r" );
@@ -1362,7 +1362,7 @@ static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)
13621362 if (!skip_prefix (sb .buf , "From " , & x ))
13631363 return -1 ;
13641364
1365- if (get_sha1_hex (x , commit_id ) < 0 )
1365+ if (get_oid_hex (x , commit_id ) < 0 )
13661366 return -1 ;
13671367
13681368 strbuf_release (& sb );
@@ -1452,12 +1452,12 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
14521452static void write_index_patch (const struct am_state * state )
14531453{
14541454 struct tree * tree ;
1455- unsigned char head [ GIT_SHA1_RAWSZ ] ;
1455+ struct object_id head ;
14561456 struct rev_info rev_info ;
14571457 FILE * fp ;
14581458
1459- if (!get_sha1_tree ("HEAD" , head ))
1460- tree = lookup_tree (head );
1459+ if (!get_sha1_tree ("HEAD" , head . hash ))
1460+ tree = lookup_tree (head . hash );
14611461 else
14621462 tree = lookup_tree (EMPTY_TREE_SHA1_BIN );
14631463
@@ -1487,19 +1487,19 @@ static void write_index_patch(const struct am_state *state)
14871487static int parse_mail_rebase (struct am_state * state , const char * mail )
14881488{
14891489 struct commit * commit ;
1490- unsigned char commit_sha1 [ GIT_SHA1_RAWSZ ] ;
1490+ struct object_id commit_oid ;
14911491
1492- if (get_mail_commit_sha1 ( commit_sha1 , mail ) < 0 )
1492+ if (get_mail_commit_oid ( & commit_oid , mail ) < 0 )
14931493 die (_ ("could not parse %s" ), mail );
14941494
1495- commit = lookup_commit_or_die (commit_sha1 , mail );
1495+ commit = lookup_commit_or_die (commit_oid . hash , mail );
14961496
14971497 get_commit_info (state , commit );
14981498
14991499 write_commit_patch (state , commit );
15001500
1501- hashcpy ( state -> orig_commit , commit_sha1 );
1502- write_state_text (state , "original-commit" , sha1_to_hex ( commit_sha1 ));
1501+ oidcpy ( & state -> orig_commit , & commit_oid );
1502+ write_state_text (state , "original-commit" , oid_to_hex ( & commit_oid ));
15031503
15041504 return 0 ;
15051505}
@@ -1673,24 +1673,23 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16731673 */
16741674static void do_commit (const struct am_state * state )
16751675{
1676- unsigned char tree [GIT_SHA1_RAWSZ ], parent [GIT_SHA1_RAWSZ ],
1677- commit [GIT_SHA1_RAWSZ ];
1678- unsigned char * ptr ;
1676+ struct object_id tree , parent , commit ;
1677+ const struct object_id * old_oid ;
16791678 struct commit_list * parents = NULL ;
16801679 const char * reflog_msg , * author ;
16811680 struct strbuf sb = STRBUF_INIT ;
16821681
16831682 if (run_hook_le (NULL , "pre-applypatch" , NULL ))
16841683 exit (1 );
16851684
1686- if (write_cache_as_tree (tree , 0 , NULL ))
1685+ if (write_cache_as_tree (tree . hash , 0 , NULL ))
16871686 die (_ ("git write-tree failed to write a tree" ));
16881687
1689- if (!get_sha1_commit ("HEAD" , parent )) {
1690- ptr = parent ;
1691- commit_list_insert (lookup_commit (parent ), & parents );
1688+ if (!get_sha1_commit ("HEAD" , parent . hash )) {
1689+ old_oid = & parent ;
1690+ commit_list_insert (lookup_commit (parent . hash ), & parents );
16921691 } else {
1693- ptr = NULL ;
1692+ old_oid = NULL ;
16941693 say (state , stderr , _ ("applying to an empty history" ));
16951694 }
16961695
@@ -1702,7 +1701,7 @@ static void do_commit(const struct am_state *state)
17021701 setenv ("GIT_COMMITTER_DATE" ,
17031702 state -> ignore_date ? "" : state -> author_date , 1 );
17041703
1705- if (commit_tree (state -> msg , state -> msg_len , tree , parents , commit ,
1704+ if (commit_tree (state -> msg , state -> msg_len , tree . hash , parents , commit . hash ,
17061705 author , state -> sign_commit ))
17071706 die (_ ("failed to write commit object" ));
17081707
@@ -1713,14 +1712,15 @@ static void do_commit(const struct am_state *state)
17131712 strbuf_addf (& sb , "%s: %.*s" , reflog_msg , linelen (state -> msg ),
17141713 state -> msg );
17151714
1716- update_ref (sb .buf , "HEAD" , commit , ptr , 0 , UPDATE_REFS_DIE_ON_ERR );
1715+ update_ref_oid (sb .buf , "HEAD" , & commit , old_oid , 0 ,
1716+ UPDATE_REFS_DIE_ON_ERR );
17171717
17181718 if (state -> rebasing ) {
17191719 FILE * fp = xfopen (am_path (state , "rewritten" ), "a" );
17201720
1721- assert (!is_null_sha1 ( state -> orig_commit ));
1722- fprintf (fp , "%s " , sha1_to_hex ( state -> orig_commit ));
1723- fprintf (fp , "%s\n" , sha1_to_hex ( commit ));
1721+ assert (!is_null_oid ( & state -> orig_commit ));
1722+ fprintf (fp , "%s " , oid_to_hex ( & state -> orig_commit ));
1723+ fprintf (fp , "%s\n" , oid_to_hex ( & commit ));
17241724 fclose (fp );
17251725 }
17261726
@@ -2041,30 +2041,30 @@ static int merge_tree(struct tree *tree)
20412041 * Clean the index without touching entries that are not modified between
20422042 * `head` and `remote`.
20432043 */
2044- static int clean_index (const unsigned char * head , const unsigned char * remote )
2044+ static int clean_index (const struct object_id * head , const struct object_id * remote )
20452045{
20462046 struct tree * head_tree , * remote_tree , * index_tree ;
2047- unsigned char index [ GIT_SHA1_RAWSZ ] ;
2047+ struct object_id index ;
20482048
2049- head_tree = parse_tree_indirect (head );
2049+ head_tree = parse_tree_indirect (head -> hash );
20502050 if (!head_tree )
2051- return error (_ ("Could not parse object '%s'." ), sha1_to_hex (head ));
2051+ return error (_ ("Could not parse object '%s'." ), oid_to_hex (head ));
20522052
2053- remote_tree = parse_tree_indirect (remote );
2053+ remote_tree = parse_tree_indirect (remote -> hash );
20542054 if (!remote_tree )
2055- return error (_ ("Could not parse object '%s'." ), sha1_to_hex (remote ));
2055+ return error (_ ("Could not parse object '%s'." ), oid_to_hex (remote ));
20562056
20572057 read_cache_unmerged ();
20582058
20592059 if (fast_forward_to (head_tree , head_tree , 1 ))
20602060 return -1 ;
20612061
2062- if (write_cache_as_tree (index , 0 , NULL ))
2062+ if (write_cache_as_tree (index . hash , 0 , NULL ))
20632063 return -1 ;
20642064
2065- index_tree = parse_tree_indirect (index );
2065+ index_tree = parse_tree_indirect (index . hash );
20662066 if (!index_tree )
2067- return error (_ ("Could not parse object '%s'." ), sha1_to_hex ( index ));
2067+ return error (_ ("Could not parse object '%s'." ), oid_to_hex ( & index ));
20682068
20692069 if (fast_forward_to (index_tree , remote_tree , 0 ))
20702070 return -1 ;
@@ -2092,14 +2092,14 @@ static void am_rerere_clear(void)
20922092 */
20932093static void am_skip (struct am_state * state )
20942094{
2095- unsigned char head [ GIT_SHA1_RAWSZ ] ;
2095+ struct object_id head ;
20962096
20972097 am_rerere_clear ();
20982098
2099- if (get_sha1 ("HEAD" , head ))
2100- hashcpy (head , EMPTY_TREE_SHA1_BIN );
2099+ if (get_oid ("HEAD" , & head ))
2100+ hashcpy (head . hash , EMPTY_TREE_SHA1_BIN );
21012101
2102- if (clean_index (head , head ))
2102+ if (clean_index (& head , & head ))
21032103 die (_ ("failed to clean index" ));
21042104
21052105 am_next (state );
@@ -2117,21 +2117,21 @@ static void am_skip(struct am_state *state)
21172117static int safe_to_abort (const struct am_state * state )
21182118{
21192119 struct strbuf sb = STRBUF_INIT ;
2120- unsigned char abort_safety [ GIT_SHA1_RAWSZ ] , head [ GIT_SHA1_RAWSZ ] ;
2120+ struct object_id abort_safety , head ;
21212121
21222122 if (file_exists (am_path (state , "dirtyindex" )))
21232123 return 0 ;
21242124
21252125 if (read_state_file (& sb , state , "abort-safety" , 1 ) > 0 ) {
2126- if (get_sha1_hex (sb .buf , abort_safety ))
2126+ if (get_oid_hex (sb .buf , & abort_safety ))
21272127 die (_ ("could not parse %s" ), am_path (state , "abort_safety" ));
21282128 } else
2129- hashclr ( abort_safety );
2129+ oidclr ( & abort_safety );
21302130
2131- if (get_sha1 ("HEAD" , head ))
2132- hashclr ( head );
2131+ if (get_oid ("HEAD" , & head ))
2132+ oidclr ( & head );
21332133
2134- if (!hashcmp ( head , abort_safety ))
2134+ if (!oidcmp ( & head , & abort_safety ))
21352135 return 1 ;
21362136
21372137 error (_ ("You seem to have moved HEAD since the last 'am' failure.\n"
@@ -2145,7 +2145,7 @@ static int safe_to_abort(const struct am_state *state)
21452145 */
21462146static void am_abort (struct am_state * state )
21472147{
2148- unsigned char curr_head [ GIT_SHA1_RAWSZ ] , orig_head [ GIT_SHA1_RAWSZ ] ;
2148+ struct object_id curr_head , orig_head ;
21492149 int has_curr_head , has_orig_head ;
21502150 char * curr_branch ;
21512151
@@ -2156,20 +2156,20 @@ static void am_abort(struct am_state *state)
21562156
21572157 am_rerere_clear ();
21582158
2159- curr_branch = resolve_refdup ("HEAD" , 0 , curr_head , NULL );
2160- has_curr_head = !is_null_sha1 ( curr_head );
2159+ curr_branch = resolve_refdup ("HEAD" , 0 , curr_head . hash , NULL );
2160+ has_curr_head = !is_null_oid ( & curr_head );
21612161 if (!has_curr_head )
2162- hashcpy (curr_head , EMPTY_TREE_SHA1_BIN );
2162+ hashcpy (curr_head . hash , EMPTY_TREE_SHA1_BIN );
21632163
2164- has_orig_head = !get_sha1 ("ORIG_HEAD" , orig_head );
2164+ has_orig_head = !get_oid ("ORIG_HEAD" , & orig_head );
21652165 if (!has_orig_head )
2166- hashcpy (orig_head , EMPTY_TREE_SHA1_BIN );
2166+ hashcpy (orig_head . hash , EMPTY_TREE_SHA1_BIN );
21672167
2168- clean_index (curr_head , orig_head );
2168+ clean_index (& curr_head , & orig_head );
21692169
21702170 if (has_orig_head )
2171- update_ref ("am --abort" , "HEAD" , orig_head ,
2172- has_curr_head ? curr_head : NULL , 0 ,
2171+ update_ref_oid ("am --abort" , "HEAD" , & orig_head ,
2172+ has_curr_head ? & curr_head : NULL , 0 ,
21732173 UPDATE_REFS_DIE_ON_ERR );
21742174 else if (curr_branch )
21752175 delete_ref (curr_branch , NULL , REF_NODEREF );
0 commit comments