From 70ef4e2efe28c642bef1935eae22b096dc3f3e8c Mon Sep 17 00:00:00 2001 From: Vladimir Buzuev Date: Sat, 3 Apr 2021 16:03:03 -0700 Subject: [PATCH 1/3] add wrapper for git_repository_item_path --- repository.go | 34 ++++++++++++++++++++++++++++++++++ repository_test.go | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/repository.go b/repository.go index a6eb7f1..b70a9cb 100644 --- a/repository.go +++ b/repository.go @@ -741,3 +741,37 @@ func (r *Repository) RemoveMessage() error { } return nil } + +type RepositoryItem int + +const ( + RepositoryItemGitDir RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR + RepositoryItemWorkDir RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR + RepositoryItemCommonDir RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR + RepositoryItemIndex RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX + RepositoryItemObjects RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS + RepositoryItemRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS + RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS + RepositoryItemRemotes RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES + RepositoryItemConfig RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG + RepositoryItemInfo RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO + RepositoryItemHooks RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS + RepositoryItemLogs RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS + RepositoryItemModules RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES + RepositoryItemWorkTrees RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES +) + +func (r *Repository) ItemPath(item RepositoryItem) (string, error) { + var c_buf C.git_buf + defer C.git_buf_dispose(&c_buf) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item)) + runtime.KeepAlive(r) + if ret < 0 { + return "", MakeGitError(ret) + } + return C.GoString(c_buf.ptr), nil +} diff --git a/repository_test.go b/repository_test.go index 5a0f920..d163a76 100644 --- a/repository_test.go +++ b/repository_test.go @@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) { t.Fatal("result must be true") } } + +func TestRepositoryItemPath(t *testing.T) { + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + gitDir, err := repo.ItemPath(RepositoryItemGitDir) + checkFatal(t, err) + if gitDir == "" { + t.Error("expected not empty gitDir") + } +} \ No newline at end of file -- 2.45.2 From f8c9b7df52b65d1884c9c5e52761ee99171c57f3 Mon Sep 17 00:00:00 2001 From: Vladimir Buzuev Date: Sat, 3 Apr 2021 16:04:25 -0700 Subject: [PATCH 2/3] add LF --- repository_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository_test.go b/repository_test.go index d163a76..e403aa9 100644 --- a/repository_test.go +++ b/repository_test.go @@ -102,4 +102,4 @@ func TestRepositoryItemPath(t *testing.T) { if gitDir == "" { t.Error("expected not empty gitDir") } -} \ No newline at end of file +} -- 2.45.2 From 27b45a1ef5298fdc58547b380ca689b873a220c7 Mon Sep 17 00:00:00 2001 From: Vladimir Buzuev Date: Sat, 3 Apr 2021 16:41:25 -0700 Subject: [PATCH 3/3] go gmt --- repository.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/repository.go b/repository.go index b70a9cb..cb82fc3 100644 --- a/repository.go +++ b/repository.go @@ -739,26 +739,26 @@ func (r *Repository) RemoveMessage() error { if cErr < 0 { return MakeGitError(cErr) } - return nil + return nil } type RepositoryItem int const ( - RepositoryItemGitDir RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR - RepositoryItemWorkDir RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR - RepositoryItemCommonDir RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR - RepositoryItemIndex RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX - RepositoryItemObjects RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS - RepositoryItemRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS + RepositoryItemGitDir RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR + RepositoryItemWorkDir RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR + RepositoryItemCommonDir RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR + RepositoryItemIndex RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX + RepositoryItemObjects RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS + RepositoryItemRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS - RepositoryItemRemotes RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES - RepositoryItemConfig RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG - RepositoryItemInfo RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO - RepositoryItemHooks RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS - RepositoryItemLogs RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS - RepositoryItemModules RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES - RepositoryItemWorkTrees RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES + RepositoryItemRemotes RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES + RepositoryItemConfig RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG + RepositoryItemInfo RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO + RepositoryItemHooks RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS + RepositoryItemLogs RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS + RepositoryItemModules RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES + RepositoryItemWorkTrees RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES ) func (r *Repository) ItemPath(item RepositoryItem) (string, error) { -- 2.45.2