@@ -22,8 +22,6 @@ const git_oid git_oid__empty_tree_sha1 =
2222 { 0x4b , 0x82 , 0x5d , 0xc6 , 0x42 , 0xcb , 0x6e , 0xb9 , 0xa0 , 0x60 ,
2323 0xe5 , 0x4b , 0xf8 , 0xd6 , 0x92 , 0x88 , 0xfb , 0xee , 0x49 , 0x04 }};
2424
25- static char to_hex [] = "0123456789abcdef" ;
26-
2725static int oid_error_invalid (const char * msg )
2826{
2927 git_error_set (GIT_ERROR_INVALID , "unable to parse OID - %s" , msg );
@@ -75,16 +73,9 @@ int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type)
7573 return git_oid_fromstrn (out , str , git_oid_hexsize (type ), type );
7674}
7775
78- GIT_INLINE (char ) * fmt_one (char * str , unsigned int val )
79- {
80- * str ++ = to_hex [val >> 4 ];
81- * str ++ = to_hex [val & 0xf ];
82- return str ;
83- }
84-
8576int git_oid_nfmt (char * str , size_t n , const git_oid * oid )
8677{
87- size_t hex_size , i , max_i ;
78+ size_t hex_size ;
8879
8980 if (!oid ) {
9081 memset (str , 0 , n );
@@ -99,14 +90,7 @@ int git_oid_nfmt(char *str, size_t n, const git_oid *oid)
9990 n = hex_size ;
10091 }
10192
102- max_i = n / 2 ;
103-
104- for (i = 0 ; i < max_i ; i ++ )
105- str = fmt_one (str , oid -> id [i ]);
106-
107- if (n & 1 )
108- * str ++ = to_hex [oid -> id [i ] >> 4 ];
109-
93+ git_oid_fmt_substr (str , oid , 0 , n );
11094 return 0 ;
11195}
11296
@@ -117,16 +101,14 @@ int git_oid_fmt(char *str, const git_oid *oid)
117101
118102int git_oid_pathfmt (char * str , const git_oid * oid )
119103{
120- size_t size , i ;
104+ size_t hex_size ;
121105
122- if (!(size = git_oid_size (oid -> type )))
106+ if (!(hex_size = git_oid_hexsize (oid -> type )))
123107 return oid_error_invalid ("unknown type" );
124108
125- str = fmt_one (str , oid -> id [0 ]);
126- * str ++ = '/' ;
127- for (i = 1 ; i < size ; i ++ )
128- str = fmt_one (str , oid -> id [i ]);
129-
109+ git_oid_fmt_substr (str , oid , 0 , 2 );
110+ str [2 ] = '/' ;
111+ git_oid_fmt_substr (& str [3 ], oid , 2 , (hex_size - 2 ));
130112 return 0 ;
131113}
132114
0 commit comments