diff --git a/src/v3/plugins/git/types.js b/src/v3/plugins/git/types.js index 028a861..820b4d0 100644 --- a/src/v3/plugins/git/types.js +++ b/src/v3/plugins/git/types.js @@ -1,10 +1,5 @@ // @flow -import stringify from "json-stable-stringify"; - -export const GIT_PLUGIN_NAME = "sourcecred/git-beta"; - -// Logical types export type Repository = {| +commits: {[Hash]: Commit}, +trees: {[Hash]: Tree}, @@ -25,127 +20,3 @@ export type TreeEntry = {| +name: string, +hash: Hash, |}; - -// Graph types - -// Nodes -export const COMMIT_NODE_TYPE: "COMMIT" = "COMMIT"; -export type CommitNodePayload = {||}; - -export const TREE_NODE_TYPE: "TREE" = "TREE"; -export type TreeNodePayload = {||}; - -export const BLOB_NODE_TYPE: "BLOB" = "BLOB"; -export type BlobNodePayload = {||}; // we do not store the content - -// In Git, a tree may point to a commit directly; in our graph, we have -// an explicit notion of "submodule commit", because, a priori, we do -// not know the repository to which the commit belongs. A submodule -// commit node stores the hash of the referent commit, as well as the -// URL to the subproject as listed in the .gitmodules file. -export const SUBMODULE_COMMIT_NODE_TYPE: "SUBMODULE_COMMIT" = - "SUBMODULE_COMMIT"; -export function submoduleCommitId(hash: Hash, submoduleUrl: string) { - return `${submoduleUrl}@${hash}`; -} -export type SubmoduleCommitPayload = {| - +hash: Hash, - +url: string, // from .gitmodules file -|}; - -export const TREE_ENTRY_NODE_TYPE: "TREE_ENTRY" = "TREE_ENTRY"; -export type TreeEntryNodePayload = {| - +name: string, -|}; -export function treeEntryId(tree: Hash, name: string): string { - return `${tree}:${name}`; -} - -export type NodePayload = - | BlobNodePayload - | CommitNodePayload - | SubmoduleCommitPayload - | TreeEntryNodePayload - | TreeNodePayload; - -export type NodeType = - | typeof BLOB_NODE_TYPE - | typeof COMMIT_NODE_TYPE - | typeof SUBMODULE_COMMIT_NODE_TYPE - | typeof TREE_ENTRY_NODE_TYPE - | typeof TREE_NODE_TYPE; - -// Edges - -// CommitNode -> CommitNode -export const HAS_PARENT_EDGE_TYPE: "HAS_PARENT" = "HAS_PARENT"; -export type HasParentEdgePayload = {| - +parentIndex: number, // one-based -|}; -export function hasParentEdgeId( - childCommitHash: Hash, - oneBasedParentIndex: number -) { - if ( - !isFinite(oneBasedParentIndex) || - oneBasedParentIndex !== Math.floor(oneBasedParentIndex) || - oneBasedParentIndex < 1 - ) { - throw new Error( - "Expected positive integer parent index, " + - `but got: ${String(oneBasedParentIndex)}` - ); - } - return `${childCommitHash}^${String(oneBasedParentIndex)}`; -} - -// CommitNode -> TreeNode -export const HAS_TREE_EDGE_TYPE: "HAS_TREE" = "HAS_TREE"; -export type HasTreeEdgePayload = {||}; - -// TreeNode -> TreeEntryNode -export const INCLUDES_EDGE_TYPE: "INCLUDES" = "INCLUDES"; -export type IncludesEdgePayload = {| - +name: string, -|}; -export function includesEdgeId(treeSha: string, name: string): string { - return `${treeSha}:${name}`; -} - -// TreeEntryNode -> TreeEntryNode -// TODO: Rename the BECOMES edges to EVOLVES, as then we can cleanly express -// the bidrectional relationship: EvolvesTo and EvolvesFrom. Note that doing -// so is a breaking change, and thus this change should be made after we have a -// versioning system that can either maintain backcompat or invalidate old -// serializations. See #280 -export const BECOMES_EDGE_TYPE: "BECOMES" = "BECOMES"; -export type BecomesEdgePayload = {| - +childCommit: Hash, - +parentCommit: Hash, - +path: $ReadOnlyArray, -|}; -export function becomesEdgeId( - childCommit: Hash, - parentCommit: Hash, - path: $ReadOnlyArray -) { - return stringify({childCommit, parentCommit, path}); -} - -// TreeEntryNode -> BlobNode | TreeNode -export const HAS_CONTENTS_EDGE_TYPE: "HAS_CONTENTS" = "HAS_CONTENTS"; -export type HasContentsEdgePayload = {||}; - -export type EdgeType = - | typeof HAS_TREE_EDGE_TYPE - | typeof HAS_PARENT_EDGE_TYPE - | typeof INCLUDES_EDGE_TYPE - | typeof BECOMES_EDGE_TYPE - | typeof HAS_CONTENTS_EDGE_TYPE; - -export type EdgePayload = - | HasTreeEdgePayload - | HasParentEdgePayload - | IncludesEdgePayload - | BecomesEdgePayload - | HasContentsEdgePayload;