Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

object/id: Zero is a property of the algorithm

Runxi Yu cdac7752 32f84b9d

+42 -46
+1 -3
network/protocol/v0v1/server/advertise.go
··· 3 3 import ( 4 4 "fmt" 5 5 "strings" 6 - 7 - objectid "codeberg.org/lindenii/furgit/object/id" 8 6 ) 9 7 10 8 // AdvertiseRefs writes one server ref advertisement. ··· 20 18 21 19 refs := sortAdvertisedRefs(ad.Refs) 22 20 if len(refs) == 0 { 23 - line := fmt.Sprintf("%s capabilities^{}\x00%s\n", objectid.Zero(session.opts.Algorithm), capList) 21 + line := fmt.Sprintf("%s capabilities^{}\x00%s\n", session.opts.Algorithm.Zero(), capList) 24 22 25 23 err := session.enc.WriteData([]byte(line)) 26 24 if err != nil {
+1 -1
network/protocol/v0v1/server/advertise_test.go
··· 93 93 94 94 got := out.String() 95 95 96 - want := objectid.Zero(algo).String() + " capabilities^{}\x00report-status object-format=" + algo.String() + "\n" 96 + want := algo.Zero().String() + " capabilities^{}\x00report-status object-format=" + algo.String() + "\n" 97 97 if !strings.Contains(got, want) { 98 98 t.Fatalf("unexpected no-refs advertisement %q", got) 99 99 }
+4 -4
network/protocol/v0v1/server/receivepack/parse_test.go
··· 19 19 testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { 20 20 t.Parallel() 21 21 22 - oldZero := objectid.Zero(algo).String() 22 + oldZero := algo.Zero().String() 23 23 oneID := mustHexID(t, algo, "1") 24 24 25 25 var wire bufferWriteFlusher ··· 105 105 enc := pktline.NewEncoder(&wire) 106 106 107 107 err := enc.WriteData([]byte( 108 - oneID.String() + " " + objectid.Zero(algo).String() + " refs/heads/old\x00delete-refs object-format=" + algo.String() + "\n", 108 + oneID.String() + " " + algo.Zero().String() + " refs/heads/old\x00delete-refs object-format=" + algo.String() + "\n", 109 109 )) 110 110 if err != nil { 111 111 t.Fatalf("WriteData: %v", err) ··· 153 153 enc := pktline.NewEncoder(&wire) 154 154 155 155 err := enc.WriteData([]byte( 156 - objectid.Zero(algo).String() + " " + oneID.String() + " refs/heads/main\x00atomic object-format=" + algo.String() + "\n", 156 + algo.Zero().String() + " " + oneID.String() + " refs/heads/main\x00atomic object-format=" + algo.String() + "\n", 157 157 )) 158 158 if err != nil { 159 159 t.Fatalf("WriteData: %v", err) ··· 209 209 "nonce nonce\n", 210 210 "push-option ci.skip\n", 211 211 "\n", 212 - objectid.Zero(algo).String() + " " + oneID.String() + " refs/heads/main\n", 212 + algo.Zero().String() + " " + oneID.String() + " refs/heads/main\n", 213 213 "-----BEGIN PGP SIGNATURE-----\n", 214 214 "abcdef\n", 215 215 "push-cert-end\n",
+2 -2
network/protocol/v0v1/server/receivepack/report_status_test.go
··· 59 59 requestEnc := pktline.NewEncoder(&requestWire) 60 60 61 61 err := requestEnc.WriteData([]byte( 62 - objectid.Zero(algo).String() + " " + mustHexID(t, algo, "1").String() + " refs/heads/main\x00report-status side-band-64k object-format=" + algo.String() + "\n", 62 + algo.Zero().String() + " " + mustHexID(t, algo, "1").String() + " refs/heads/main\x00report-status side-band-64k object-format=" + algo.String() + "\n", 63 63 )) 64 64 if err != nil { 65 65 t.Fatalf("WriteData(request): %v", err) ··· 243 243 requestEnc := pktline.NewEncoder(&requestWire) 244 244 245 245 err := requestEnc.WriteData([]byte( 246 - objectid.Zero(algo).String() + " " + mustHexID(t, algo, "1").String() + " refs/heads/main\x00report-status side-band-64k object-format=" + algo.String() + "\n", 246 + algo.Zero().String() + " " + mustHexID(t, algo, "1").String() + " refs/heads/main\x00report-status side-band-64k object-format=" + algo.String() + "\n", 247 247 )) 248 248 if err != nil { 249 249 t.Fatalf("WriteData(request): %v", err)
+1 -1
network/protocol/v0v1/server/receivepack/session.go
··· 208 208 } 209 209 210 210 func commandIsDelete(cmd Command) bool { 211 - return cmd.NewID == objectid.Zero(cmd.NewID.Algorithm()) 211 + return cmd.NewID == cmd.NewID.Algorithm().Zero() 212 212 } 213 213 214 214 func deleteOnly(commands []Command) bool {
+1 -2
network/receivepack/hooks/reject_force_push.go
··· 7 7 8 8 "codeberg.org/lindenii/furgit/commitquery" 9 9 receivepack "codeberg.org/lindenii/furgit/network/receivepack" 10 - objectid "codeberg.org/lindenii/furgit/object/id" 11 10 objectmix "codeberg.org/lindenii/furgit/object/store/mix" 12 11 refstore "codeberg.org/lindenii/furgit/ref/store" 13 12 ) ··· 33 32 } 34 33 35 34 for i, update := range req.Updates { 36 - if update.OldID == objectid.Zero(update.OldID.Algorithm()) || update.NewID == objectid.Zero(update.NewID.Algorithm()) { 35 + if update.OldID == update.OldID.Algorithm().Zero() || update.NewID == update.NewID.Algorithm().Zero() { 37 36 continue 38 37 } 39 38
+14 -14
network/receivepack/int_test.go
··· 36 36 ) 37 37 38 38 input.WriteString(pktlineData( 39 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 39 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 40 40 )) 41 41 input.WriteString("0000") 42 42 ··· 83 83 ) 84 84 85 85 input.WriteString(pktlineData( 86 - staleID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status delete-refs object-format=" + algo.String() + "\n", 86 + staleID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status delete-refs object-format=" + algo.String() + "\n", 87 87 )) 88 88 input.WriteString(pktlineData( 89 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/topic\n", 89 + commitID.String() + " " + algo.Zero().String() + " refs/heads/topic\n", 90 90 )) 91 91 input.WriteString("0000") 92 92 ··· 138 138 ) 139 139 140 140 input.WriteString(pktlineData( 141 - staleID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 141 + staleID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 142 142 )) 143 143 input.WriteString(pktlineData( 144 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/topic\n", 144 + commitID.String() + " " + algo.Zero().String() + " refs/heads/topic\n", 145 145 )) 146 146 input.WriteString("0000") 147 147 ··· 242 242 ) 243 243 244 244 input.WriteString(pktlineData( 245 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00delete-refs atomic object-format=" + algo.String() + "\n", 245 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00delete-refs atomic object-format=" + algo.String() + "\n", 246 246 )) 247 247 input.WriteString("0000") 248 248 ··· 281 281 ) 282 282 283 283 input.WriteString(pktlineData( 284 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 284 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status atomic delete-refs object-format=" + algo.String() + "\n", 285 285 )) 286 286 input.WriteString("0000") 287 287 ··· 365 365 ) 366 366 367 367 input.WriteString(pktlineData( 368 - objectid.Zero(algo).String() + " " + commitID.String() + " refs/heads/main\x00report-status-v2 atomic object-format=" + algo.String() + "\n", 368 + algo.Zero().String() + " " + commitID.String() + " refs/heads/main\x00report-status-v2 atomic object-format=" + algo.String() + "\n", 369 369 )) 370 370 input.WriteString("0000") 371 371 ··· 437 437 ) 438 438 439 439 input.WriteString(pktlineData( 440 - objectid.Zero(algo).String() + " " + commitID.String() + " refs/heads/main\x00report-status-v2 atomic object-format=" + algo.String() + "\n", 440 + algo.Zero().String() + " " + commitID.String() + " refs/heads/main\x00report-status-v2 atomic object-format=" + algo.String() + "\n", 441 441 )) 442 442 input.WriteString("0000") 443 443 ··· 519 519 ) 520 520 521 521 input.WriteString(pktlineData( 522 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status delete-refs object-format=" + algo.String() + "\n", 522 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status delete-refs object-format=" + algo.String() + "\n", 523 523 )) 524 524 input.WriteString(pktlineData( 525 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/topic\n", 525 + commitID.String() + " " + algo.Zero().String() + " refs/heads/topic\n", 526 526 )) 527 527 input.WriteString("0000") 528 528 ··· 577 577 ) 578 578 579 579 input.WriteString(pktlineData( 580 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status side-band-64k atomic delete-refs object-format=" + algo.String() + "\n", 580 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status side-band-64k atomic delete-refs object-format=" + algo.String() + "\n", 581 581 )) 582 582 input.WriteString("0000") 583 583 ··· 725 725 ) 726 726 727 727 input.WriteString(pktlineData( 728 - commitID.String() + " " + objectid.Zero(algo).String() + " refs/heads/main\x00report-status-v2 atomic delete-refs object-format=" + algo.String() + "\n", 728 + commitID.String() + " " + algo.Zero().String() + " refs/heads/main\x00report-status-v2 atomic delete-refs object-format=" + algo.String() + "\n", 729 729 )) 730 730 input.WriteString("0000") 731 731 ··· 747 747 t.Fatalf("missing option old-oid in %q", got) 748 748 } 749 749 750 - if !strings.Contains(got, "option new-oid "+objectid.Zero(algo).String()+"\n") { 750 + if !strings.Contains(got, "option new-oid "+algo.Zero().String()+"\n") { 751 751 t.Fatalf("missing option new-oid in %q", got) 752 752 } 753 753 })
+2 -3
network/receivepack/service/apply.go
··· 2 2 3 3 import ( 4 4 "codeberg.org/lindenii/furgit/internal/utils" 5 - objectid "codeberg.org/lindenii/furgit/object/id" 6 5 refstore "codeberg.org/lindenii/furgit/ref/store" 7 6 ) 8 7 ··· 101 100 return tx.Delete(command.Name, command.OldID) 102 101 } 103 102 104 - if command.OldID == objectid.Zero(command.OldID.Algorithm()) { 103 + if command.OldID == command.OldID.Algorithm().Zero() { 105 104 return tx.Create(command.Name, command.NewID) 106 105 } 107 106 ··· 115 114 return 116 115 } 117 116 118 - if command.OldID == objectid.Zero(command.OldID.Algorithm()) { 117 + if command.OldID == command.OldID.Algorithm().Zero() { 119 118 batch.Create(command.Name, command.NewID) 120 119 121 120 return
+1 -1
network/receivepack/service/command.go
··· 22 22 } 23 23 24 24 func isDelete(command Command) bool { 25 - return command.NewID == objectid.Zero(command.NewID.Algorithm()) 25 + return command.NewID == command.NewID.Algorithm().Zero() 26 26 } 27 27 28 28 func objectIDPointer(id objectid.ObjectID) *objectid.ObjectID {
+4 -4
network/receivepack/service/service_test.go
··· 29 29 result, err := svc.Execute(context.Background(), &service.Request{ 30 30 Commands: []service.Command{{ 31 31 Name: "refs/heads/main", 32 - OldID: objectid.Zero(algo), 33 - NewID: objectid.Zero(algo), 32 + OldID: algo.Zero(), 33 + NewID: algo.Zero(), 34 34 }}, 35 35 PackExpected: true, 36 36 Pack: strings.NewReader("not a pack"), ··· 73 73 result, err := svc.Execute(context.Background(), &service.Request{ 74 74 Commands: []service.Command{{ 75 75 Name: "refs/heads/main", 76 - OldID: objectid.Zero(algo), 77 - NewID: objectid.Zero(algo), 76 + OldID: algo.Zero(), 77 + NewID: algo.Zero(), 78 78 }}, 79 79 PackExpected: true, 80 80 Pack: strings.NewReader("not a pack"),
+11
object/id/algorithm_zero.go
··· 1 + package objectid 2 + 3 + // Zero returns the all-zero object ID for this algorithm. 4 + func (algo Algorithm) Zero() ObjectID { 5 + id, err := FromBytes(algo, make([]byte, algo.Size())) 6 + if err != nil { 7 + panic(err) 8 + } 9 + 10 + return id 11 + }
-11
object/id/objectid_zero.go
··· 1 - package objectid 2 - 3 - // Zero returns the all-zero object ID for the specified algorithm. 4 - func Zero(algo Algorithm) ObjectID { 5 - id, err := FromBytes(algo, make([]byte, algo.Size())) 6 - if err != nil { 7 - panic(err) 8 - } 9 - 10 - return id 11 - }