Let gitea_commit take a large patch from a hash-checked spool file (issue 852)
mesh/merge-gate head d4b8b2470159 merged into trunk aee97bf8ad42 — pass: builds gitea → novox; no bus step; every machine composes with the change as it di…
mesh/repo-check head d4b8b2470159 merged into trunk aee97bf8ad42 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
mesh/merge-gate head d4b8b2470159 merged into trunk aee97bf8ad42 — pass: builds gitea → novox; no bus step; every machine composes with the change as it di…
mesh/repo-check head d4b8b2470159 merged into trunk aee97bf8ad42 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
A feature's diff is megabytes, too large to type into a call. gitea_commit now also takes patch_file, the random hex name of a file in the module's spool directory /var/lib/mesh/forge-patches (mode 0733, owned by the machine's account), with patch_sha256. The tool reads only that directory, never through a symlink or a hard link, refuses a file whose SHA-256 differs, applies it as it applies patch, and removes it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,11 @@ type CommitAsk struct {
|
||||
Message string
|
||||
Files []FileChange
|
||||
Patch string // a unified diff, as git diff writes it, instead of Files
|
||||
// PatchFile is the name of a file in the spool directory holding the patch (novox/hq issue 852), with the
|
||||
// SHA-256 its caller says it has; commitAsk reads it into Patch.
|
||||
PatchFile string
|
||||
PatchSHA256 string
|
||||
patchFileGiven bool
|
||||
}
|
||||
|
||||
// Committed is what gitea_commit made.
|
||||
@@ -69,6 +74,11 @@ func readCommitAsk(args map[string]any) (CommitAsk, error) {
|
||||
a := CommitAsk{Owner: text(args, "owner"), Repo: text(args, "repo"), Branch: text(args, "branch"),
|
||||
Base: text(args, "base"), Message: strings.TrimSpace(raw(args, "message"))}
|
||||
a.Patch = raw(args, "patch")
|
||||
if v, ok := args["patch_file"]; ok && v != nil {
|
||||
a.patchFileGiven = true
|
||||
a.PatchFile = raw(args, "patch_file")
|
||||
}
|
||||
a.PatchSHA256 = strings.ToLower(strings.TrimSpace(raw(args, "patch_sha256")))
|
||||
if a.Branch == "" {
|
||||
return a, refuse("branch is required: the branch the commit goes on, a branch of its own (created from base when absent). Nothing was sent")
|
||||
}
|
||||
@@ -111,11 +121,23 @@ func readCommitAsk(args map[string]any) (CommitAsk, error) {
|
||||
a.Files = append(a.Files, fc)
|
||||
}
|
||||
}
|
||||
sources := 0
|
||||
for _, g := range []bool{len(a.Files) > 0, strings.TrimSpace(a.Patch) != "", a.patchFileGiven} {
|
||||
if g {
|
||||
sources++
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case len(a.Files) == 0 && strings.TrimSpace(a.Patch) == "":
|
||||
return a, refuse("give files (each {path, content | content_base64 | delete: true}) or patch (a unified diff, as git diff writes it). Nothing was sent")
|
||||
case len(a.Files) > 0 && strings.TrimSpace(a.Patch) != "":
|
||||
return a, refuse("give files or patch, not both: one commit carries one of them. Nothing was sent")
|
||||
case sources == 0:
|
||||
return a, refuse("give files (each {path, content | content_base64 | delete: true}), patch (a unified diff, as git diff writes it) or patch_file (the name of a patch in the spool directory). Nothing was sent")
|
||||
case sources > 1:
|
||||
return a, refuse("give files, patch or patch_file, not more than one: one commit carries one of them. Nothing was sent")
|
||||
case a.PatchSHA256 != "" && !a.patchFileGiven:
|
||||
return a, refuse("patch_sha256 goes with patch_file only. Nothing was sent")
|
||||
case a.patchFileGiven:
|
||||
if err := checkPatchFileAsk(a); err != nil {
|
||||
return a, err
|
||||
}
|
||||
case len(a.Files) > maxFiles:
|
||||
return a, refuse("%d files is more than the %d one commit carries. Nothing was sent", len(a.Files), maxFiles)
|
||||
case len(a.Patch) > maxPatchBytes:
|
||||
@@ -134,13 +156,13 @@ func readCommitAsk(args map[string]any) (CommitAsk, error) {
|
||||
return a, refuse("%s is named twice in files. Nothing was sent", fc.Path)
|
||||
}
|
||||
seen[fc.Path] = true
|
||||
given := 0
|
||||
have := 0
|
||||
for _, g := range []bool{fc.Content != nil, fc.ContentBase64 != nil, fc.Delete} {
|
||||
if g {
|
||||
given++
|
||||
have++
|
||||
}
|
||||
}
|
||||
if given != 1 {
|
||||
if have != 1 {
|
||||
return a, refuse("files[%d] (%s) needs exactly one of content, content_base64 or delete: true. Nothing was sent", i, fc.Path)
|
||||
}
|
||||
if fc.Content != nil && !utf8.ValidString(*fc.Content) {
|
||||
|
||||
Reference in New Issue
Block a user