mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add Git.destroy() that frees native repository
This commit is contained in:
@@ -10,6 +10,7 @@ var $git = {};
|
||||
native function getDiffStats(path);
|
||||
native function isSubmodule(path);
|
||||
native function refreshIndex();
|
||||
native function destroy();
|
||||
|
||||
function GitRepository(path) {
|
||||
var repo = getRepository(path);
|
||||
@@ -29,5 +30,6 @@ var $git = {};
|
||||
GitRepository.prototype.getDiffStats = getDiffStats;
|
||||
GitRepository.prototype.isSubmodule = isSubmodule;
|
||||
GitRepository.prototype.refreshIndex = refreshIndex;
|
||||
GitRepository.prototype.destroy = destroy;
|
||||
this.GitRepository = GitRepository;
|
||||
})();
|
||||
|
||||
@@ -16,10 +16,17 @@ public:
|
||||
}
|
||||
|
||||
~GitRepository() {
|
||||
git_repository_free(repo);
|
||||
Destroy();
|
||||
}
|
||||
|
||||
BOOL exists() {
|
||||
void Destroy() {
|
||||
if (Exists()) {
|
||||
git_repository_free(repo);
|
||||
repo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL Exists() {
|
||||
return repo != NULL;
|
||||
}
|
||||
|
||||
@@ -190,7 +197,7 @@ bool Git::Execute(const CefString& name,
|
||||
CefString& exception) {
|
||||
if (name == "getRepository") {
|
||||
GitRepository *repository = new GitRepository(arguments[0]->GetStringValue().ToString().c_str());
|
||||
if (repository->exists()) {
|
||||
if (repository->Exists()) {
|
||||
CefRefPtr<CefBase> userData = repository;
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
retval->SetUserData(userData);
|
||||
@@ -248,6 +255,12 @@ bool Git::Execute(const CefString& name,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "destroy") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
userData->Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
Subscriber = require 'subscriber'
|
||||
|
||||
module.exports =
|
||||
class Git
|
||||
@@ -23,12 +25,17 @@ class Git
|
||||
|
||||
constructor: (path) ->
|
||||
@repo = new GitRepository(path)
|
||||
$(window).on 'focus', => @refreshIndex()
|
||||
@subscribe $(window), 'focus', => @refreshIndex()
|
||||
|
||||
refreshIndex: -> @repo.refreshIndex()
|
||||
|
||||
getPath: -> @repo.getPath()
|
||||
|
||||
destroy: ->
|
||||
@repo.destroy()
|
||||
@repo = null
|
||||
@unsubscribe()
|
||||
|
||||
getWorkingDirectory: ->
|
||||
repoPath = @getPath()
|
||||
repoPath?.substring(0, repoPath.length - 6)
|
||||
@@ -85,3 +92,5 @@ class Git
|
||||
|
||||
isSubmodule: (path) ->
|
||||
@repo.isSubmodule(@relativize(path))
|
||||
|
||||
_.extend Git.prototype, Subscriber
|
||||
|
||||
@@ -34,6 +34,8 @@ class Project
|
||||
grammarOverridesByPath: @grammarOverridesByPath
|
||||
|
||||
destroy: ->
|
||||
@repo?.destroy()
|
||||
@repo = null
|
||||
editSession.destroy() for editSession in @getEditSessions()
|
||||
|
||||
addGrammarOverrideForPath: (path, grammar) ->
|
||||
|
||||
Reference in New Issue
Block a user