diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-06 09:26:46 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-06 09:27:53 +0800 |
commit | da1d8f4e7c332c7109427915e6459b10209cedce (patch) | |
tree | 280b921be3b51f93d82d916b4eaa89387b7102cc /internal/oldgit/patch.go | |
parent | git2c, git2d: Rename cmd1 and cmd2 descriptively (diff) | |
download | forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.gz forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.zst forge-da1d8f4e7c332c7109427915e6459b10209cedce.zip |
Move the Go stuff to ./forged/v0.1.32
Diffstat (limited to 'internal/oldgit/patch.go')
-rw-r--r-- | internal/oldgit/patch.go | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/internal/oldgit/patch.go b/internal/oldgit/patch.go deleted file mode 100644 index 30bf8e8..0000000 --- a/internal/oldgit/patch.go +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package oldgit - -import ( - "errors" - - "github.com/go-git/go-git/v5/plumbing" - "github.com/go-git/go-git/v5/plumbing/object" -) - -// CommitToPatch creates an [object.Patch] from the first parent of a given -// [object.Commit]. -// -// TODO: This function should be deprecated as it only diffs with the first -// parent and does not correctly handle merge commits. -func CommitToPatch(commit *object.Commit) (parentCommitHash plumbing.Hash, patch *object.Patch, err error) { - var parentCommit *object.Commit - var commitTree *object.Tree - - parentCommit, err = commit.Parent(0) - switch { - case errors.Is(err, object.ErrParentNotFound): - if commitTree, err = commit.Tree(); err != nil { - return - } - if patch, err = NullTree.Patch(commitTree); err != nil { - return - } - case err != nil: - return - default: - parentCommitHash = parentCommit.Hash - if patch, err = parentCommit.Patch(commit); err != nil { - return - } - } - return -} - -var NullTree object.Tree //nolint:gochecknoglobals |