Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
golang-gopkg-libgit2-git2go
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Debian Go Packaging Team
packages
golang-gopkg-libgit2-git2go
Commits
daee43b8
Commit
daee43b8
authored
May 20, 2017
by
Carlos Martín Nieto
Committed by
GitHub
May 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #376 from ankurmittal/short-hash
Add support for getting short object Id
parents
7cd5a4e7
7caac1fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
object.go
object.go
+14
-0
object_test.go
object_test.go
+27
-0
No files found.
object.go
View file @
daee43b8
...
@@ -49,6 +49,20 @@ func (o *Object) Id() *Oid {
...
@@ -49,6 +49,20 @@ func (o *Object) Id() *Oid {
return
newOidFromC
(
C
.
git_object_id
(
o
.
ptr
))
return
newOidFromC
(
C
.
git_object_id
(
o
.
ptr
))
}
}
func
(
o
*
Object
)
ShortId
()
(
string
,
error
)
{
resultBuf
:=
C
.
git_buf
{}
runtime
.
LockOSThread
()
defer
runtime
.
UnlockOSThread
()
ecode
:=
C
.
git_object_short_id
(
&
resultBuf
,
o
.
ptr
)
if
ecode
<
0
{
return
""
,
MakeGitError
(
ecode
)
}
defer
C
.
git_buf_free
(
&
resultBuf
)
return
C
.
GoString
(
resultBuf
.
ptr
),
nil
}
func
(
o
*
Object
)
Type
()
ObjectType
{
func
(
o
*
Object
)
Type
()
ObjectType
{
return
ObjectType
(
C
.
git_object_type
(
o
.
ptr
))
return
ObjectType
(
C
.
git_object_type
(
o
.
ptr
))
}
}
...
...
object_test.go
View file @
daee43b8
package
git
package
git
import
(
import
(
"strings"
"testing"
"testing"
)
)
...
@@ -105,6 +106,32 @@ func TestObjectOwner(t *testing.T) {
...
@@ -105,6 +106,32 @@ func TestObjectOwner(t *testing.T) {
checkOwner
(
t
,
repo
,
tree
.
Object
)
checkOwner
(
t
,
repo
,
tree
.
Object
)
}
}
func
checkShortId
(
t
*
testing
.
T
,
Id
,
shortId
string
)
{
if
len
(
shortId
)
<
7
||
len
(
shortId
)
>=
len
(
Id
)
{
t
.
Fatal
(
"bad shortId lenght %s"
,
len
(
shortId
))
}
if
!
strings
.
HasPrefix
(
Id
,
shortId
)
{
t
.
Fatalf
(
"bad shortId, should be prefix of %s, but is %s
\n
"
,
Id
,
shortId
)
}
}
func
TestObjectShortId
(
t
*
testing
.
T
)
{
t
.
Parallel
()
repo
:=
createTestRepo
(
t
)
defer
cleanupTestRepo
(
t
,
repo
)
commitId
,
_
:=
seedTestRepo
(
t
,
repo
)
commit
,
err
:=
repo
.
LookupCommit
(
commitId
)
checkFatal
(
t
,
err
)
shortId
,
err
:=
commit
.
ShortId
()
checkFatal
(
t
,
err
)
checkShortId
(
t
,
commitId
.
String
(),
shortId
)
}
func
TestObjectPeel
(
t
*
testing
.
T
)
{
func
TestObjectPeel
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
repo
:=
createTestRepo
(
t
)
repo
:=
createTestRepo
(
t
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment