-
Notifications
You must be signed in to change notification settings - Fork 179
Implement git status and diffs #102
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
Conversation
β¦luding basic testing
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'll need to take a deeper look at this, but I left some preliminary thoughts here.
SwiftGit2/Diffs.swift
Outdated
public var newFile: GitDiffFile? | ||
} | ||
|
||
public enum GitDiffFlag: Int { |
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.
This looks like it could be an OptionSet
.
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.
Brilliant. Didn't know about optionset. Thanks. Partially doing this to get better at swift, definitely appreciate the feedback.
SwiftGit2/Diffs.swift
Outdated
case validId = 2 | ||
case exists = 4 | ||
|
||
public var value: UInt32 { |
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 think you could just declare the rawValue
to be UInt32
.
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.
Makes sense. Can't remember why I wrote it this way but I'll clean it up.
SwiftGit2/Diffs.swift
Outdated
// Copyright Β© 2017 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
public struct GitDiffFile { |
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 don't think we need to put Git
in the type names. It's a bit redundant.
SwiftGit2/Diffs.swift
Outdated
public var flags: UInt32 | ||
} | ||
|
||
public enum GitStatus: Int { |
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 think this could just be declared as UInt32
.
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.
Here are some more thoughts. I'll review again once all these are fixed up.
SwiftGit2/Repository.swift
Outdated
|
||
// MARK: - Diffs | ||
|
||
public func getDiffDeltas(for commit: Commit) -> Result<[GitDiffDelta], NSError> { |
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 think we can name this diff(for commit: Commit)
.
SwiftGit2/Repository.swift
Outdated
} | ||
} | ||
} | ||
return self.processDiffDeltas(mergeDiff!) |
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.
This code doesn't look any different than the code in getDiffDeltasWithOneParent
, so I think that function can be removed. This function can be used instead and the loop will do the right thing.
SwiftGit2/Repository.swift
Outdated
|
||
// MARK: - Status | ||
|
||
public func getRepositoryStatus() -> [GitStatusEntry] { |
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 think we can call this status()
.
SwiftGit2/Repository.swift
Outdated
pointer.deallocate(capacity: 1) | ||
|
||
var status: OpaquePointer? = nil | ||
git_status_list_new(&status, self.pointer, &options) |
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.
The return code for this function should be checked.
SwiftGit2/Repository.swift
Outdated
flags: s?.pointee.index_to_workdir.pointee.flags, | ||
oldFile: itowOldFile, | ||
newFile: itowNewFile) | ||
} |
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.
The code here is duplicated with the code in the previous if
. Can you add a function that creates a GitDiffDelta
from a git_diff_delta
? Probably adding an init
to GitDiffDelta
is the best way to do this.
SwiftGit2/Repository.swift
Outdated
status = GitStatus(rawValue: Int(status!.value & GitStatus.workTreeTypeChange.value)) | ||
} | ||
|
||
return status! |
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.
This should be an init
on GitStatus
instead of a method here.
SwiftGit2/Repository.swift
Outdated
path: path.map(String.init(cString:))!, | ||
size: file.size, | ||
flags: file.flags) | ||
return newFile |
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.
This should be an init
on GitDiffFile
.
β¦me thing, factor them out completely
β¦ecide what the different statuses returned by libgit2 mean rather than imposing our own assumptions
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.
Ok, I've tried to make all your requested changes. Let me know what you think!
SwiftGit2/Diffs.swift
Outdated
public var oid: OID | ||
public var path: String | ||
public var size: Int64 | ||
public var flags: UInt32 |
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.
This should be a DiffFlag
.
SwiftGit2/Diffs.swift
Outdated
public static let conflicted = Status(rawValue: 1 << 12) | ||
} | ||
|
||
public struct DiffFlag: OptionSet { |
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 think this should have a plural name. DiffFlags
SwiftGit2/Diffs.swift
Outdated
self.oldFile = DiffFile(from: diffDelta.old_file) | ||
self.newFile = DiffFile(from: diffDelta.new_file) | ||
} | ||
} |
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.
What do you think of adding a Diff
type that holds the deltas and then nesting these types inside of it?
public struct Diff {
public struct File { β¦ }
public struct Flag: OptionSet { ... }
public struct Delta {
public var status: Status
public var flags: DiffFlag
public var oldFile: File
public var newFile: File
}
let deltas: [Delta]
}
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.
The only caveat with this is that to create an array of a nested struct defined that way, you apparently need to typealias it like so typealias Delta = Diff.Delta; var returnDict = [Delta]()
, but otherwise i like the organization it provides
SwiftGit2/Diffs.swift
Outdated
public var status: Status? | ||
public var flags: DiffFlag? | ||
public var oldFile: DiffFile? | ||
public var newFile: DiffFile? |
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.
Why are these all optional?
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.
you're right, only the files need to be optional as libgit2 will return nil depending on the delta
SwiftGit2/Diffs.swift
Outdated
} | ||
|
||
public struct StatusEntry { | ||
public var status: Status? |
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.
This probably shouldn't be optional?
SwiftGit2/Repository.swift
Outdated
var unsafeDiff: OpaquePointer? = nil | ||
let diffResult = git_diff_tree_to_tree(&unsafeDiff, self.pointer, unwrapParentTree, unwrapBaseTree, nil) | ||
guard diffResult == GIT_OK.rawValue, let unwrapDiffResult = unsafeDiff else { | ||
return Result.failure(NSError(gitError: diffResult, pointOfFailure: "git_diff_tree_to_tree")) |
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.
git_diff_tree_to_tree
, git_commit_lookup
, and git_commit_tree
are all used multiple times, but they're quite a bit of code. It seems like we could create helper functions for these? That should really improve readability here.
SwiftGit2/Repository.swift
Outdated
indexToWorkDir = DiffDelta(from: itow.pointee) | ||
} | ||
|
||
let statusEntry = StatusEntry(status: status, headToIndex: headToIndex, indexToWorkDir: indexToWorkDir) |
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.
Can we make the StatusEntry.init
take the git_status_entry
and do this work?
Mapping these libgit2 APIs onto Swift is a lot of work! π But you're doing great! |
β¦into helper functions and nest the various Diff structs inside a struct named Diff
β¦f Diff since it has references to two Diff Deltas but itself is not a Diff and not used by anything contained within Diff. It is conceptually different.
SwiftGit2Tests/RepositorySpec.swift
Outdated
@@ -641,8 +641,63 @@ class RepositorySpec: QuickSpec { | |||
expect(commitMessages).to(equal(expectedMessages)) | |||
} | |||
} | |||
|
|||
describe("Repository.getRepositoryStatus") { |
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.
This name needs to be updated
SwiftGit2Tests/RepositorySpec.swift
Outdated
|
||
let head = repo.HEAD().value! | ||
let commit = repo.object(head.oid).value! as! Commit | ||
let objects = repo.diff(for: commit) |
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.
This test (and the following ones) are testing diff
, so they should be in a separate describe
.
SwiftGit2/Repository.swift
Outdated
let baseTree = self.tree(from: baseCommit.value!) | ||
guard baseTree.error == nil else { | ||
return Result.failure(baseTree.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.
No that these are nicely abstracted, we can use flatMap
to propagate errors automatically.
return self
.commit(with: commit.oid)
.flatMap { baseCommit in
return self.tree(from: baseCommit)
}
.flatMap { baseTree in
guard !commit.parents.isEmpty else {
// Initial commit in a repository
return self.diff(withOldTree: nil, andNewTree: baseTree.value)
}
var mergeDiff: Result<OpaquePointer?, NSError> = .success(nil)
for parent in commit.parents {
mergeDiff = mergeDiff
.flatMap { mergeDiff in
return self
.parentCommit(from: parent)
.flatMap { commit in
return self.tree(from: commit)
}
.flatMap { tree in
return self.diff(withOldTree: tree, andNewTree: baseTree)
}
.flatMap { diff in
guard let mergeDiff = mergeDiff else { return .success(diff) }
let merge = git_diff_merge(mergeDiff, diff)
guard mergeResult == gIT_OK.rawValue else {
// return return error
}
return .success(merge)
}
}
}
}
.flatMap { diffResult in
return self.processDiffDeltas(diffResult)
}
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.
interesting. I've seen flatmap before but not like this. I'll put this in
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.
Wait, is flatMap supposed to be implemented on Repository? I see it implemented in Result but I'm not sure how to use this sample code.
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.
Oops! There was a line missing. I've updated the code sample above.
SwiftGit2Tests/RepositorySpec.swift
Outdated
let initalCommit = repo.object(head.oid).value! as! Commit | ||
let objects = repo.diff(for: initalCommit) | ||
|
||
expect(objects.value?.count).to(equal(2)) |
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.
It'd be nice to test the results a bit more fully.
I would stick with the I think either your test or your expectation is wrong. I think it's the test, because that commit only changed one file. |
@mdiep It looks like the issue was actually that we were returning mergeDiff too soon, so only one parent was considered. I don't love the way I'm doing it instead ( |
SwiftGit2/Diffs.swift
Outdated
} | ||
|
||
if let itow = statusEntry.index_to_workdir { | ||
self.indexToWorkDir = Diff.Delta(_: itow.pointee) |
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.
You don't need to specify _:
here; I didn't even know you could do that. Diff.Delta(itow.pointee)
is sufficient.
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.
nice catch
SwiftGit2/Repository.swift
Outdated
|
||
returnDict.append(gitDiffDelta) | ||
|
||
git_diff_free(OpaquePointer(delta)) |
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.
This is incorrect. git_diff_free
is called on git_diff
s; delta
is a git_diff_delta
.
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.
Good catch. According to the docs The git_diff_delta pointer points to internal data and you do not have to release it when you are done with it. It will go away when the * git_diff (or any associated git_patch) goes away.
SwiftGit2/Repository.swift
Outdated
} | ||
git_commit_free(unsafeBaseCommit) | ||
|
||
return Result.success(unwrapBaseCommit) |
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 don't think it's safe to use unwrapBaseCommit
here after freeing unsafeBaseCommit
. I think this should switch to use the same callback style as the remoteLookup
method.
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 was working on this when I discovered the already existing withGitObject
β¦ what do you think about replacing e.g. .commit(with: parent.oid)
with .withGitObject(parent.oid, type: GIT_OBJ_COMMIT)
and killing the commit(with:)
altogether? The tests still pass.
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.
Yeah, that sounds good! π You can tell it's been a while since I've really worked with this code. π
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.
No worries. There's actually a handful of helpers I never noticed before, so I'll convert things to use those.
SwiftGit2/Repository.swift
Outdated
return Result.failure(NSError(gitError: diffResult, pointOfFailure: "git_diff_tree_to_tree")) | ||
} | ||
|
||
return Result.success(unwrapDiffResult) |
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.
Same here about it being unsafe, except this is missing a git_diff_free
.
SwiftGit2/Repository.swift
Outdated
} | ||
git_tree_free(unsafeTree) | ||
|
||
return Result.success(unwrapTree) |
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.
Same here about it being unsafe.
SwiftGit2/Repository.swift
Outdated
continue | ||
} | ||
|
||
let statusEntry = StatusEntry(from: (s?.pointee)!) |
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.
Might as well do s!.pointee
here instead of (s?.pointee)!
.
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.
π
SwiftGit2Tests/RepositorySpec.swift
Outdated
var oldFilePaths: [String] = [] | ||
for delta in deltas { | ||
oldFilePaths.append((delta.oldFile?.path)!) | ||
} |
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.
These could use map
instead of for
loops
let oldFilePaths = deltas.map { $0.oldFile!.path }
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.
nice π
I think the tests look good enough now that they include the paths of the files. π |
β¦er with memory.
- use existing `withGitObject` method - introduce extended version that can handle multiple git objects for the purpose of handling multiple parents
SwiftGit2/Repository.swift
Outdated
git_tree_free(tree) | ||
git_commit_free(commit) | ||
return result | ||
if oldTree != nil && newTree != nil { |
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 unsure of this triple branch of logic. I was hoping to find a "swifty" way of identifying which tree was (or whether both trees were) supplied, without needing three if else
branches but couldn't get it. I'm particularly interested if something pops out, I tried several different things and none were as satisfying to me as just doing the branch.
SwiftGit2/Repository.swift
Outdated
mergeDiff = diff.value! | ||
} else { | ||
let mergeResult = git_diff_merge(mergeDiff, diff.value) | ||
guard mergeResult == GIT_OK.rawValue else { |
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 think we could just do git_object_free(diff)
here instead of keeping a list of diffs
. That would reduce memory consumption and should also make the code a little clearer.
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.
nice catch π
SwiftGit2/Repository.swift
Outdated
git_object_free(diff) | ||
} | ||
|
||
return .success(Diff(mergeDiff!)) |
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 think we need to free mergeDiff
. Putting a defer { git_object_free(mergeDiff) }
before this line should work.
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.
π
SwiftGit2/Repository.swift
Outdated
return Result.failure(result.error!) | ||
} | ||
|
||
oldTree = result.value |
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.
Maybe follow this line with defer { git_object_free(oldTree) }
(and same with newTree
below).
The locality of that is nice, but it should also help us free memory if we return an 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.
π
SwiftGit2/Repository.swift
Outdated
return .success(Diff(mergeDiff!)) | ||
} | ||
|
||
/// Caller is responsible to free returned git_diff with git_object_free |
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.
Instead of making the caller free the diff, I think this should take a block that lets you execute code with the diff. That should let us remove the need for the above frees that I comment about.
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.
good call, I might have missed something memory management wise and handling errors was a bit of a trick but I think I have a solution.
newTree = result.value! | ||
} | ||
|
||
if oldTree != nil && newTree != nil { |
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.
You should be able to replace this with a switch
.
switch (oldTree, newTree) {
case let (oldTree?, newTree?): // I'm not sure if you'll be able to reuse the names here
// has both
case let (tree?, nil), let (nil, tree?):
// has one
case (nil, nil):
// has neither
}
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.
nice!
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.
It looks like case let (oldTree?, newTree?)
works, the only problem I have is I'm not sure how to use tree here: case let (tree?, nil), let (nil, tree?):
. I'm not sure how to use this. I need to know which of the two has a value.
e.g. I wrote it like this, but I really can't figure out the appropriate syntax and it is incorrect and breaks the tests. ideas?:
case let (tree?, nil), let (nil, tree?):
return withGitObject(tree.oid, type: GIT_OBJ_TREE, transform: { tree in
var diff: OpaquePointer? = nil
let diffResult = git_diff_tree_to_tree(&diff, self.pointer,
tree,
tree,
nil)
...
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.
Ah, it looks like those will need to be separate cases. I didn't see that they were subtly different. Maybe we can reuse some code between them?
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.
Ok, well I guess a triple branch is the best we can do. I factored the commonalities into a separate private method.
SwiftGit2/Repository.swift
Outdated
} | ||
|
||
/// Memory safe | ||
private func diff(from oldCommitOid: OID?, to newCommitOid: OID?) -> Result<Diff, NSError> { |
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.
It seems like the safe and un-safe versions of this should share some code.
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.
Just a few memory fixes to go! This really makes you appreciate ARC. π
It'd also be nice to see some more documentation on the added API if you're willing.
let result = git_object_lookup(&pointer, self.pointer, &oid, type) | ||
|
||
guard result == GIT_OK.rawValue else { | ||
return Result.failure(NSError(gitError: result, pointOfFailure: "git_object_lookup")) |
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.
pointers
need to be freed here.
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 think the point of collecting them was to allow the caller to perform custom behavior on their values e.g. on line 683. The collection is then freed in 243-245. Or did you mean something else?
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 mean that in the case where we return an error here, they need to be freed.
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.
Got it. How about another defer
?
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.
Oh yeah! For some reason I was thinking that wouldn't work but it totally does. π€¦ββοΈ
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.
π
SwiftGit2/Repository.swift
Outdated
} | ||
} | ||
|
||
defer { git_object_free(mergeDiff) } |
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.
This isn't freed in either of the error conditions here.
Let's move this defer
to be immediately after the var mergeDiff
declaration.
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.
good catch π
SwiftGit2/Repository.swift
Outdated
} | ||
|
||
oldTree = result.value | ||
git_object_free(oldTree) |
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 think this should be in a defer
before the if
?
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.
It's gotchas like these that help me learn. I'm a rails developer for my day job. Thanks!
SwiftGit2/Repository.swift
Outdated
} | ||
|
||
newTree = result.value | ||
git_object_free(newTree) |
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 think this should be in a defer
before the if
?
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'd be happy to see about adding to the documentation, where can I find that? |
Any documentation should be added inline with 3 /// Information about this struct
struct Struct {
/// Information about this method
///
/// - parameters:
/// - foo: Information about foo
/// - returns: Information about the return value
func doSomething(foo: String) -> Int {
}
} |
SwiftGit2/Repository.swift
Outdated
pointer.deallocate(capacity: 1) | ||
|
||
var unsafeStatus: OpaquePointer? = nil | ||
let statusResult = git_status_list_new(&unsafeStatus, self.pointer, &options) |
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.
One last memory issue: This needs a git_status_list_free
in a defer
.
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.
π
After this last fix we can merge! π |
Sounds good! Thanks for finding all those memory leaks! I should have been more diligent about considering that. π |
No worries! I think I missed them several times too. π Thanks for all your work on this! Sorry to put you through so many rounds of review. |
Not at all! glad we got it right, and you've helped me learn a lot. π π― |
π |
I'm working on implementing repository status and diffs, it isn't complete but I think this is a good starting point. Currently you can get the diff deltas for comparing a given commit in a repository to that commit's parent, or parents if it's a merge commit, or just get what was committed if it's the initial commit. You can also get the current status of a repository from the index to the working directory, or from the HEAD to the index. Let me know what you think!