Commit dccb32b
object-file.c: stop dying in parse_loose_header()
Make parse_loose_header() return error codes and data instead of
invoking die() by itself.
For now we'll move the relevant die() call to loose_object_info() and
read_loose_object() to keep this change smaller. In a subsequent
commit we'll make read_loose_object() return an error code instead of
dying. We should also address the "allow_unknown" case (should be
moved to builtin/cat-file.c), but for now I'll be leaving it.
For making parse_loose_header() not die() change its prototype to
accept a "struct object_info *" instead of the "unsigned long *sizep"
it accepted before. Its callers can now check the populated populated
"oi->typep".
Because of this we don't need to pass in the "unsigned int flags"
which we used for OBJECT_INFO_ALLOW_UNKNOWN_TYPE, we can instead do
that check in loose_object_info().
This also refactors some confusing control flow around the "status"
variable. In some cases we set it to the return value of "error()",
i.e. -1, and later checked if "status < 0" was true.
Since 93cff9a (sha1_loose_object_info: return error for corrupted
objects, 2017-04-01) the return value of loose_object_info() (then
named sha1_loose_object_info()) had been a "status" variable that be
any negative value, as we were expecting to return the "enum
object_type".
The only negative type happens to be OBJ_BAD, but the code still
assumed that more might be added. This was then used later in
e.g. c84a1f3 (sha1_file: refactor read_object, 2017-06-21). Now
that parse_loose_header() will return 0 on success instead of the
type (which it'll stick into the "struct object_info") we don't need
to conflate these two cases in its callers.
Since parse_loose_header() doesn't need to return an arbitrary
"status" we only need to treat its "ret < 0" specially, but can
idiomatically overwrite it with our own error() return. This along
with having made unpack_loose_header() return an "enum
unpack_loose_header_result" in an earlier commit means that we can
move the previously nested if/else cases mostly into the "ULHR_OK"
branch of the "switch" statement.
We should be less silent if we reach that "status = -1" branch, which
happens if we've got trailing garbage in loose objects, see
f6371f9 (sha1_file: add read_loose_object() function, 2017-01-13)
for a better way to handle it. For now let's punt on it, a subsequent
commit will address that edge case.
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent 5848fb1 commit dccb32b
3 files changed
+44
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
1335 | 1343 | | |
1336 | | - | |
1337 | | - | |
| 1344 | + | |
1338 | 1345 | | |
1339 | 1346 | | |
1340 | 1347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1324 | 1324 | | |
1325 | 1325 | | |
1326 | 1326 | | |
1327 | | - | |
1328 | | - | |
| 1327 | + | |
1329 | 1328 | | |
1330 | 1329 | | |
1331 | 1330 | | |
| |||
1347 | 1346 | | |
1348 | 1347 | | |
1349 | 1348 | | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | 1349 | | |
1360 | 1350 | | |
1361 | 1351 | | |
| |||
1382 | 1372 | | |
1383 | 1373 | | |
1384 | 1374 | | |
1385 | | - | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
1386 | 1383 | | |
1387 | 1384 | | |
1388 | 1385 | | |
| |||
1396 | 1393 | | |
1397 | 1394 | | |
1398 | 1395 | | |
| 1396 | + | |
1399 | 1397 | | |
1400 | 1398 | | |
1401 | 1399 | | |
| |||
1427 | 1425 | | |
1428 | 1426 | | |
1429 | 1427 | | |
| 1428 | + | |
| 1429 | + | |
1430 | 1430 | | |
1431 | 1431 | | |
1432 | 1432 | | |
1433 | 1433 | | |
1434 | 1434 | | |
1435 | 1435 | | |
1436 | 1436 | | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
1437 | 1449 | | |
1438 | 1450 | | |
1439 | 1451 | | |
| |||
1445 | 1457 | | |
1446 | 1458 | | |
1447 | 1459 | | |
1448 | | - | |
1449 | | - | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
1463 | | - | |
1464 | | - | |
1465 | | - | |
1466 | | - | |
| 1460 | + | |
| 1461 | + | |
1467 | 1462 | | |
1468 | 1463 | | |
1469 | 1464 | | |
1470 | 1465 | | |
| 1466 | + | |
| 1467 | + | |
1471 | 1468 | | |
1472 | | - | |
| 1469 | + | |
1473 | 1470 | | |
1474 | 1471 | | |
1475 | 1472 | | |
| |||
2533 | 2530 | | |
2534 | 2531 | | |
2535 | 2532 | | |
| 2533 | + | |
2536 | 2534 | | |
2537 | 2535 | | |
2538 | 2536 | | |
| |||
2549 | 2547 | | |
2550 | 2548 | | |
2551 | 2549 | | |
2552 | | - | |
2553 | | - | |
| 2550 | + | |
2554 | 2551 | | |
2555 | 2552 | | |
2556 | 2553 | | |
2557 | 2554 | | |
| 2555 | + | |
| 2556 | + | |
2558 | 2557 | | |
2559 | 2558 | | |
2560 | 2559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
| |||
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
241 | | - | |
| 242 | + | |
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
| |||
0 commit comments