MCPcopy Create free account
hub / github.com/go-git/go-git / pushHashes

Function pushHashes

remote.go:1427–1475  ·  view source on GitHub ↗
(
	ctx context.Context,
	sess transport.ReceivePackSession,
	s storage.Storer,
	req *packp.ReferenceUpdateRequest,
	hs []plumbing.Hash,
	useRefDeltas bool,
	allDelete bool,
)

Source from the content-addressed store, hash-verified

1425}
1426
1427func pushHashes(
1428 ctx context.Context,
1429 sess transport.ReceivePackSession,
1430 s storage.Storer,
1431 req *packp.ReferenceUpdateRequest,
1432 hs []plumbing.Hash,
1433 useRefDeltas bool,
1434 allDelete bool,
1435) (*packp.ReportStatus, error) {
1436 rd, wr := io.Pipe()
1437
1438 config, err := s.Config()
1439 if err != nil {
1440 return nil, err
1441 }
1442
1443 // Set buffer size to 1 so the error message can be written when
1444 // ReceivePack fails. Otherwise the goroutine will be blocked writing
1445 // to the channel.
1446 done := make(chan error, 1)
1447
1448 if !allDelete {
1449 req.Packfile = rd
1450 go func() {
1451 e := packfile.NewEncoder(wr, s, useRefDeltas)
1452 if _, err := e.Encode(hs, config.Pack.Window); err != nil {
1453 done <- wr.CloseWithError(err)
1454 return
1455 }
1456
1457 done <- wr.Close()
1458 }()
1459 } else {
1460 close(done)
1461 }
1462
1463 rs, err := sess.ReceivePack(ctx, req)
1464 if err != nil {
1465 // close the pipe to unlock encode write
1466 _ = rd.Close()
1467 return nil, err
1468 }
1469
1470 if err := <-done; err != nil {
1471 return nil, err
1472 }
1473
1474 return rs, nil
1475}
1476
1477func (r *Remote) updateShallow(o *FetchOptions, resp *packp.UploadPackResponse) error {
1478 if o.Depth == 0 || len(resp.Shallows) == 0 {

Callers 1

PushContextMethod · 0.85

Calls 5

EncodeMethod · 0.95
NewEncoderFunction · 0.92
ConfigMethod · 0.65
CloseMethod · 0.65
ReceivePackMethod · 0.65

Tested by

no test coverage detected