Skip to content

Commit

Permalink
Remove unnecessary code&&adjust indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Nov 24, 2017
1 parent d14a884 commit 5109296
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Source/CarthageKit/Algorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public func topologicalSort<Node: Comparable>(_ graph: [Node: Set<Node>], nodes:

/// Returns the set of nodes that the given node in the provided graph has as
/// its incoming nodes, both directly and transitively.
private func transitiveIncomingNodes<Node: Equatable>(_ graph: [Node: Set<Node>], node: Node) -> Set<Node> {
private func transitiveIncomingNodes<Node>(_ graph: [Node: Set<Node>], node: Node) -> Set<Node> {
guard let nodes = graph[node] else {
return Set()
}
Expand Down
4 changes: 2 additions & 2 deletions Source/CarthageKit/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct Constants {
} else {
homePath = ("~/.carthage" as NSString).expandingTildeInPath
}
return URL(fileURLWithPath: homePath, isDirectory:true)
return URL(fileURLWithPath: homePath, isDirectory: true)
}()

/// ~/Library/Caches/org.carthage.CarthageKit/
Expand All @@ -33,7 +33,7 @@ public struct Constants {
let dependenciesURL = cachesURL.appendingPathComponent(Constants.bundleIdentifier, isDirectory: true)
let dependenciesPath = dependenciesURL.absoluteString

if fileManager.fileExists(atPath: dependenciesPath, isDirectory:nil) {
if fileManager.fileExists(atPath: dependenciesPath, isDirectory: nil) {
if fileManager.isWritableFile(atPath: dependenciesPath) {
return Result(value: dependenciesURL)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/CarthageKit/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Dependency {
if urlString.contains(githubHostIdentifier) {
let gitbubHostScanner = Scanner(string: urlString)

gitbubHostScanner.scanUpTo(githubHostIdentifier, into:nil)
gitbubHostScanner.scanUpTo(githubHostIdentifier, into: nil)
gitbubHostScanner.scanString(githubHostIdentifier, into: nil)

// find an SCP or URL path separator
Expand Down
56 changes: 27 additions & 29 deletions Source/CarthageKit/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct FetchCache {
/// Amount of time before a git repository is fetched again. Defaults to 1 minute
public static var fetchCacheInterval: TimeInterval = 60.0

private static var lastFetchTimes: [GitURL : TimeInterval] = [:]
private static var lastFetchTimes: [GitURL: TimeInterval] = [:]

internal static func clearFetchTimes() {
lastFetchTimes.removeAll()
Expand Down Expand Up @@ -155,26 +155,25 @@ public func checkoutRepositoryToDirectory(
_ workingDirectoryURL: URL,
revision: String = "HEAD"
) -> SignalProducer<(), CarthageError> {
return SignalProducer
{ () -> Result<[String: String], CarthageError> in
var environment = ProcessInfo.processInfo.environment
environment["GIT_WORK_TREE"] = workingDirectoryURL.path
return .success(environment)
}
.attempt { _ in
Result(attempt: { try FileManager.default.createDirectory(at: workingDirectoryURL, withIntermediateDirectories: true) })
.mapError {
CarthageError.repositoryCheckoutFailed(
workingDirectoryURL: workingDirectoryURL,
reason: "Could not create working directory",
underlyingError: $0
)
}
}
.flatMap(.concat) { environment in
return launchGitTask([ "checkout", "--quiet", "--force", revision ], repositoryFileURL: repositoryFileURL, environment: environment)
}
.then(SignalProducer<(), CarthageError>.empty)
return SignalProducer { () -> Result<[String: String], CarthageError> in
var environment = ProcessInfo.processInfo.environment
environment["GIT_WORK_TREE"] = workingDirectoryURL.path
return .success(environment)
}
.attempt { _ in
Result(attempt: { try FileManager.default.createDirectory(at: workingDirectoryURL, withIntermediateDirectories: true) })
.mapError {
CarthageError.repositoryCheckoutFailed(
workingDirectoryURL: workingDirectoryURL,
reason: "Could not create working directory",
underlyingError: $0
)
}
}
.flatMap(.concat) { environment in
return launchGitTask([ "checkout", "--quiet", "--force", revision ], repositoryFileURL: repositoryFileURL, environment: environment)
}
.then(SignalProducer<(), CarthageError>.empty)
}

/// Clones the given submodule into the working directory of its parent
Expand Down Expand Up @@ -215,15 +214,14 @@ public func cloneSubmoduleInWorkingDirectory(_ submodule: Submodule, _ workingDi
}
}

return SignalProducer<(), CarthageError>
{ () -> Result<(), CarthageError> in
repositoryCheck("remove submodule checkout") {
try FileManager.default.removeItem(at: submoduleDirectoryURL)
}
return SignalProducer<(), CarthageError> { () -> Result<(), CarthageError> in
repositoryCheck("remove submodule checkout") {
try FileManager.default.removeItem(at: submoduleDirectoryURL)
}
.then(cloneRepository(submodule.url, workingDirectoryURL.appendingPathComponent(submodule.path), isBare: false))
.then(checkoutSubmodule(submodule, submoduleDirectoryURL))
.then(purgeGitDirectories)
}
.then(cloneRepository(submodule.url, workingDirectoryURL.appendingPathComponent(submodule.path), isBare: false))
.then(checkoutSubmodule(submodule, submoduleDirectoryURL))
.then(purgeGitDirectories)
}

/// Recursively checks out the given submodule's revision, in its working
Expand Down
93 changes: 46 additions & 47 deletions Source/CarthageKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public final class Project { // swiftlint:disable:this type_body_length
/// Sends the URL of the dSYM after copying.
public func copyDSYMToBuildFolderForFramework(_ frameworkURL: URL, fromDirectoryURL directoryURL: URL) -> SignalProducer<URL, CarthageError> {
let destinationDirectoryURL = frameworkURL.deletingLastPathComponent()
return dSYMForFramework(frameworkURL, inDirectoryURL:directoryURL)
return dSYMForFramework(frameworkURL, inDirectoryURL: directoryURL)
.copyFileURLsIntoDirectory(destinationDirectoryURL)
}

Expand Down Expand Up @@ -1213,57 +1213,56 @@ public func cloneOrFetch(
let fileManager = FileManager.default
let repositoryURL = repositoryFileURL(for: dependency, baseURL: destinationURL)

return SignalProducer
{
Result(at: destinationURL, attempt: {
try fileManager.createDirectory(at: $0, withIntermediateDirectories: true)
return dependency.gitURL(preferHTTPS: preferHTTPS)!
})
}
.flatMap(.merge) { (remoteURL: GitURL) -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
return isGitRepository(repositoryURL)
.flatMap(.merge) { isRepository -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
if isRepository {
let fetchProducer: () -> SignalProducer<(ProjectEvent?, URL), CarthageError> = {
guard FetchCache.needsFetch(forURL: remoteURL) else {
return SignalProducer(value: (nil, repositoryURL))
}

return SignalProducer(value: (.fetching(dependency), repositoryURL))
.concat(
fetchRepository(repositoryURL, remoteURL: remoteURL, refspec: "+refs/heads/*:refs/heads/*")
.then(SignalProducer<(ProjectEvent?, URL), CarthageError>.empty)
)
return SignalProducer {
Result(at: destinationURL, attempt: {
try fileManager.createDirectory(at: $0, withIntermediateDirectories: true)
return dependency.gitURL(preferHTTPS: preferHTTPS)!
})
}
.flatMap(.merge) { (remoteURL: GitURL) -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
return isGitRepository(repositoryURL)
.flatMap(.merge) { isRepository -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
if isRepository {
let fetchProducer: () -> SignalProducer<(ProjectEvent?, URL), CarthageError> = {
guard FetchCache.needsFetch(forURL: remoteURL) else {
return SignalProducer(value: (nil, repositoryURL))
}

// If we've already cloned the repo, check for the revision, possibly skipping an unnecessary fetch
if let commitish = commitish {
return SignalProducer.zip(
branchExistsInRepository(repositoryURL, pattern: commitish),
commitExistsInRepository(repositoryURL, revision: commitish)
)
.flatMap(.concat) { branchExists, commitExists -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
// If the given commitish is a branch, we should fetch.
if branchExists || !commitExists {
return fetchProducer()
} else {
return SignalProducer(value: (nil, repositoryURL))
}
}
} else {
return fetchProducer()
}
} else {
// Either the directory didn't exist or it did but wasn't a git repository
// (Could happen if the process is killed during a previous directory creation)
// So we remove it, then clone
_ = try? fileManager.removeItem(at: repositoryURL)
return SignalProducer(value: (.cloning(dependency), repositoryURL))
return SignalProducer(value: (.fetching(dependency), repositoryURL))
.concat(
cloneRepository(remoteURL, repositoryURL)
fetchRepository(repositoryURL, remoteURL: remoteURL, refspec: "+refs/heads/*:refs/heads/*")
.then(SignalProducer<(ProjectEvent?, URL), CarthageError>.empty)
)
}

// If we've already cloned the repo, check for the revision, possibly skipping an unnecessary fetch
if let commitish = commitish {
return SignalProducer.zip(
branchExistsInRepository(repositoryURL, pattern: commitish),
commitExistsInRepository(repositoryURL, revision: commitish)
)
.flatMap(.concat) { branchExists, commitExists -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
// If the given commitish is a branch, we should fetch.
if branchExists || !commitExists {
return fetchProducer()
} else {
return SignalProducer(value: (nil, repositoryURL))
}
}
} else {
return fetchProducer()
}
} else {
// Either the directory didn't exist or it did but wasn't a git repository
// (Could happen if the process is killed during a previous directory creation)
// So we remove it, then clone
_ = try? fileManager.removeItem(at: repositoryURL)
return SignalProducer(value: (.cloning(dependency), repositoryURL))
.concat(
cloneRepository(remoteURL, repositoryURL)
.then(SignalProducer<(ProjectEvent?, URL), CarthageError>.empty)
)
}
}
}
}
}
36 changes: 17 additions & 19 deletions Source/CarthageKit/Resolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,30 @@ public struct Resolver: ResolverProtocol {
) -> SignalProducer<DependencyGraph, CarthageError> {
let scheduler = QueueScheduler(qos: .default, name: "org.carthage.CarthageKit.Resolver.graphs")

return SignalProducer<(DependencyGraph, [DependencyNode]), CarthageError>
{ () -> Result<(DependencyGraph, [DependencyNode]), CarthageError> in
return SignalProducer<(DependencyGraph, [DependencyNode]), CarthageError> { () -> Result<(DependencyGraph, [DependencyNode]), CarthageError> in
var graph = inputGraph
return graph
.addNodes(nodes, dependenciesOf: dependencyOf)
.map { newNodes in
return (graph, newNodes)
}
}
.flatMap(.concat) { graph, nodes -> SignalProducer<DependencyGraph, CarthageError> in
return SignalProducer(nodes)
// Each producer represents all evaluations of one subtree.
.map { node in self.graphsForDependenciesOfNode(node, basedOnGraph: graph) }
.observe(on: scheduler)
.permute()
.flatMap(.concat) { graphs -> SignalProducer<Signal<DependencyGraph, CarthageError>.Event, NoError> in
return SignalProducer<DependencyGraph, CarthageError>
{
mergeGraphs([ inputGraph ] + graphs)
}
.materialize()
}
.flatMap(.concat) { graph, nodes -> SignalProducer<DependencyGraph, CarthageError> in
return SignalProducer(nodes)
// Each producer represents all evaluations of one subtree.
.map { node in self.graphsForDependenciesOfNode(node, basedOnGraph: graph) }
.observe(on: scheduler)
.permute()
.flatMap(.concat) { graphs -> SignalProducer<Signal<DependencyGraph, CarthageError>.Event, NoError> in
return SignalProducer<DependencyGraph, CarthageError> {
mergeGraphs([ inputGraph ] + graphs)
}
// Pass through resolution errors only if we never got
// a valid graph.
.dematerializeErrorsIfEmpty()
}
.materialize()
}
// Pass through resolution errors only if we never got
// a valid graph.
.dematerializeErrorsIfEmpty()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/CarthageKit/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private func mergeBuildProducts(

let sourceModulesURL = SignalProducer(result: simulatorBuildSettings.relativeModulesPath.fanout(simulatorBuildSettings.builtProductsDirectoryURL))
.filter { $0.0 != nil }
.map { (modulesPath, productsURL) -> URL in
.map { modulesPath, productsURL in
return productsURL.appendingPathComponent(modulesPath!)
}

Expand Down

0 comments on commit 5109296

Please sign in to comment.