contrib: indent golang code using only tabs instead of both tabs and spaces
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #242 Approved by: cgwalters
This commit is contained in:
parent
7763c452dd
commit
6a091c96ba
|
|
@ -47,50 +47,50 @@ func GoBool(b C.gboolean) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GError struct {
|
type GError struct {
|
||||||
ptr unsafe.Pointer
|
ptr unsafe.Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGError() GError {
|
func NewGError() GError {
|
||||||
return GError{nil}
|
return GError{nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GError) Native() *C.GError {
|
func (e *GError) Native() *C.GError {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (*C.GError)(e.ptr)
|
return (*C.GError)(e.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertGError(e *C.GError) error {
|
func ConvertGError(e *C.GError) error {
|
||||||
defer C.g_error_free(e)
|
defer C.g_error_free(e)
|
||||||
return errors.New(C.GoString((*C.char)(C._g_error_get_message(e))))
|
return errors.New(C.GoString((*C.char)(C._g_error_get_message(e))))
|
||||||
}
|
}
|
||||||
|
|
||||||
type GType uint
|
type GType uint
|
||||||
|
|
||||||
func (t GType) Name() string {
|
func (t GType) Name() string {
|
||||||
return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
|
return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
|
||||||
}
|
}
|
||||||
|
|
||||||
type GVariant struct {
|
type GVariant struct {
|
||||||
ptr unsafe.Pointer
|
ptr unsafe.Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
func GVariantNew(p unsafe.Pointer) *GVariant {
|
func GVariantNew(p unsafe.Pointer) *GVariant {
|
||||||
o := &GVariant{p}
|
o := &GVariant{p}
|
||||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
func GVariantNewSink(p unsafe.Pointer) *GVariant {
|
func GVariantNewSink(p unsafe.Pointer) *GVariant {
|
||||||
o := &GVariant{p}
|
o := &GVariant{p}
|
||||||
runtime.SetFinalizer(o, (*GVariant).Unref)
|
runtime.SetFinalizer(o, (*GVariant).Unref)
|
||||||
o.RefSink()
|
o.RefSink()
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GVariant) native() *C.GVariant {
|
func (v *GVariant) native() *C.GVariant {
|
||||||
return (*C.GVariant)(v.ptr);
|
return (*C.GVariant)(v.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GVariant) Ref() {
|
func (v *GVariant) Ref() {
|
||||||
|
|
@ -98,7 +98,7 @@ func (v *GVariant) Ref() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GVariant) Unref() {
|
func (v *GVariant) Unref() {
|
||||||
C.g_variant_unref(v.native())
|
C.g_variant_unref(v.native())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GVariant) RefSink() {
|
func (v *GVariant) RefSink() {
|
||||||
|
|
@ -116,14 +116,14 @@ func (v *GVariant) GetChildValue(i int) *GVariant {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GVariant) LookupString(key string) (string, error) {
|
func (v *GVariant) LookupString(key string) (string, error) {
|
||||||
ckey := C.CString(key)
|
ckey := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(ckey))
|
defer C.free(unsafe.Pointer(ckey))
|
||||||
// TODO: Find a way to have constant C strings in golang
|
// TODO: Find a way to have constant C strings in golang
|
||||||
cstr := C._g_variant_lookup_string(v.native(), ckey)
|
cstr := C._g_variant_lookup_string(v.native(), ckey)
|
||||||
if cstr == nil {
|
if cstr == nil {
|
||||||
return "", fmt.Errorf("No such key: %s", key)
|
return "", fmt.Errorf("No such key: %s", key)
|
||||||
}
|
}
|
||||||
return C.GoString(cstr), nil
|
return C.GoString(cstr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -144,9 +144,9 @@ type GObject struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GObjectNew(p unsafe.Pointer) *GObject {
|
func GObjectNew(p unsafe.Pointer) *GObject {
|
||||||
o := &GObject{p}
|
o := &GObject{p}
|
||||||
runtime.SetFinalizer(o, (*GObject).Unref)
|
runtime.SetFinalizer(o, (*GObject).Unref)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GObject) Ptr() unsafe.Pointer {
|
func (v *GObject) Ptr() unsafe.Pointer {
|
||||||
|
|
@ -172,7 +172,7 @@ func (v *GObject) Ref() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GObject) Unref() {
|
func (v *GObject) Unref() {
|
||||||
C.g_object_unref(C.gpointer(v.ptr))
|
C.g_object_unref(C.gpointer(v.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *GObject) RefSink() {
|
func (v *GObject) RefSink() {
|
||||||
|
|
@ -191,7 +191,7 @@ func (v *GObject) ForceFloating() {
|
||||||
// GIO types
|
// GIO types
|
||||||
|
|
||||||
type GCancellable struct {
|
type GCancellable struct {
|
||||||
*GObject
|
*GObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *GCancellable) native() *C.GCancellable {
|
func (self *GCancellable) native() *C.GCancellable {
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
*GObject
|
*GObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func RepoGetType() GType {
|
func RepoGetType() GType {
|
||||||
return GType(C.ostree_repo_get_type())
|
return GType(C.ostree_repo_get_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) native() *C.OstreeRepo {
|
func (r *Repo) native() *C.OstreeRepo {
|
||||||
|
|
@ -28,67 +28,67 @@ func (r *Repo) native() *C.OstreeRepo {
|
||||||
}
|
}
|
||||||
|
|
||||||
func repoFromNative(p *C.OstreeRepo) *Repo {
|
func repoFromNative(p *C.OstreeRepo) *Repo {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
o := GObjectNew(unsafe.Pointer(p))
|
o := GObjectNew(unsafe.Pointer(p))
|
||||||
r := &Repo{o}
|
r := &Repo{o}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func RepoNewOpen(path string) (*Repo, error) {
|
func RepoNewOpen(path string) (*Repo, error) {
|
||||||
var cerr *C.GError = nil
|
var cerr *C.GError = nil
|
||||||
cpath := C.CString(path)
|
cpath := C.CString(path)
|
||||||
pathc := C.g_file_new_for_path(cpath);
|
pathc := C.g_file_new_for_path(cpath);
|
||||||
defer C.g_object_unref(C.gpointer(pathc))
|
defer C.g_object_unref(C.gpointer(pathc))
|
||||||
crepo := C.ostree_repo_new(pathc)
|
crepo := C.ostree_repo_new(pathc)
|
||||||
repo := repoFromNative(crepo);
|
repo := repoFromNative(crepo);
|
||||||
r := GoBool(C.ostree_repo_open(repo.native(), nil, &cerr))
|
r := GoBool(C.ostree_repo_open(repo.native(), nil, &cerr))
|
||||||
if !r {
|
if !r {
|
||||||
return nil, ConvertGError(cerr)
|
return nil, ConvertGError(cerr)
|
||||||
}
|
}
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) GetParent() *Repo {
|
func (r *Repo) GetParent() *Repo {
|
||||||
return repoFromNative(C.ostree_repo_get_parent(r.native()))
|
return repoFromNative(C.ostree_repo_get_parent(r.native()))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectType int
|
type ObjectType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OBJECT_TYPE_FILE ObjectType = C.OSTREE_OBJECT_TYPE_FILE
|
OBJECT_TYPE_FILE ObjectType = C.OSTREE_OBJECT_TYPE_FILE
|
||||||
OBJECT_TYPE_DIR_TREE = C.OSTREE_OBJECT_TYPE_DIR_TREE
|
OBJECT_TYPE_DIR_TREE = C.OSTREE_OBJECT_TYPE_DIR_TREE
|
||||||
OBJECT_TYPE_DIR_META = C.OSTREE_OBJECT_TYPE_DIR_META
|
OBJECT_TYPE_DIR_META = C.OSTREE_OBJECT_TYPE_DIR_META
|
||||||
OBJECT_TYPE_COMMIT = C.OSTREE_OBJECT_TYPE_COMMIT
|
OBJECT_TYPE_COMMIT = C.OSTREE_OBJECT_TYPE_COMMIT
|
||||||
OBJECT_TYPE_TOMBSTONE_COMMIT = C.OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT
|
OBJECT_TYPE_TOMBSTONE_COMMIT = C.OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT
|
||||||
)
|
)
|
||||||
|
|
||||||
func (repo *Repo) LoadVariant(t ObjectType, checksum string) (*GVariant, error) {
|
func (repo *Repo) LoadVariant(t ObjectType, checksum string) (*GVariant, error) {
|
||||||
var cerr *C.GError = nil
|
var cerr *C.GError = nil
|
||||||
var cvariant *C.GVariant = nil
|
var cvariant *C.GVariant = nil
|
||||||
|
|
||||||
r := GoBool(C.ostree_repo_load_variant(repo.native(), C.OstreeObjectType(t), C.CString(checksum), &cvariant, &cerr))
|
r := GoBool(C.ostree_repo_load_variant(repo.native(), C.OstreeObjectType(t), C.CString(checksum), &cvariant, &cerr))
|
||||||
if !r {
|
if !r {
|
||||||
return nil, ConvertGError(cerr)
|
return nil, ConvertGError(cerr)
|
||||||
}
|
}
|
||||||
variant := GVariantNew(unsafe.Pointer(cvariant))
|
variant := GVariantNew(unsafe.Pointer(cvariant))
|
||||||
return variant, nil
|
return variant, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repo) ResolveRev(ref string) (string, error) {
|
func (repo *Repo) ResolveRev(ref string) (string, error) {
|
||||||
var cerr *C.GError = nil
|
var cerr *C.GError = nil
|
||||||
var crev *C.char = nil
|
var crev *C.char = nil
|
||||||
|
|
||||||
r := GoBool(C.ostree_repo_resolve_rev(repo.native(), C.CString(ref), GBool(true), &crev, &cerr))
|
r := GoBool(C.ostree_repo_resolve_rev(repo.native(), C.CString(ref), GBool(true), &crev, &cerr))
|
||||||
if !r {
|
if !r {
|
||||||
return "", ConvertGError(cerr)
|
return "", ConvertGError(cerr)
|
||||||
}
|
}
|
||||||
defer C.free(unsafe.Pointer(crev))
|
defer C.free(unsafe.Pointer(crev))
|
||||||
return C.GoString(crev), nil
|
return C.GoString(crev), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (commit *GVariant) CommitGetMetadataKeyString(key string) (string, error) {
|
func (commit *GVariant) CommitGetMetadataKeyString(key string) (string, error) {
|
||||||
cmeta := GVariantNew(unsafe.Pointer(C.g_variant_get_child_value(commit.native(), 0)))
|
cmeta := GVariantNew(unsafe.Pointer(C.g_variant_get_child_value(commit.native(), 0)))
|
||||||
return cmeta.LookupString(key)
|
return cmeta.LookupString(key)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,47 +9,47 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTypeName(t *testing.T) {
|
func TestTypeName(t *testing.T) {
|
||||||
name := RepoGetType().Name();
|
name := RepoGetType().Name();
|
||||||
if name != "OstreeRepo" {
|
if name != "OstreeRepo" {
|
||||||
t.Errorf("%s != OstreeRepo");
|
t.Errorf("%s != OstreeRepo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepoNew(t *testing.T) {
|
func TestRepoNew(t *testing.T) {
|
||||||
r, err := RepoNewOpen("/ostree/repo")
|
r, err := RepoNewOpen("/ostree/repo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err);
|
t.Errorf("%s", err);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parent := r.GetParent()
|
parent := r.GetParent()
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
t.Errorf("Expected no parent")
|
t.Errorf("Expected no parent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepoGetMetadataVersion(t *testing.T) {
|
func TestRepoGetMetadataVersion(t *testing.T) {
|
||||||
r, err := RepoNewOpen("/ostree/repo")
|
r, err := RepoNewOpen("/ostree/repo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err);
|
t.Errorf("%s", err);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commit,err := r.ResolveRev("rhel-atomic-host/7/x86_64/standard")
|
commit,err := r.ResolveRev("rhel-atomic-host/7/x86_64/standard")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err)
|
t.Errorf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commitv,err := r.LoadVariant(OBJECT_TYPE_COMMIT, commit)
|
commitv,err := r.LoadVariant(OBJECT_TYPE_COMMIT, commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err)
|
t.Errorf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ver, err := commitv.CommitGetMetadataKeyString("version")
|
ver, err := commitv.CommitGetMetadataKeyString("version")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err)
|
t.Errorf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ver != "7.1.3" {
|
if ver != "7.1.3" {
|
||||||
t.Errorf("expected 7.1.3")
|
t.Errorf("expected 7.1.3")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue