aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama/models
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:10 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitf8c9e7fff564667700c3dbc239d55db8fcd032a6 (patch)
tree2fbe2e87ed8e713e119aaadf0f2e317fb01d90fc /lib/pama/models
parentcfcab6c5c883a08afa3a56c11e4f48d9725be2a0 (diff)
downloadaerc-f8c9e7fff564667700c3dbc239d55db8fcd032a6.tar.gz
patch: implement worktree support
Implement worktree support for the patch management. Use ":patch apply -w <commit-ish> <tag>" to create a new worktree and apply the selected messages to it. The worktree is linked to repo in the current project. Internally, the worktree is stored as a new project. When this project is deleted with ":patch delete", the underlying linked worktree is removed as well. ":patch list" shows when a project is a worktree and to what project it is linked to. Worktrees enable the users to create a new copy of the repo at a given commit and apply patches without interrupting the current work in the base repo. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/models')
-rw-r--r--lib/pama/models/models.go20
-rw-r--r--lib/pama/models/view.go20
2 files changed, 32 insertions, 8 deletions
diff --git a/lib/pama/models/models.go b/lib/pama/models/models.go
index 1c098885..9b21f0f5 100644
--- a/lib/pama/models/models.go
+++ b/lib/pama/models/models.go
@@ -20,6 +20,15 @@ type Commit struct {
Tag string
}
+// WorktreeParent stores the name and repo location for the base project in the
+// linked worktree project.
+type WorktreeParent struct {
+ // Name is the project name from the base repo.
+ Name string
+ // Root is the root directory of the base repo.
+ Root string
+}
+
// Project contains the data to access a revision control system and to store
// the internal patch tracking data.
type Project struct {
@@ -30,6 +39,9 @@ type Project struct {
Root string
// RevctrlID stores the ID for the revision control system.
RevctrlID string
+ // Worktree keeps the base repo information. If Worktree.Name and
+ // Worktree.Root are not zero, this project contains a linked worktree.
+ Worktree WorktreeParent
// Base represents the reference (base) commit.
Base Commit
// Commits contains the commits that are being tracked. The slice can
@@ -64,6 +76,12 @@ type RevisionController interface {
// ApplyCmd returns a string with an executable command that is used to
// apply patches with the :pipe command.
ApplyCmd() string
+ // CreateWorktree creats a worktree in path at commit.
+ CreateWorktree(path string, commit string) error
+ // DeleteWorktree removes the linked worktree stored in the path
+ // location. Note that this function should be called from the base
+ // repo.
+ DeleteWorktree(path string) error
}
// PersistentStorer is an interface to a persistent storage for Project structs.
@@ -81,6 +99,8 @@ type PersistentStorer interface {
Current() (Project, error)
// Names returns a slice of Project.Name for all stored projects.
Names() ([]string, error)
+ // Project returns the stored project for the provided name.
+ Project(string) (Project, error)
// Projects returns all stored projects.
Projects() ([]Project, error)
}
diff --git a/lib/pama/models/view.go b/lib/pama/models/view.go
index 093ca6f0..6a5b6bd4 100644
--- a/lib/pama/models/view.go
+++ b/lib/pama/models/view.go
@@ -10,7 +10,7 @@ import (
)
var templateText = `
-Project {{.Name}} {{if .IsActive}}[active]{{end}}
+Project {{.Name}} {{if .IsActive}}[active]{{end}} {{if .IsWorktree}}[Linked worktree to {{.WorktreeParent}}]{{end}}
Directory {{.Root}}
Base {{with .Base.ID}}{{if ge (len .) 40}}{{printf "%-6.6s" .}}{{else}}{{.}}{{end}}{{end}}
{{$notes := .Notes}}{{$commits := .Commits}}
@@ -37,17 +37,21 @@ type view struct {
// the key and the annotation is the value.
Notes map[string]string
// IsActive is true if the current project is selected.
- IsActive bool
+ IsActive bool
+ IsWorktree bool
+ WorktreeParent string
}
func newView(p Project, active bool, notes map[string]string) view {
v := view{
- Name: p.Name,
- Root: p.Root,
- Base: p.Base,
- Commits: make(map[string][]Commit),
- Notes: notes,
- IsActive: active,
+ Name: p.Name,
+ Root: p.Root,
+ Base: p.Base,
+ Commits: make(map[string][]Commit),
+ Notes: notes,
+ IsActive: active,
+ IsWorktree: p.Worktree.Root != "" && p.Worktree.Name != "",
+ WorktreeParent: p.Worktree.Name,
}
for _, commit := range p.Commits {