Skip to content

Commit 6c4194f

Browse files
committed
- Fixes git history viewer
- Fixes fsnotes:// router #1439
1 parent f0fd18f commit 6c4194f

File tree

5 files changed

+56
-35
lines changed

5 files changed

+56
-35
lines changed

FSNotes/AppDelegate+URLRoutes.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ extension AppDelegate {
125125
var lastPath = url.lastPathComponent
126126

127127
if let wikiURL = url["id"] {
128-
if let note = Storage.sharedInstance().getBy(title: wikiURL) {
128+
var note = Storage.sharedInstance().getBy(fileName: wikiURL)
129+
if note == nil {
130+
note = Storage.sharedInstance().getBy(title: wikiURL)
131+
}
132+
133+
if let note = note {
129134
vc.cleanSearchAndEditArea(shouldBecomeFirstResponder: false, completion: { () -> Void in
130135
vc.notesTableView.selectRowAndSidebarItem(note: note)
131136
NSApp.mainWindow?.makeFirstResponder(vc.editor)

FSNotes/Business/Project+Git.swift

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ extension Project {
238238

239239
public func pull() throws {
240240
guard let repository = try getRepository() else { return }
241+
242+
if let origin = getGitOrigin() {
243+
repository.addRemoteOrigin(path: origin)
244+
}
245+
241246
let repositoryProject = getRepositoryProject()
242247

243248
if !UserDefaultsManagement.separateRepo || isCloudProject() {

FSNotes/EditorViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class EditorViewController: NSViewController, NSTextViewDelegate, WebFrameLoadDe
536536

537537
noteDupe.save()
538538

539-
Storage.shared().add(noteDupe)
539+
Storage.sharedInstance().add(noteDupe)
540540
ViewController.shared()?.notesTableView.insertNew(note: noteDupe)
541541
}
542542
}

FSNotes/Git/revision/FileHistoryIterator.swift

+37-32
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class FileHistoryIterator : RevisionIterator {
5656
guard let oid = super.next() else {
5757
return nil
5858
}
59-
59+
6060
lastFetchedOid = oid
6161

6262
do {
@@ -69,53 +69,58 @@ public class FileHistoryIterator : RevisionIterator {
6969
// Find current entry
7070
let entry = try tree.entry(byPath: path)
7171
if (entry == nil) {
72-
previousOid = oid
73-
return next();
72+
return diffPrev(tree: tree, oid: oid)
7473
}
7574

7675
// Test previous
7776
if (previousOid == nil) {
77+
previousOid = oid
78+
79+
return next()
80+
} else {
81+
return diffPrev(tree: tree, oid: oid)
82+
}
83+
84+
} catch {
85+
NSLog("Unable to find next OID \(error)")
86+
}
87+
88+
return nil
89+
}
90+
91+
private func diffPrev(tree: Tree, oid: OID) -> OID? {
92+
guard let pOid = previousOid else { return next() }
93+
94+
do {
95+
// Find commit
96+
let previousCommit = try repository.commitLookup(oid: pOid)
97+
98+
// Find parent entry
99+
let previousTree = try previousCommit.tree()
100+
101+
// Find diff
102+
let diff = try previousTree.diff(other: tree)
103+
104+
// Find
105+
if diff.find(byPath: path) == nil {
78106

79107
// Set previous and find next
80108
previousOid = oid
81109

82110
return next()
83-
84111
} else {
85112

86-
// Find commit
87-
let previousCommit = try repository.commitLookup(oid: previousOid!)
113+
// Save previousOid
114+
let validOid = previousOid
88115

89-
// Find parent entry
90-
let previousTree = try previousCommit.tree()
91-
92-
// Find diff
93-
let diff = try previousTree.diff(other: tree)
116+
// Set previousOid
117+
previousOid = oid
94118

95-
// Find
96-
if diff.find(byPath: path) == nil {
97-
98-
// Set previous and find next
99-
previousOid = oid
100-
101-
return next()
102-
} else {
103-
104-
// Save previousOid
105-
let validOid = previousOid
106-
107-
// Set previousOid
108-
previousOid = oid
109-
110-
return validOid;
111-
}
119+
return validOid;
112120
}
113-
114121
} catch {
115-
NSLog("Unable to find next OID \(error)")
122+
return nil
116123
}
117-
118-
return nil
119124
}
120125

121126
public func getLast() -> OID? {

FSNotes/Preferences/PreferencesGitViewController.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class PreferencesGitViewController: NSViewController {
143143
project?.saveSettings()
144144

145145
UserDefaultsManagement.gitOrigin = sender.stringValue
146+
147+
ViewController.shared()?.gitQueue.cancelAllOperations()
146148
}
147149

148150
@IBAction func username(_ sender: NSTextField) {
@@ -191,6 +193,8 @@ class PreferencesGitViewController: NSViewController {
191193
}
192194

193195
@IBAction func pullInterval(_ sender: NSTextField) {
196+
ViewController.shared()?.gitQueue.cancelAllOperations()
197+
194198
if var interval = Int(sender.stringValue) {
195199
if interval < 10 {
196200
interval = 10
@@ -213,9 +217,11 @@ class PreferencesGitViewController: NSViewController {
213217
}
214218

215219
@IBAction func clonePull(_ sender: Any) {
216-
guard let project = Storage.shared().getDefault() else { return }
220+
guard let project = Storage.sharedInstance().getDefault() else { return }
217221
guard let window = view.window else { return }
218222

223+
ViewController.shared()?.gitQueue.cancelAllOperations()
224+
219225
let origin = self.origin.stringValue
220226
project.gitOrigin = origin
221227
project.saveSettings()

0 commit comments

Comments
 (0)