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
This commit is contained in:
William Chargin 2018-04-25 14:35:45 -07:00 committed by GitHub
parent ad56ba087c
commit 5e4b7b1fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 19 deletions

View File

@ -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<Hash, Commit>,
+trees: Map<Hash, Tree>,
|};
export type Hash = string;
export type Commit = {|
+hash: Hash,
+treeHash: Hash,
|};
export type Tree = {|
+hash: Hash,
+entries: Map<string, TreeEntry>, // 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

20
src/plugins/git/types.js Normal file
View File

@ -0,0 +1,20 @@
// @flow
export type Repository = {|
+commits: Map<Hash, Commit>,
+trees: Map<Hash, Tree>,
|};
export type Hash = string;
export type Commit = {|
+hash: Hash,
+treeHash: Hash,
|};
export type Tree = {|
+hash: Hash,
+entries: Map<string, TreeEntry>, // map from name
|};
export type TreeEntry = {|
+type: "blob" | "commit" | "tree",
+name: string,
+hash: Hash,
|};