-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow revision #45
Open
MichaelXavier
wants to merge
13
commits into
purescript:master
Choose a base branch
from
Soostone:allow-revision
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Allow revision #45
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e761abb
First stab at allowing branch, tag or SHA
MichaelXavier aff276f
Quieter output
MichaelXavier 159343d
Set cloned repo so it can fetch any rev/tag
MichaelXavier 1075cdb
Merge branch 'upstream-master' into allow-revision
MichaelXavier 9d5c6f7
Implement new cloning logic
MichaelXavier b313d07
Merge branch 'upstream-master' into allow-revision
MichaelXavier 2da6fb4
Indent wheres
MichaelXavier 4c81122
Remove redundancy
MichaelXavier b69be29
Use --heads --tags --refs in ls-remote
MichaelXavier cb46cce
Switch to offline clone target type inference
MichaelXavier 71c8a53
Remove // from reference parsing
MichaelXavier a5d4df3
Update clone target parser's shema parsing
MichaelXavier cd86c43
Merge remote-tracking branch 'upstream/master' into allow-revision
MichaelXavier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ data PackageConfig = PackageConfig | |
{ name :: PackageName | ||
, depends :: [PackageName] | ||
, set :: Text | ||
, source :: Text | ||
, source :: Repo | ||
} deriving (Show, Generic, Aeson.FromJSON, Aeson.ToJSON) | ||
|
||
pathToTextUnsafe :: Turtle.FilePath -> Text | ||
|
@@ -96,49 +96,97 @@ writePackageFile = | |
. packageConfigToJSON | ||
|
||
data PackageInfo = PackageInfo | ||
{ repo :: Text | ||
{ repo :: Repo | ||
, version :: Text | ||
, dependencies :: [PackageName] | ||
} deriving (Show, Eq, Generic, Aeson.FromJSON, Aeson.ToJSON) | ||
|
||
type PackageSet = Map.Map PackageName PackageInfo | ||
|
||
cloneShallow | ||
newtype Repo = Repo { unRepo :: Text } deriving (Show, Eq) | ||
|
||
instance Aeson.FromJSON Repo where | ||
parseJSON = fmap Repo . Aeson.parseJSON | ||
|
||
|
||
instance Aeson.ToJSON Repo where | ||
toJSON = Aeson.toJSON . unRepo | ||
|
||
|
||
data CloneTarget = CloneTag Text | ||
| CloneSHA Text | ||
deriving (Show) | ||
|
||
|
||
-- | Parses "sha:somesha", "tag:sometag", and "sometag" without a | ||
-- schema as a tag. | ||
parseCloneTarget | ||
:: Text | ||
-> Either Text CloneTarget | ||
parseCloneTarget t = | ||
if T.null remainder | ||
then Right (CloneTag t) | ||
else case T.toLower schemeName of | ||
"sha" -> Right (CloneSHA withoutScheme) | ||
"tag" -> Right (CloneTag withoutScheme) | ||
_ -> Left ("Invalid scheme. Expected sha: | tag: but got " <> schemeName) | ||
where | ||
(schemeName, remainder) = T.breakOn ":" t | ||
withoutScheme = T.drop 1 remainder | ||
|
||
|
||
-- Both tags and SHAs can be treated as immutable so we only have to run this once | ||
cloneShallow | ||
:: Repo | ||
-- ^ repo | ||
-> Text | ||
-- ^ branch/tag | ||
-> CloneTarget | ||
-- ^ tag/SHA | ||
-> Turtle.FilePath | ||
-- ^ target directory | ||
-> IO ExitCode | ||
cloneShallow from ref into = | ||
proc "git" | ||
[ "clone" | ||
, "-q" | ||
, "-c", "advice.detachedHead=false" | ||
, "--depth", "1" | ||
, "-b", ref | ||
, from | ||
, pathToTextUnsafe into | ||
] empty .||. exit (ExitFailure 1) | ||
-> IO () | ||
cloneShallow (Repo from) tgt into = do | ||
void $ proc "git" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I try this with a SHA hash, I get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we confirm this works by now? |
||
[ "clone" | ||
, "-q" | ||
, "-c", "advice.detachedHead=false" | ||
, "--no-checkout" | ||
, "-b", tgtText | ||
, from | ||
, pathToTextUnsafe into | ||
] empty .||. exit (ExitFailure 1) | ||
case tgt of | ||
CloneSHA sha -> | ||
inGitRepo $ void $ proc "git" | ||
[ "checkout" | ||
, "-q" | ||
, "-c", "advice.detachedHead=false" | ||
, "--no-checkout" | ||
, sha | ||
] empty .||. exit (ExitFailure 1) | ||
CloneTag _ -> return () | ||
where | ||
inGitRepo m = sh (pushd into >> m) | ||
tgtText = case tgt of | ||
CloneTag t -> t | ||
CloneSHA t -> t | ||
|
||
listRemoteTags | ||
:: Text | ||
:: Repo | ||
-- ^ repo | ||
-> Turtle.Shell Text | ||
listRemoteTags from = let gitProc = inproc "git" | ||
[ "ls-remote" | ||
, "-q" | ||
, "-t" | ||
, from | ||
] empty | ||
in lineToText <$> gitProc | ||
listRemoteTags (Repo from) = let gitProc = inproc "git" | ||
[ "ls-remote" | ||
, "-q" | ||
, "-t" | ||
, from | ||
] empty | ||
in lineToText <$> gitProc | ||
|
||
getPackageSet :: PackageConfig -> IO () | ||
getPackageSet PackageConfig{ source, set } = do | ||
let pkgDir = ".psc-package" </> fromText set </> ".set" | ||
exists <- testdir pkgDir | ||
unless exists . void $ cloneShallow source set pkgDir | ||
unless exists . void $ cloneShallow source (CloneTag set) pkgDir | ||
|
||
readPackageSet :: PackageConfig -> IO PackageSet | ||
readPackageSet PackageConfig{ set } = do | ||
|
@@ -158,11 +206,13 @@ writePackageSet PackageConfig{ set } = | |
installOrUpdate :: Text -> PackageName -> PackageInfo -> IO Turtle.FilePath | ||
installOrUpdate set pkgName PackageInfo{ repo, version } = do | ||
let pkgDir = ".psc-package" </> fromText set </> fromText (runPackageName pkgName) </> fromText version | ||
exists <- testdir pkgDir | ||
unless exists . void $ do | ||
echoT ("Updating " <> runPackageName pkgName) | ||
cloneShallow repo version pkgDir | ||
pure pkgDir | ||
echoT ("Updating " <> runPackageName pkgName) | ||
case parseCloneTarget version of | ||
Left parseError -> exitWithErr parseError | ||
Right target -> do | ||
exists <- testdir pkgDir | ||
unless exists . void $ cloneShallow repo target pkgDir | ||
pure pkgDir | ||
|
||
getTransitiveDeps :: PackageSet -> [PackageName] -> IO [(PackageName, PackageInfo)] | ||
getTransitiveDeps db deps = | ||
|
@@ -198,7 +248,7 @@ getPureScriptVersion = do | |
| otherwise -> exitWithErr "Unable to parse output of purs --version" | ||
_ -> exitWithErr "Unexpected output from purs --version" | ||
|
||
initialize :: Maybe (Text, Maybe Text) -> IO () | ||
initialize :: Maybe (Text, Maybe Repo) -> IO () | ||
initialize setAndSource = do | ||
exists <- testfile "psc-package.json" | ||
when exists $ exitWithErr "psc-package.json already exists" | ||
|
@@ -212,13 +262,13 @@ initialize setAndSource = do | |
echoT "(Use --source / --set to override this behavior)" | ||
pure PackageConfig { name = pkgName | ||
, depends = [ preludePackageName ] | ||
, source = "https://github.com/purescript/package-sets.git" | ||
, source = Repo "https://github.com/purescript/package-sets.git" | ||
, set = "psc-" <> pack (showVersion pursVersion) | ||
} | ||
Just (set, source) -> | ||
pure PackageConfig { name = pkgName | ||
, depends = [ preludePackageName ] | ||
, source = fromMaybe "https://github.com/purescript/package-sets.git" source | ||
, source = fromMaybe (Repo "https://github.com/purescript/package-sets.git") source | ||
, set | ||
} | ||
|
||
|
@@ -276,17 +326,17 @@ listPackages sorted = do | |
then traverse_ echoT (fmt <$> inOrder (Map.assocs db)) | ||
else traverse_ echoT (fmt <$> Map.assocs db) | ||
where | ||
fmt :: (PackageName, PackageInfo) -> Text | ||
fmt (name, PackageInfo{ version, repo }) = | ||
runPackageName name <> " (" <> version <> ", " <> repo <> ")" | ||
|
||
inOrder xs = fromNode . fromVertex <$> vs where | ||
(gr, fromVertex) = | ||
G.graphFromEdges' [ (pkg, name, dependencies pkg) | ||
| (name, pkg) <- xs | ||
] | ||
vs = G.topSort (G.transposeG gr) | ||
fromNode (pkg, name, _) = (name, pkg) | ||
fmt :: (PackageName, PackageInfo) -> Text | ||
fmt (name, PackageInfo{ version, repo }) = | ||
runPackageName name <> " (" <> version <> ", " <> unRepo repo <> ")" | ||
|
||
inOrder xs = fromNode . fromVertex <$> vs where | ||
(gr, fromVertex) = | ||
G.graphFromEdges' [ (pkg, name, dependencies pkg) | ||
| (name, pkg) <- xs | ||
] | ||
vs = G.topSort (G.transposeG gr) | ||
fromNode (pkg, name, _) = (name, pkg) | ||
|
||
getSourcePaths :: PackageConfig -> PackageSet -> [PackageName] -> IO [Turtle.FilePath] | ||
getSourcePaths PackageConfig{..} db pkgNames = do | ||
|
@@ -455,7 +505,7 @@ main = do | |
commands = (Opts.subparser . fold) | ||
[ Opts.command "init" | ||
(Opts.info (initialize <$> optional ((,) <$> (fromString <$> set) | ||
<*> optional (fromString <$> source)) | ||
<*> optional (Repo . fromString <$> source)) | ||
Opts.<**> Opts.helper) | ||
(Opts.progDesc "Initialize a new package")) | ||
, Opts.command "update" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should probably allow using tags by default and warn about it. Thoughts? cc @kritzcreek
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused. I could see adding a case for
"" -> Right (CloneTag withoutScheme)
. But if they affirmatively provided a scheme that's some unknown, it seems like we should still error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've read all of the code instead of just this bit :D I see now that we only hit this case if the target contained a
:
in the first place.