@@ -1068,8 +1068,10 @@ static const char PACKED_REFS_HEADER[] =
1068
1068
* Return a pointer to the refname within the line (null-terminated),
1069
1069
* or NULL if there was a problem.
1070
1070
*/
1071
- static const char * parse_ref_line (char * line , unsigned char * sha1 )
1071
+ static const char * parse_ref_line (struct strbuf * line , unsigned char * sha1 )
1072
1072
{
1073
+ const char * ref ;
1074
+
1073
1075
/*
1074
1076
* 42: the answer to everything.
1075
1077
*
@@ -1078,22 +1080,23 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
1078
1080
* +1 (space in between hex and name)
1079
1081
* +1 (newline at the end of the line)
1080
1082
*/
1081
- int len = strlen (line ) - 42 ;
1082
-
1083
- if (len <= 0 )
1083
+ if (line -> len <= 42 )
1084
1084
return NULL ;
1085
- if (get_sha1_hex (line , sha1 ) < 0 )
1085
+
1086
+ if (get_sha1_hex (line -> buf , sha1 ) < 0 )
1086
1087
return NULL ;
1087
- if (!isspace (line [40 ]))
1088
+ if (!isspace (line -> buf [40 ]))
1088
1089
return NULL ;
1089
- line += 41 ;
1090
- if (isspace (* line ))
1090
+
1091
+ ref = line -> buf + 41 ;
1092
+ if (isspace (* ref ))
1091
1093
return NULL ;
1092
- if (line [len ] != '\n' )
1094
+
1095
+ if (line -> buf [line -> len - 1 ] != '\n' )
1093
1096
return NULL ;
1094
- line [ len ] = 0 ;
1097
+ line -> buf [ -- line -> len ] = 0 ;
1095
1098
1096
- return line ;
1099
+ return ref ;
1097
1100
}
1098
1101
1099
1102
/*
@@ -1126,16 +1129,15 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
1126
1129
static void read_packed_refs (FILE * f , struct ref_dir * dir )
1127
1130
{
1128
1131
struct ref_entry * last = NULL ;
1129
- char refline [ PATH_MAX ] ;
1132
+ struct strbuf line = STRBUF_INIT ;
1130
1133
enum { PEELED_NONE , PEELED_TAGS , PEELED_FULLY } peeled = PEELED_NONE ;
1131
1134
1132
- while (fgets ( refline , sizeof ( refline ), f ) ) {
1135
+ while (strbuf_getwholeline ( & line , f , '\n' ) != EOF ) {
1133
1136
unsigned char sha1 [20 ];
1134
1137
const char * refname ;
1135
- static const char header [] = "# pack-refs with:" ;
1138
+ const char * traits ;
1136
1139
1137
- if (!strncmp (refline , header , sizeof (header )- 1 )) {
1138
- const char * traits = refline + sizeof (header ) - 1 ;
1140
+ if (skip_prefix (line .buf , "# pack-refs with:" , & traits )) {
1139
1141
if (strstr (traits , " fully-peeled " ))
1140
1142
peeled = PEELED_FULLY ;
1141
1143
else if (strstr (traits , " peeled " ))
@@ -1144,7 +1146,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1144
1146
continue ;
1145
1147
}
1146
1148
1147
- refname = parse_ref_line (refline , sha1 );
1149
+ refname = parse_ref_line (& line , sha1 );
1148
1150
if (refname ) {
1149
1151
int flag = REF_ISPACKED ;
1150
1152
@@ -1160,10 +1162,10 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1160
1162
continue ;
1161
1163
}
1162
1164
if (last &&
1163
- refline [0 ] == '^' &&
1164
- strlen ( refline ) == PEELED_LINE_LENGTH &&
1165
- refline [PEELED_LINE_LENGTH - 1 ] == '\n' &&
1166
- !get_sha1_hex (refline + 1 , sha1 )) {
1165
+ line . buf [0 ] == '^' &&
1166
+ line . len == PEELED_LINE_LENGTH &&
1167
+ line . buf [PEELED_LINE_LENGTH - 1 ] == '\n' &&
1168
+ !get_sha1_hex (line . buf + 1 , sha1 )) {
1167
1169
hashcpy (last -> u .value .peeled , sha1 );
1168
1170
/*
1169
1171
* Regardless of what the file header said,
@@ -1173,6 +1175,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1173
1175
last -> flag |= REF_KNOWS_PEELED ;
1174
1176
}
1175
1177
}
1178
+
1179
+ strbuf_release (& line );
1176
1180
}
1177
1181
1178
1182
/*
0 commit comments