From 5e4b7b1fcc0bfbce33e4f30b3e02e22fe850f534 Mon Sep 17 00:00:00 2001 From: William Chargin Date: Wed, 25 Apr 2018 14:35:45 -0700 Subject: [PATCH] Extract repository types to a separate module (#141) Summary: We should be able to get the types without depending on the function to load a Git repo from disk, and in particular without depending on `child_process`. Test Plan: Flow and tests are sufficient. wchargin-branch: extract-repository-types --- src/plugins/git/loadRepository.js | 21 ++------------------- src/plugins/git/types.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 src/plugins/git/types.js diff --git a/src/plugins/git/loadRepository.js b/src/plugins/git/loadRepository.js index 2503cd6..d4477c1 100644 --- a/src/plugins/git/loadRepository.js +++ b/src/plugins/git/loadRepository.js @@ -11,6 +11,8 @@ import {execFileSync} from "child_process"; +import type {Repository, Hash, Commit, Tree, TreeEntry} from "./types"; + export type GitDriver = (args: string[], options?: ExecOptions) => string; type ExecOptions = Object; // close enough export function localGit(repositoryPath: string): GitDriver { @@ -24,25 +26,6 @@ export function localGit(repositoryPath: string): GitDriver { }; } -export type Repository = {| - +commits: Map, - +trees: Map, -|}; -export type Hash = string; -export type Commit = {| - +hash: Hash, - +treeHash: Hash, -|}; -export type Tree = {| - +hash: Hash, - +entries: Map, // map from name -|}; -export type TreeEntry = {| - +type: "blob" | "commit" | "tree", - +name: string, - +hash: Hash, -|}; - /** * Load a Git repository from disk into memory. The `rootRef` should be * a revision reference as accepted by `git rev-parse`: "HEAD" and diff --git a/src/plugins/git/types.js b/src/plugins/git/types.js new file mode 100644 index 0000000..74c0147 --- /dev/null +++ b/src/plugins/git/types.js @@ -0,0 +1,20 @@ +// @flow + +export type Repository = {| + +commits: Map, + +trees: Map, +|}; +export type Hash = string; +export type Commit = {| + +hash: Hash, + +treeHash: Hash, +|}; +export type Tree = {| + +hash: Hash, + +entries: Map, // map from name +|}; +export type TreeEntry = {| + +type: "blob" | "commit" | "tree", + +name: string, + +hash: Hash, +|};