| 1 |
package models |
| 2 |
|
| 3 |
// Commit represents a commit object in a revision control system. |
| 4 |
type Commit struct { |
| 5 |
// ID is the commit hash. |
| 6 |
ID string |
| 7 |
// Subject is the subject line of the commit. |
| 8 |
Subject string |
| 9 |
// Author is the author's name. |
| 10 |
Author string |
| 11 |
// Date associated with the given commit. |
| 12 |
Date string |
| 13 |
// MessageId is the message id for the message that contains the commit |
| 14 |
// diff. This field is only set when commits were applied via patch |
| 15 |
// apply system. |
| 16 |
MessageId string |
| 17 |
// Tag is a user label that is assigned to one or multiple commits. It |
| 18 |
// creates a logical connection between a group of commits to represent |
| 19 |
// a patch set. |
| 20 |
Tag string |
| 21 |
} |
| 22 |
|
| 23 |
// WorktreeParent stores the name and repo location for the base project in the |
| 24 |
// linked worktree project. |
| 25 |
type WorktreeParent struct { |
| 26 |
// Name is the project name from the base repo. |
| 27 |
Name string |
| 28 |
// Root is the root directory of the base repo. |
| 29 |
Root string |
| 30 |
} |
| 31 |
|
| 32 |
// Project contains the data to access a revision control system and to store |
| 33 |
// the internal patch tracking data. |
| 34 |
type Project struct { |
| 35 |
// Name is the project name and works as the project ID. Do not change |
| 36 |
// it. |
| 37 |
Name string |
| 38 |
// Root represents the root directory of the revision control system. |
| 39 |
Root string |
| 40 |
// RevctrlID stores the ID for the revision control system. |
| 41 |
RevctrlID string |
| 42 |
// Worktree keeps the base repo information. If Worktree.Name and |
| 43 |
// Worktree.Root are not zero, this project contains a linked worktree. |
| 44 |
Worktree WorktreeParent |
| 45 |
// Base represents the reference (base) commit. |
| 46 |
Base Commit |
| 47 |
// Commits contains the commits that are being tracked. The slice can |
| 48 |
// contain any commit between the Base commit and HEAD. These commits |
| 49 |
// will be updated by an applying, removing or rebase operation. |
| 50 |
Commits []Commit |
| 51 |
} |
| 52 |
|
| 53 |
// RevisionController is an interface to a revision control system. |
| 54 |
type RevisionController interface { |
| 55 |
// Returns the commit hash of the HEAD commit. |
| 56 |
Head() (string, error) |
| 57 |
// History accepts a commit hash and returns a list of commit hashes |
| 58 |
// between the provided hash and HEAD. The order of the returned slice |
| 59 |
// is important. The commit hashes should be ordered from "earlier" to |
| 60 |
// "later" where the last element must be HEAD. |
| 61 |
History(string) ([]string, error) |
| 62 |
// Clean returns true if there are no unstaged changes. If there are |
| 63 |
// unstaged changes, applying and removing patches will not work. |
| 64 |
Clean() bool |
| 65 |
// Exists returns true if the commit hash exists in the commit history. |
| 66 |
Exists(string) bool |
| 67 |
// Subject returns the subject line for the provided commit hash. |
| 68 |
Subject(string) string |
| 69 |
// Author returns the author for the provided commit hash. |
| 70 |
Author(string) string |
| 71 |
// Date returns the date for the provided commit hash. |
| 72 |
Date(string) string |
| 73 |
// Drop removes the commit with the provided commit hash from the |
| 74 |
// repository. |
| 75 |
Drop(string) error |
| 76 |
// ApplyCmd returns a string with an executable command that is used to |
| 77 |
// apply patches with the :pipe command. |
| 78 |
ApplyCmd() string |
| 79 |
// CreateWorktree creates a worktree in path at commit. |
| 80 |
CreateWorktree(path string, commit string) error |
| 81 |
// DeleteWorktree removes the linked worktree stored in the path |
| 82 |
// location. Note that this function should be called from the base |
| 83 |
// repo. |
| 84 |
DeleteWorktree(path string) error |
| 85 |
} |
| 86 |
|
| 87 |
// PersistentStorer is an interface to a persistent storage for Project structs. |
| 88 |
type PersistentStorer interface { |
| 89 |
// StoreProject saves the project data persistently. If overwrite is |
| 90 |
// true, it will write over existing data. |
| 91 |
StoreProject(Project, bool) error |
| 92 |
// DeleteProject removes the project data from the store. |
| 93 |
DeleteProject(string) error |
| 94 |
// CurrentName returns the Project.Name for the active project. |
| 95 |
CurrentName() (string, error) |
| 96 |
// SetCurrent stores a Project.Name and make that project active. |
| 97 |
SetCurrent(string) error |
| 98 |
// Current returns the project data for the active project. |
| 99 |
Current() (Project, error) |
| 100 |
// Names returns a slice of Project.Name for all stored projects. |
| 101 |
Names() ([]string, error) |
| 102 |
// Project returns the stored project for the provided name. |
| 103 |
Project(string) (Project, error) |
| 104 |
// Projects returns all stored projects. |
| 105 |
Projects() ([]Project, error) |
| 106 |
} |