Change getNumberOfUnsynced to numberOfLocalCommits
This commit is contained in:
parent
ac3dbad4dd
commit
f36899a8ad
3 changed files with 34 additions and 16 deletions
|
|
@ -74,7 +74,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
// section 0
|
// section 0
|
||||||
[[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords", .detailText: numberOfPasswords],
|
[[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords", .detailText: numberOfPasswords],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size", .detailText: sizeOfRepository],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size", .detailText: sizeOfRepository],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Unsynced", .detailText: String(self?.passwordStore.getNumberOfUnsyncedPasswords() ?? 0)],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Local Commits", .detailText: String(self?.passwordStore.numberOfLocalCommits() ?? 0)],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits", .detailText: numberOfCommitsString],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits", .detailText: numberOfCommitsString],
|
||||||
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
SVProgressHUD.show(withStatus: "Sync Password Store")
|
SVProgressHUD.show(withStatus: "Sync Password Store")
|
||||||
let numberOfUnsyncedPasswords = self.passwordStore.getNumberOfUnsyncedPasswords()
|
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits()
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
try self.passwordStore.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
|
try self.passwordStore.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
|
||||||
|
|
@ -114,7 +114,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if numberOfUnsyncedPasswords > 0 {
|
if numberOfLocalCommits > 0 {
|
||||||
try self.passwordStore.pushRepository(transferProgressBlock: {(current, total, bytes, stop) in
|
try self.passwordStore.pushRepository(transferProgressBlock: {(current, total, bytes, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
||||||
|
|
@ -362,11 +362,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
} else {
|
} else {
|
||||||
title = "Password Store"
|
title = "Password Store"
|
||||||
}
|
}
|
||||||
let numberOfUnsynced = self.passwordStore.getNumberOfUnsyncedPasswords()
|
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits()
|
||||||
if numberOfUnsynced == 0 {
|
if numberOfLocalCommits == 0 {
|
||||||
navigationItem.title = "\(title)"
|
navigationItem.title = "\(title)"
|
||||||
} else {
|
} else {
|
||||||
navigationItem.title = "\(title) (\(numberOfUnsynced))"
|
navigationItem.title = "\(title) (\(numberOfLocalCommits))"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -647,17 +647,8 @@ class PasswordStore {
|
||||||
|
|
||||||
// return the number of discarded commits
|
// return the number of discarded commits
|
||||||
func reset() throws -> Int {
|
func reset() throws -> Int {
|
||||||
// get the remote origin/master branch
|
|
||||||
guard let remoteBranches = try storeRepository?.remoteBranches(),
|
|
||||||
let index = remoteBranches.index(where: { $0.shortName == "master" })
|
|
||||||
else {
|
|
||||||
throw NSError(domain: "me.mssun.pass.error", code: 1, userInfo: [NSLocalizedDescriptionKey: "Cannot find remote branch origin/master."])
|
|
||||||
}
|
|
||||||
let remoteMasterBranch = remoteBranches[index]
|
|
||||||
//print("remoteMasterBranch \(remoteMasterBranch)")
|
|
||||||
|
|
||||||
// get a list of local commits
|
// get a list of local commits
|
||||||
if let localCommits = try storeRepository?.localCommitsRelative(toRemoteBranch: remoteMasterBranch),
|
if let localCommits = try getLocalCommits(),
|
||||||
localCommits.count > 0 {
|
localCommits.count > 0 {
|
||||||
// get the oldest local commit
|
// get the oldest local commit
|
||||||
guard let firstLocalCommit = localCommits.last,
|
guard let firstLocalCommit = localCommits.last,
|
||||||
|
|
@ -675,4 +666,31 @@ class PasswordStore {
|
||||||
return 0 // no new commit
|
return 0 // no new commit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func numberOfLocalCommits() -> Int {
|
||||||
|
do {
|
||||||
|
if let localCommits = try getLocalCommits() {
|
||||||
|
return localCommits.count
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getLocalCommits() throws -> [GTCommit]? {
|
||||||
|
// get the remote origin/master branch
|
||||||
|
guard let remoteBranches = try storeRepository?.remoteBranches(),
|
||||||
|
let index = remoteBranches.index(where: { $0.shortName == "master" })
|
||||||
|
else {
|
||||||
|
throw NSError(domain: "me.mssun.pass.error", code: 1, userInfo: [NSLocalizedDescriptionKey: "Cannot find remote branch origin/master."])
|
||||||
|
}
|
||||||
|
let remoteMasterBranch = remoteBranches[index]
|
||||||
|
//print("remoteMasterBranch \(remoteMasterBranch)")
|
||||||
|
|
||||||
|
// get a list of local commits
|
||||||
|
return try storeRepository?.localCommitsRelative(toRemoteBranch: remoteMasterBranch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue