Signed-off-by: Seongmin Lee git@boltless.me
+127
-200
Diff
round #0
+5
-17
appview/db/pulls.go
+5
-17
appview/db/pulls.go
···
194
194
pull_at,
195
195
round_number,
196
196
patch,
197
-
combined,
198
197
source_rev,
199
198
patch_blob_ref,
200
199
patch_blob_mime,
201
200
patch_blob_size
202
201
)
203
-
values (?, ?, ?, ?, ?, ?, ?, ?)
202
+
values (?, ?, ?, ?, ?, ?, ?)
204
203
`,
205
204
pull.AtUri(),
206
205
i,
207
206
s.Patch,
208
-
s.Combined,
209
207
s.SourceRev,
210
208
s.Blob.Ref.String(),
211
209
s.Blob.MimeType,
···
255
253
pull_at,
256
254
round_number,
257
255
patch,
258
-
combined,
259
256
source_rev,
260
257
patch_blob_ref,
261
258
patch_blob_mime,
262
259
patch_blob_size
263
260
)
264
-
values (?, ?, ?, ?, ?, ?, ?, ?)
261
+
values (?, ?, ?, ?, ?, ?, ?)
265
262
`,
266
263
pull.AtUri(),
267
264
i,
268
265
s.Patch,
269
-
s.Combined,
270
266
s.SourceRev,
271
267
s.Blob.Ref.String(),
272
268
s.Blob.MimeType,
···
505
501
pull_at,
506
502
round_number,
507
503
patch,
508
-
combined,
509
504
created,
510
505
source_rev,
511
506
patch_blob_ref,
···
529
524
for rows.Next() {
530
525
var submission models.PullSubmission
531
526
var submissionCreatedStr string
532
-
var submissionSourceRev, submissionCombined sql.Null[string]
527
+
var submissionSourceRev sql.Null[string]
533
528
var patchBlobRef, patchBlobMime sql.Null[string]
534
529
var patchBlobSize sql.Null[int64]
535
530
err := rows.Scan(
···
537
532
&submission.PullAt,
538
533
&submission.RoundNumber,
539
534
&submission.Patch,
540
-
&submissionCombined,
541
535
&submissionCreatedStr,
542
536
&submissionSourceRev,
543
537
&patchBlobRef,
···
556
550
submission.SourceRev = submissionSourceRev.V
557
551
}
558
552
559
-
if submissionCombined.Valid {
560
-
submission.Combined = submissionCombined.V
561
-
}
562
-
563
553
if patchBlobRef.Valid {
564
554
submission.Blob.Ref = lexutil.LexLink(cid.MustParse(patchBlobRef.V))
565
555
}
···
845
835
pullAt syntax.ATURI,
846
836
newRoundNumber int,
847
837
newPatch string,
848
-
combinedPatch string,
849
838
newSourceRev string,
850
839
blob *lexutil.LexBlob,
851
840
) error {
···
854
843
pull_at,
855
844
round_number,
856
845
patch,
857
-
combined,
858
846
source_rev,
859
847
patch_blob_ref,
860
848
patch_blob_mime,
861
849
patch_blob_size
862
850
)
863
-
values (?, ?, ?, ?, ?, ?, ?, ?)
864
-
`, pullAt, newRoundNumber, newPatch, combinedPatch, newSourceRev, blob.Ref.String(), blob.MimeType, blob.Size)
851
+
values (?, ?, ?, ?, ?, ?, ?)
852
+
`, pullAt, newRoundNumber, newPatch, newSourceRev, blob.Ref.String(), blob.MimeType, blob.Size)
865
853
866
854
return err
867
855
}
-9
appview/models/pull.go
-9
appview/models/pull.go
···
298
298
RoundNumber int
299
299
Blob lexutil.LexBlob
300
300
Patch string
301
-
Combined string
302
301
Comments []PullComment
303
302
SourceRev string // include the rev that was used to create this submission: only for branch/fork PRs
304
303
···
457
456
return participants
458
457
}
459
458
460
-
func (s PullSubmission) CombinedPatch() string {
461
-
if s.Combined == "" {
462
-
return s.Patch
463
-
}
464
-
465
-
return s.Combined
466
-
}
467
-
468
459
func (s *PullSubmission) GetBlob() *lexutil.LexBlob {
469
460
if !s.Blob.Ref.Defined() {
470
461
return nil
+122
-174
appview/pulls/pulls.go
+122
-174
appview/pulls/pulls.go
···
197
197
l.Error("failed to parse round id", "err", err, "round_number", roundIdInt)
198
198
return
199
199
}
200
+
if interdiff && roundIdInt < 1 {
201
+
http.Error(w, "bad round id", http.StatusBadRequest)
202
+
l.Error("failed to parse round id", "err", err, "round_number", roundIdInt)
203
+
return
204
+
}
200
205
201
206
var diffOpts types.DiffOpts
202
207
if d := r.URL.Query().Get("diff"); d == "split" {
···
275
280
}
276
281
}
277
282
278
-
patch := pull.Submissions[roundIdInt].CombinedPatch()
283
+
ctx := r.Context()
284
+
xrpcc := &indigoxrpc.Client{Host: s.config.KnotMirror.Url}
285
+
279
286
var diff types.DiffRenderer
280
-
diff = patchutil.AsNiceDiff(patch, pull.TargetBranch)
281
287
282
288
if interdiff {
283
-
currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch())
284
-
if err != nil {
285
-
l.Error("failed to interdiff; current patch malformed", "err", err, "round_number", roundIdInt)
286
-
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.")
287
-
return
288
-
}
289
+
if pull.IsForkBased() {
290
+
// calculate interdiff in appview
291
+
prevPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].Patch)
292
+
if err != nil {
293
+
l.Error("failed to interdiff; previous patch malformed", "err", err, "round_number", roundIdInt)
294
+
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.")
295
+
return
296
+
}
297
+
currPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].Patch)
298
+
if err != nil {
299
+
l.Error("failed to interdiff; current patch malformed", "err", err, "round_number", roundIdInt)
300
+
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.")
301
+
return
302
+
}
303
+
diff = patchutil.Interdiff(prevPatch, currPatch)
304
+
} else {
305
+
var sourceRepo string
306
+
if pull.PullSource != nil && pull.PullSource.RepoAt != nil {
307
+
sourceRepo = pull.PullSource.RepoAt.String()
308
+
}
309
+
xrpcBytes, err := tangled.GitTempInterdiffRevs(
310
+
ctx,
311
+
xrpcc,
312
+
pull.TargetBranch,
313
+
pull.Submissions[roundIdInt-1].SourceRev,
314
+
pull.Submissions[roundIdInt].SourceRev,
315
+
sourceRepo,
316
+
pull.RepoAt.String(),
317
+
)
318
+
if err != nil {
319
+
l.Error("failed to call git.interdiffRevs", "err", err, "round_number", roundIdInt)
320
+
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff.")
321
+
return
322
+
}
289
323
290
-
previousPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].CombinedPatch())
324
+
// NOTE: see comment at knotmirror/xrpc/git_interdiff_revs.go
325
+
var out struct{
326
+
Patch1 string
327
+
Patch2 string
328
+
}
329
+
if err := json.Unmarshal(xrpcBytes, &out); err != nil {
330
+
l.Error("failed to decode XRPC response", "err", err)
331
+
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff.")
332
+
return
333
+
}
334
+
335
+
diff, err = func() (*patchutil.InterdiffResult, error) {
336
+
l.Debug("interdiff", "patch1", out.Patch1, "patch2", out.Patch2)
337
+
patch1, err := patchutil.AsDiff(out.Patch1)
338
+
if err != nil {
339
+
return nil, err
340
+
}
341
+
patch2, err := patchutil.AsDiff(out.Patch2)
342
+
if err != nil {
343
+
return nil, err
344
+
}
345
+
return patchutil.Interdiff(patch1, patch2), nil
346
+
}()
347
+
if err != nil {
348
+
l.Error("failed to interdiff", "err", err, "round_number", roundIdInt)
349
+
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff.")
350
+
return
351
+
}
352
+
}
353
+
} else {
354
+
// diff from merge-base to pull sourceRev
355
+
out, err := tangled.GitTempCompareRevs(ctx, xrpcc, pull.RepoAt.String(), pull.TargetBranch, pull.Submissions[roundIdInt].SourceRev)
291
356
if err != nil {
292
-
l.Error("failed to interdiff; previous patch malformed", "err", err, "round_number", roundIdInt)
293
-
s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.")
357
+
l.Error("failed to get combined patch", "err", err)
358
+
s.pages.Error503(w)
294
359
return
295
360
}
296
-
297
-
diff = patchutil.Interdiff(previousPatch, currentPatch)
361
+
diff = patchutil.AsNiceDiff(out.Patch, pull.TargetBranch)
298
362
}
299
363
300
364
err = s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{
···
1120
1184
) {
1121
1185
l := s.logger.With("handler", "handleBranchBasedPull", "user", userDid, "target_branch", targetBranch, "source_branch", sourceBranch, "is_stacked", isStacked)
1122
1186
1123
-
scheme := "http"
1124
-
if !s.config.Core.Dev {
1125
-
scheme = "https"
1126
-
}
1127
-
host := fmt.Sprintf("%s://%s", scheme, repo.Knot)
1128
-
xrpcc := &indigoxrpc.Client{
1129
-
Host: host,
1130
-
}
1187
+
xrpcc := &indigoxrpc.Client{Host: s.config.KnotMirror.Url}
1131
1188
1132
-
xrpcBytes, err := tangled.RepoCompare(r.Context(), xrpcc, repo.RepoIdentifier(), targetBranch, sourceBranch)
1189
+
fpOut, err := tangled.GitTempFormatPatch(r.Context(), xrpcc, repo.RepoAt().String(), "", targetBranch, sourceBranch)
1133
1190
if err != nil {
1134
1191
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1135
-
l.Error("failed to call XRPC repo.compare", "xrpcerr", xrpcerr, "err", err)
1192
+
l.Error("failed to call XRPC git.formatPatch", "xrpcerr", xrpcerr, "err", err)
1136
1193
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1137
1194
return
1138
1195
}
1139
-
l.Error("failed to compare", "err", err)
1196
+
l.Error("failed to run format-patch", "err", err)
1140
1197
s.pages.Notice(w, "pull", err.Error())
1141
1198
return
1142
1199
}
1143
-
1144
-
var comparison types.RepoFormatPatchResponse
1145
-
if err := json.Unmarshal(xrpcBytes, &comparison); err != nil {
1146
-
l.Error("failed to decode XRPC compare response", "err", err)
1200
+
if fpOut.Rev2 == nil {
1201
+
l.Error("failed to parse git.formatPatch output", "err", "rev2 is missing")
1147
1202
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1148
1203
return
1149
1204
}
1150
1205
1151
-
sourceRev := comparison.Rev2
1152
-
patch := comparison.FormatPatchRaw
1153
-
combined := comparison.CombinedPatchRaw
1206
+
sourceRev := *fpOut.Rev2
1207
+
patch := fpOut.Patch
1154
1208
1155
1209
if err := s.validator.ValidatePatch(&patch); err != nil {
1156
1210
s.logger.Error("failed to validate patch", "err", err)
···
1162
1216
Branch: sourceBranch,
1163
1217
}
1164
1218
1165
-
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked)
1219
+
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, sourceRev, pullSource, isStacked)
1166
1220
}
1167
1221
1168
1222
func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, title, body, targetBranch, patch string, isStacked bool) {
···
1172
1226
return
1173
1227
}
1174
1228
1175
-
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, "", "", nil, isStacked)
1229
+
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, "", nil, isStacked)
1176
1230
}
1177
1231
1178
1232
func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, forkRepo string, title, body, targetBranch, sourceBranch string, isStacked bool) {
···
1191
1245
return
1192
1246
}
1193
1247
1194
-
client, err := s.oauth.ServiceClient(
1195
-
r,
1196
-
oauth.WithService(fork.Knot),
1197
-
oauth.WithLxm(tangled.RepoHiddenRefNSID),
1198
-
oauth.WithDev(s.config.Core.Dev),
1199
-
)
1200
-
1201
-
resp, err := tangled.RepoHiddenRef(
1202
-
r.Context(),
1203
-
client,
1204
-
&tangled.RepoHiddenRef_Input{
1205
-
ForkRef: sourceBranch,
1206
-
RemoteRef: targetBranch,
1207
-
Repo: fork.RepoAt().String(),
1208
-
},
1209
-
)
1210
-
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1211
-
s.logger.Error("failed to set hidden ref", "xrpcerr", xrpcerr, "err", err)
1212
-
s.pages.Notice(w, "pull", xrpcerr.Error())
1213
-
return
1214
-
}
1215
-
1216
-
if !resp.Success {
1217
-
errorMsg := "Failed to create pull request"
1218
-
if resp.Error != nil {
1219
-
errorMsg = fmt.Sprintf("Failed to create pull request: %s", *resp.Error)
1220
-
}
1221
-
s.pages.Notice(w, "pull", errorMsg)
1222
-
return
1223
-
}
1224
-
1225
-
hiddenRef := fmt.Sprintf("hidden/%s/%s", sourceBranch, targetBranch)
1226
-
// We're now comparing the sourceBranch (on the fork) against the hiddenRef which is tracking
1227
-
// the targetBranch on the target repository. This code is a bit confusing, but here's an example:
1228
-
// hiddenRef: hidden/feature-1/main (on repo-fork)
1229
-
// targetBranch: main (on repo-1)
1230
-
// sourceBranch: feature-1 (on repo-fork)
1231
-
forkScheme := "http"
1232
-
if !s.config.Core.Dev {
1233
-
forkScheme = "https"
1234
-
}
1235
-
forkHost := fmt.Sprintf("%s://%s", forkScheme, fork.Knot)
1236
-
forkXrpcc := &indigoxrpc.Client{
1237
-
Host: forkHost,
1238
-
}
1248
+
xrpcc := &indigoxrpc.Client{Host: s.config.KnotMirror.Url}
1239
1249
1240
-
forkXrpcBytes, err := tangled.RepoCompare(r.Context(), forkXrpcc, fork.RepoIdentifier(), hiddenRef, sourceBranch)
1250
+
fpOut, err := tangled.GitTempFormatPatch(r.Context(), xrpcc, repo.RepoAt().String(), fork.RepoAt().String(), targetBranch, sourceBranch)
1241
1251
if err != nil {
1242
1252
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1243
-
l.Error("failed to call XRPC repo.compare for fork", "xrpcerr", xrpcerr, "err", err, "hidden_ref", hiddenRef)
1253
+
l.Error("failed to call XRPC git.formatPatch", "xrpcerr", xrpcerr, "err", err)
1244
1254
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1245
1255
return
1246
1256
}
1247
-
l.Error("failed to compare across branches", "err", err, "hidden_ref", hiddenRef)
1257
+
l.Error("failed to run format-patch", "err", err)
1248
1258
s.pages.Notice(w, "pull", err.Error())
1249
1259
return
1250
1260
}
1251
-
1252
-
var comparison types.RepoFormatPatchResponse
1253
-
if err := json.Unmarshal(forkXrpcBytes, &comparison); err != nil {
1254
-
l.Error("failed to decode XRPC compare response for fork", "err", err)
1261
+
if fpOut.Rev2 == nil {
1262
+
l.Error("failed to parse git.formatPatch output", "err", "rev2 is missing")
1255
1263
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1256
1264
return
1257
1265
}
1258
1266
1259
-
sourceRev := comparison.Rev2
1260
-
patch := comparison.FormatPatchRaw
1261
-
combined := comparison.CombinedPatchRaw
1267
+
sourceRev := *fpOut.Rev2
1268
+
patch := fpOut.Patch
1262
1269
1263
1270
if err := s.validator.ValidatePatch(&patch); err != nil {
1264
1271
s.logger.Error("failed to validate patch", "err", err)
···
1279
1286
RepoDid: forkDid,
1280
1287
}
1281
1288
1282
-
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked)
1289
+
s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, sourceRev, pullSource, isStacked)
1283
1290
}
1284
1291
1285
1292
func (s *Pulls) createPullRequest(
···
1289
1296
userDid syntax.DID,
1290
1297
title, body, targetBranch string,
1291
1298
patch string,
1292
-
combined string,
1293
1299
sourceRev string,
1294
1300
pullSource *models.PullSource,
1295
1301
isStacked bool,
···
1372
1378
Submissions: []*models.PullSubmission{
1373
1379
{
1374
1380
Patch: patch,
1375
-
Combined: combined,
1376
1381
SourceRev: sourceRev,
1377
1382
Blob: *blob.Blob,
1378
1383
Created: now,
···
1795
1800
1796
1801
patch := r.FormValue("patch")
1797
1802
1798
-
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, "", "")
1803
+
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, "")
1799
1804
}
1800
1805
1801
1806
func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) {
···
1833
1838
return
1834
1839
}
1835
1840
1836
-
scheme := "http"
1837
-
if !s.config.Core.Dev {
1838
-
scheme = "https"
1839
-
}
1840
-
host := fmt.Sprintf("%s://%s", scheme, f.Knot)
1841
-
xrpcc := &indigoxrpc.Client{
1842
-
Host: host,
1843
-
}
1841
+
xrpcc := &indigoxrpc.Client{Host: s.config.KnotMirror.Url}
1844
1842
1845
-
xrpcBytes, err := tangled.RepoCompare(r.Context(), xrpcc, f.RepoIdentifier(), pull.TargetBranch, pull.PullSource.Branch)
1843
+
fpOut, err := tangled.GitTempFormatPatch(r.Context(), xrpcc, f.RepoAt().String(), "", pull.TargetBranch, pull.PullSource.Branch)
1846
1844
if err != nil {
1847
1845
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1848
-
l.Error("failed to call XRPC repo.compare", "xrpcerr", xrpcerr, "err", err, "source_branch", pull.PullSource.Branch)
1849
-
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
1846
+
l.Error("failed to call XRPC git.formatPatch", "xrpcerr", xrpcerr, "err", err, "source_branch", pull.PullSource.Branch)
1847
+
s.pages.Notice(w, "resubmit-error", "Failed to resubmit pull request. Try again later.")
1850
1848
return
1851
1849
}
1852
-
l.Error("compare request failed", "err", err, "source_branch", pull.PullSource.Branch)
1850
+
l.Error("failed to run format-patch", "err", err, "source_branch", pull.PullSource.Branch)
1853
1851
s.pages.Notice(w, "resubmit-error", err.Error())
1854
1852
return
1855
1853
}
1856
-
1857
-
var comparison types.RepoFormatPatchResponse
1858
-
if err := json.Unmarshal(xrpcBytes, &comparison); err != nil {
1859
-
l.Error("failed to decode XRPC compare response", "err", err)
1860
-
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
1854
+
if fpOut.Rev2 == nil {
1855
+
l.Error("failed to parse git.formatPatch output", "err", "rev2 is missing")
1856
+
s.pages.Notice(w, "resubmit-error", "Failed to resubmit pull request. Try again later.")
1861
1857
return
1862
1858
}
1863
1859
1864
-
sourceRev := comparison.Rev2
1865
-
patch := comparison.FormatPatchRaw
1866
-
combined := comparison.CombinedPatchRaw
1860
+
sourceRev := *fpOut.Rev2
1861
+
patch := fpOut.Patch
1867
1862
1868
-
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev)
1863
+
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, sourceRev)
1869
1864
}
1870
1865
1871
1866
func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) {
···
1903
1898
return
1904
1899
}
1905
1900
1906
-
// update the hidden tracking branch to latest
1907
-
client, err := s.oauth.ServiceClient(
1908
-
r,
1909
-
oauth.WithService(forkRepo.Knot),
1910
-
oauth.WithLxm(tangled.RepoHiddenRefNSID),
1911
-
oauth.WithDev(s.config.Core.Dev),
1912
-
)
1913
-
if err != nil {
1914
-
l.Error("failed to connect to knot server", "err", err, "fork_knot", forkRepo.Knot)
1915
-
return
1916
-
}
1917
-
1918
-
resp, err := tangled.RepoHiddenRef(
1919
-
r.Context(),
1920
-
client,
1921
-
&tangled.RepoHiddenRef_Input{
1922
-
ForkRef: pull.PullSource.Branch,
1923
-
RemoteRef: pull.TargetBranch,
1924
-
Repo: forkRepo.RepoAt().String(),
1925
-
},
1926
-
)
1927
-
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1928
-
s.logger.Error("failed to set hidden ref", "xrpcerr", xrpcerr, "err", err)
1929
-
s.pages.Notice(w, "resubmit-error", xrpcerr.Error())
1930
-
return
1931
-
}
1932
-
if !resp.Success {
1933
-
l.Error("failed to update tracking ref", "err", resp.Error, "fork_ref", pull.PullSource.Branch, "remote_ref", pull.TargetBranch)
1934
-
s.pages.Notice(w, "resubmit-error", "Failed to update tracking ref.")
1935
-
return
1936
-
}
1901
+
xrpcc := &indigoxrpc.Client{Host: s.config.KnotMirror.Url}
1937
1902
1938
-
hiddenRef := fmt.Sprintf("hidden/%s/%s", pull.PullSource.Branch, pull.TargetBranch)
1939
-
// extract patch by performing compare
1940
-
forkScheme := "http"
1941
-
if !s.config.Core.Dev {
1942
-
forkScheme = "https"
1943
-
}
1944
-
forkHost := fmt.Sprintf("%s://%s", forkScheme, forkRepo.Knot)
1945
-
forkXrpcBytes, err := tangled.RepoCompare(r.Context(), &indigoxrpc.Client{Host: forkHost}, forkRepo.RepoIdentifier(), hiddenRef, pull.PullSource.Branch)
1903
+
fpOut, err := tangled.GitTempFormatPatch(r.Context(), xrpcc, pull.RepoAt.String(), forkRepo.RepoAt().String(), pull.TargetBranch, pull.PullSource.Branch)
1946
1904
if err != nil {
1947
1905
if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil {
1948
-
l.Error("failed to call XRPC repo.compare for fork", "xrpcerr", xrpcerr, "err", err, "hidden_ref", hiddenRef, "source_branch", pull.PullSource.Branch)
1949
-
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
1906
+
l.Error("failed to call XRPC git.formatPatch", "xrpcerr", xrpcerr, "err", err)
1907
+
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1950
1908
return
1951
1909
}
1952
-
l.Error("failed to compare branches", "err", err, "hidden_ref", hiddenRef, "source_branch", pull.PullSource.Branch)
1953
-
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
1910
+
l.Error("failed to run format-patch", "err", err)
1911
+
s.pages.Notice(w, "pull", err.Error())
1954
1912
return
1955
1913
}
1956
-
1957
-
var forkComparison types.RepoFormatPatchResponse
1958
-
if err := json.Unmarshal(forkXrpcBytes, &forkComparison); err != nil {
1959
-
l.Error("failed to decode XRPC compare response for fork", "err", err)
1960
-
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
1914
+
if fpOut.Rev2 == nil {
1915
+
l.Error("failed to parse git.formatPatch output", "err", "rev2 is missing")
1916
+
s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.")
1961
1917
return
1962
1918
}
1963
1919
1964
-
// Use the fork comparison we already made
1965
-
comparison := forkComparison
1966
-
1967
-
sourceRev := comparison.Rev2
1968
-
patch := comparison.FormatPatchRaw
1969
-
combined := comparison.CombinedPatchRaw
1920
+
sourceRev := *fpOut.Rev2
1921
+
patch := fpOut.Patch
1970
1922
1971
-
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev)
1923
+
s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, sourceRev)
1972
1924
}
1973
1925
1974
1926
func (s *Pulls) resubmitPullHelper(
···
1978
1930
userDid syntax.DID,
1979
1931
pull *models.Pull,
1980
1932
patch string,
1981
-
combined string,
1982
1933
sourceRev string,
1983
1934
) {
1984
1935
l := s.logger.With("handler", "resubmitPullHelper", "user", userDid, "pull_id", pull.PullId, "target_branch", pull.TargetBranch)
···
2012
1963
newRoundNumber := len(pull.Submissions)
2013
1964
newPatch := patch
2014
1965
newSourceRev := sourceRev
2015
-
combinedPatch := combined
2016
1966
2017
1967
client, err := s.oauth.AuthorizedClient(r)
2018
1968
if err != nil {
···
2056
2006
return
2057
2007
}
2058
2008
2059
-
err = db.ResubmitPull(s.db, pullAt, newRoundNumber, newPatch, combinedPatch, newSourceRev, blob.Blob)
2009
+
err = db.ResubmitPull(s.db, pullAt, newRoundNumber, newPatch, newSourceRev, blob.Blob)
2060
2010
if err != nil {
2061
2011
l.Error("failed to resubmit pull request in database", "err", err, "round_number", newRoundNumber)
2062
2012
s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.")
···
2259
2209
pullAt := op.AtUri()
2260
2210
newRoundNumber := len(op.Submissions)
2261
2211
newPatch := np.LatestPatch()
2262
-
combinedPatch := np.LatestSubmission().Combined
2263
2212
newSourceRev := np.LatestSha()
2264
2213
2265
2214
blob, err := xrpc.RepoUploadBlob(r.Context(), client, gz(newPatch), ApplicationGzip)
···
2270
2219
}
2271
2220
2272
2221
// create new round
2273
-
err = db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, combinedPatch, newSourceRev, blob.Blob)
2222
+
err = db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, newSourceRev, blob.Blob)
2274
2223
if err != nil {
2275
2224
l.Error("failed to update pull in database", "err", err, "pull_id", op.PullId, "round_number", newRoundNumber)
2276
2225
s.pages.Notice(w, "pull-resubmit-error", "Failed to resubmit pull request. Try again later.")
···
2643
2592
{
2644
2593
Patch: fp.Raw,
2645
2594
SourceRev: fp.SHA,
2646
-
Combined: fp.Raw,
2647
2595
Blob: *blobs[i],
2648
2596
Created: now,
2649
2597
},
History
1 round
0 comments
boltless.me
submitted
#0
1 commit
expand
collapse
appview: use knotmirror for format-patch & interdiff
Signed-off-by: Seongmin Lee <git@boltless.me>
merge conflicts detected
expand
collapse
expand
collapse
- knotmirror/config/config.go:11
- knotmirror/knotmirror.go:9
- knotmirror/xrpc/xrpc.go:10
- nix/vm.nix:148