Monorepo for Tangled tangled.org

appview: pulls: bump sourceRev for stacks without causing resubmits

this gets noisy really quickly when the stack is rebased. now, the only
things that can cause a resubmit are: reauthoring commit messages or
modifying the patch itself.

authored by oppi.li and committed by Tangled b3941e39 ca2bb4cd

Changed files
+71 -2
appview
db
state
+25
appview/db/pulls.go
··· 947 return err 948 } 949 950 type PullCount struct { 951 Open int 952 Merged int
··· 947 return err 948 } 949 950 + // Only used when stacking to update contents in the event of a rebase (the interdiff should be empty). 951 + // otherwise submissions are immutable 952 + func UpdatePull(e Execer, newPatch, sourceRev string, filters ...filter) error { 953 + var conditions []string 954 + var args []any 955 + 956 + args = append(args, sourceRev) 957 + args = append(args, newPatch) 958 + 959 + for _, filter := range filters { 960 + conditions = append(conditions, filter.Condition()) 961 + args = append(args, filter.arg) 962 + } 963 + 964 + whereClause := "" 965 + if conditions != nil { 966 + whereClause = " where " + strings.Join(conditions, " and ") 967 + } 968 + 969 + query := fmt.Sprintf("update pull_submissions set source_rev = ?, patch = ? %s", whereClause) 970 + _, err := e.Exec(query, args...) 971 + 972 + return err 973 + } 974 + 975 type PullCount struct { 976 Open int 977 Merged int
+46 -2
appview/state/pull.go
··· 260 latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev 261 } 262 263 if latestSourceRev != result.Branch.Hash { 264 - log.Println(latestSourceRev, result.Branch.Hash) 265 return pages.ShouldResubmit 266 } 267 ··· 1609 patchutil.SortPatch(origFiles) 1610 1611 // text content of patch may be identical, but a jj rebase might have forwarded it 1612 - if patchutil.Equal(newFiles, origFiles) && origHeader.SHA == newHeader.SHA { 1613 unchanged[op.ChangeId] = struct{}{} 1614 } else { 1615 updated[op.ChangeId] = struct{}{} ··· 1683 1684 record := op.AsRecord() 1685 record.Patch = submission.Patch 1686 1687 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 1688 RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{
··· 260 latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev 261 } 262 263 + log.Println(latestSourceRev, result.Branch.Hash) 264 + 265 if latestSourceRev != result.Branch.Hash { 266 return pages.ShouldResubmit 267 } 268 ··· 1610 patchutil.SortPatch(origFiles) 1611 1612 // text content of patch may be identical, but a jj rebase might have forwarded it 1613 + // 1614 + // we still need to update the hash in submission.Patch and submission.SourceRev 1615 + if patchutil.Equal(newFiles, origFiles) && 1616 + origHeader.Title == newHeader.Title && 1617 + origHeader.Body == newHeader.Body { 1618 unchanged[op.ChangeId] = struct{}{} 1619 } else { 1620 updated[op.ChangeId] = struct{}{} ··· 1688 1689 record := op.AsRecord() 1690 record.Patch = submission.Patch 1691 + 1692 + writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 1693 + RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{ 1694 + Collection: tangled.RepoPullNSID, 1695 + Rkey: op.Rkey, 1696 + Value: &lexutil.LexiconTypeDecoder{ 1697 + Val: &record, 1698 + }, 1699 + }, 1700 + }) 1701 + } 1702 + 1703 + // unchanged pulls are edited without starting a new round 1704 + // 1705 + // update source-revs & patches without advancing rounds 1706 + for changeId := range unchanged { 1707 + op, _ := origById[changeId] 1708 + np, _ := newById[changeId] 1709 + 1710 + origSubmission := op.Submissions[op.LastRoundNumber()] 1711 + newSubmission := np.Submissions[np.LastRoundNumber()] 1712 + 1713 + log.Println("moving unchanged change id : ", changeId) 1714 + 1715 + err := db.UpdatePull( 1716 + tx, 1717 + newSubmission.Patch, 1718 + newSubmission.SourceRev, 1719 + db.FilterEq("id", origSubmission.ID), 1720 + ) 1721 + 1722 + if err != nil { 1723 + log.Println("failed to update pull", err, op.PullId) 1724 + s.pages.Notice(w, "pull-resubmit-error", "Failed to resubmit pull request. Try again later.") 1725 + return 1726 + } 1727 + 1728 + record := op.AsRecord() 1729 + record.Patch = newSubmission.Patch 1730 1731 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 1732 RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{