aboutsummaryrefslogtreecommitdiff
path: root/git_format_patch.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 01:30:02 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 01:30:02 +0800
commit7b7e20e60c1c6b858ae0c4eb78d414912263642f (patch)
tree988bc0a39e142dcfd52af98ec65e11578474002c /git_format_patch.go
parentirc: Factor the IRC stuff into its own package (diff)
downloadforge-7b7e20e60c1c6b858ae0c4eb78d414912263642f.tar.gz
forge-7b7e20e60c1c6b858ae0c4eb78d414912263642f.tar.zst
forge-7b7e20e60c1c6b858ae0c4eb78d414912263642f.zip
oldgit: Separate some go-git stuff into here
Diffstat (limited to 'git_format_patch.go')
-rw-r--r--git_format_patch.go56
1 files changed, 0 insertions, 56 deletions
diff --git a/git_format_patch.go b/git_format_patch.go
deleted file mode 100644
index 5628ce1..0000000
--- a/git_format_patch.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
-
-package forge
-
-import (
- "bytes"
- "fmt"
- "strings"
- "time"
-
- "github.com/go-git/go-git/v5/plumbing/object"
-)
-
-// fmtCommitPatch formats a commit object as if it was returned by
-// git-format-patch.
-func fmtCommitPatch(commit *object.Commit) (final string, err error) {
- var patch *object.Patch
- var buf bytes.Buffer
- var author object.Signature
- var date string
- var commitTitle, commitDetails string
-
- if _, patch, err = commitToPatch(commit); err != nil {
- return "", err
- }
-
- author = commit.Author
- date = author.When.Format(time.RFC1123Z)
-
- commitTitle, commitDetails, _ = strings.Cut(commit.Message, "\n")
-
- // This date is hardcoded in Git.
- fmt.Fprintf(&buf, "From %s Mon Sep 17 00:00:00 2001\n", commit.Hash)
- fmt.Fprintf(&buf, "From: %s <%s>\n", author.Name, author.Email)
- fmt.Fprintf(&buf, "Date: %s\n", date)
- fmt.Fprintf(&buf, "Subject: [PATCH] %s\n\n", commitTitle)
-
- if commitDetails != "" {
- commitDetails1, commitDetails2, _ := strings.Cut(commitDetails, "\n")
- if strings.TrimSpace(commitDetails1) == "" {
- commitDetails = commitDetails2
- }
- buf.WriteString(commitDetails)
- buf.WriteString("\n")
- }
- buf.WriteString("---\n")
- fmt.Fprint(&buf, patch.Stats().String())
- fmt.Fprintln(&buf)
-
- buf.WriteString(patch.String())
-
- fmt.Fprintf(&buf, "\n-- \n2.48.1\n")
-
- return buf.String(), nil
-}