vendor: update ostree-go

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2018-11-13 10:34:12 +01:00
parent 6f2ae41211
commit dd6e8cc3a3
No known key found for this signature in database
GPG key ID: E4730F97F60286ED
47 changed files with 208 additions and 215 deletions

View file

@ -18,76 +18,102 @@ import (
// #include "builtin.go.h" // #include "builtin.go.h"
import "C" import "C"
// Repo represents a local ostree repository
type Repo struct { type Repo struct {
//*glib.GObject
ptr unsafe.Pointer ptr unsafe.Pointer
} }
// Converts an ostree repo struct to its C equivalent // isInitialized checks if the repo has been initialized
func (r *Repo) isInitialized() bool {
if r == nil || r.ptr == nil {
return false
}
return true
}
// native converts an ostree repo struct to its C equivalent
func (r *Repo) native() *C.OstreeRepo { func (r *Repo) native() *C.OstreeRepo {
//return (*C.OstreeRepo)(r.Ptr()) if !r.isInitialized() {
return nil
}
return (*C.OstreeRepo)(r.ptr) return (*C.OstreeRepo)(r.ptr)
} }
// Takes a C ostree repo and converts it to a Go struct // repoFromNative takes a C ostree repo and converts it to a Go struct
func repoFromNative(p *C.OstreeRepo) *Repo { func repoFromNative(or *C.OstreeRepo) *Repo {
if p == nil { if or == nil {
return nil return nil
} }
//o := (*glib.GObject)(unsafe.Pointer(p)) r := &Repo{unsafe.Pointer(or)}
//r := &Repo{o}
r := &Repo{unsafe.Pointer(p)}
return r return r
} }
// Checks if the repo has been initialized // OpenRepo attempts to open the repo at the given path
func (r *Repo) isInitialized() bool { func OpenRepo(path string) (*Repo, error) {
if r.ptr != nil { if path == "" {
return true return nil, errors.New("empty path")
}
return false
} }
// Attempts to open the repo at the given path
func OpenRepo(path string) (*Repo, error) {
var cerr *C.GError = nil
cpath := C.CString(path) cpath := C.CString(path)
pathc := C.g_file_new_for_path(cpath) defer C.free(unsafe.Pointer(cpath))
defer C.g_object_unref(C.gpointer(pathc)) repoPath := C.g_file_new_for_path(cpath)
crepo := C.ostree_repo_new(pathc) defer C.g_object_unref(C.gpointer(repoPath))
crepo := C.ostree_repo_new(repoPath)
repo := repoFromNative(crepo) repo := repoFromNative(crepo)
var cerr *C.GError
r := glib.GoBool(glib.GBoolean(C.ostree_repo_open(crepo, nil, &cerr))) r := glib.GoBool(glib.GBoolean(C.ostree_repo_open(crepo, nil, &cerr)))
if !r { if !r {
return nil, generateError(cerr) return nil, generateError(cerr)
} }
return repo, nil return repo, nil
} }
// Enable support for tombstone commits, which allow the repo to distinguish between // enableTombstoneCommits enables support for tombstone commits.
// commits that were intentionally deleted and commits that were removed accidentally //
func enableTombstoneCommits(repo *Repo) error { // This allows to distinguish between intentional deletions and accidental removals
var tombstoneCommits bool // of commits.
var config *C.GKeyFile = C.ostree_repo_get_config(repo.native()) func (r *Repo) enableTombstoneCommits() error {
var cerr *C.GError if !r.isInitialized() {
return errors.New("repo not initialized")
}
tombstoneCommits = glib.GoBool(glib.GBoolean(C.g_key_file_get_boolean(config, (*C.gchar)(C.CString("core")), (*C.gchar)(C.CString("tombstone-commits")), nil))) config := C.ostree_repo_get_config(r.native())
groupC := C.CString("core")
defer C.free(unsafe.Pointer(groupC))
keyC := C.CString("tombstone-commits")
defer C.free(unsafe.Pointer(keyC))
valueC := C.g_key_file_get_boolean(config, (*C.gchar)(groupC), (*C.gchar)(keyC), nil)
tombstoneCommits := glib.GoBool(glib.GBoolean(valueC))
// tombstoneCommits is false only if it really is false or if it is set to FALSE in the config file // tombstoneCommits is false only if it really is false or if it is set to FALSE in the config file
if !tombstoneCommits { if !tombstoneCommits {
C.g_key_file_set_boolean(config, (*C.gchar)(C.CString("core")), (*C.gchar)(C.CString("tombstone-commits")), C.TRUE) var cerr *C.GError
if !glib.GoBool(glib.GBoolean(C.ostree_repo_write_config(repo.native(), config, &cerr))) { C.g_key_file_set_boolean(config, (*C.gchar)(groupC), (*C.gchar)(keyC), C.TRUE)
if !glib.GoBool(glib.GBoolean(C.ostree_repo_write_config(r.native(), config, &cerr))) {
return generateError(cerr) return generateError(cerr)
} }
} }
return nil return nil
} }
// generateError wraps a GLib error into a Go one.
func generateError(err *C.GError) error { func generateError(err *C.GError) error {
if err == nil {
return errors.New("nil GError")
}
goErr := glib.ConvertGError(glib.ToGError(unsafe.Pointer(err))) goErr := glib.ConvertGError(glib.ToGError(unsafe.Pointer(err)))
_, file, line, ok := runtime.Caller(1) _, file, line, ok := runtime.Caller(1)
if ok { if ok {
return errors.New(fmt.Sprintf("%s:%d - %s", file, line, goErr)) return fmt.Errorf("%s:%d - %s", file, line, goErr)
} else { }
return goErr return goErr
} }
// isOk wraps a return value (gboolean/gint) into a bool.
// 0 is false/error, everything else is true/ok.
func isOk(v C.int) bool {
return glib.GoBool(glib.GBoolean(v))
} }

View file

@ -33,24 +33,12 @@ _ostree_repo_file(GFile *file)
return OSTREE_REPO_FILE (file); return OSTREE_REPO_FILE (file);
} }
static guint
_gpointer_to_uint (gpointer ptr)
{
return GPOINTER_TO_UINT (ptr);
}
static gpointer static gpointer
_guint_to_pointer (guint u) _guint_to_pointer (guint u)
{ {
return GUINT_TO_POINTER (u); return GUINT_TO_POINTER (u);
} }
static void
_g_clear_object (volatile GObject **object_ptr)
{
g_clear_object(object_ptr);
}
static const GVariantType* static const GVariantType*
_g_variant_type (char *type) _g_variant_type (char *type)
{ {

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1,7 +1,7 @@
package otbuiltin package otbuiltin
import ( import (
"strings" "errors"
"unsafe" "unsafe"
glib "github.com/ostreedev/ostree-go/pkg/glibobject" glib "github.com/ostreedev/ostree-go/pkg/glibobject"
@ -14,34 +14,42 @@ import (
// #include "builtin.go.h" // #include "builtin.go.h"
import "C" import "C"
// Global variable for options // checkoutOptions defines all of the options for checking commits
var checkoutOpts checkoutOptions // out of an ostree repo
//
// Contains all of the options for checking commits out of // Note: while this is private, fields are public and part of the API.
// an ostree repo
type checkoutOptions struct { type checkoutOptions struct {
UserMode bool // Do not change file ownership or initialize extended attributes // UserMode defines whether to checkout a repo in `bare-user` mode
Union bool // Keep existing directories and unchanged files, overwriting existing filesystem UserMode bool
AllowNoent bool // Do nothing if the specified filepath does not exist // Union specifies whether to overwrite existing filesystem entries
DisableCache bool // Do not update or use the internal repository uncompressed object caceh Union bool
Whiteouts bool // Process 'whiteout' (docker style) entries // AllowNoEnt defines whether to skip filepaths that do not exist
RequireHardlinks bool // Do not fall back to full copies if hard linking fails AllowNoent bool
Subpath string // Checkout sub-directory path // DisableCache defines whether to disable internal repository uncompressed object cache
FromFile string // Process many checkouts from the given file DisableCache bool
// Whiteouts defines whether to Process 'whiteout' (docker style) entries
Whiteouts bool
// RequireHardlinks defines whether to fall back to full copies if hard linking fails
RequireHardlinks bool
// SubPath specifies a sub-directory to use for checkout
Subpath string
// FromFile specifies an optional file containing many checkouts to process
FromFile string
} }
// Instantiates and returns a checkoutOptions struct with default values set // NewCheckoutOptions instantiates and returns a checkoutOptions struct with default values set
func NewCheckoutOptions() checkoutOptions { func NewCheckoutOptions() checkoutOptions {
return checkoutOptions{} return checkoutOptions{}
} }
// Checks out a commit with the given ref from a repository at the location of repo path to to the destination. Returns an error if the checkout could not be processed // Checkout checks out commit `commitRef` from a repository at `repoPath`,
func Checkout(repoPath, destination, commit string, opts checkoutOptions) error { // writing it to `destination`. Returns an error if the checkout could not be processed.
checkoutOpts = opts func Checkout(repoPath, destination, commitRef string, opts checkoutOptions) error {
var cancellable *glib.GCancellable var cancellable *glib.GCancellable
ccommit := C.CString(commit)
ccommit := C.CString(commitRef)
defer C.free(unsafe.Pointer(ccommit)) defer C.free(unsafe.Pointer(ccommit))
var gerr = glib.NewGError() var gerr = glib.NewGError()
cerr := (*C.GError)(gerr.Ptr()) cerr := (*C.GError)(gerr.Ptr())
defer C.free(unsafe.Pointer(cerr)) defer C.free(unsafe.Pointer(cerr))
@ -53,50 +61,48 @@ func Checkout(repoPath, destination, commit string, opts checkoutOptions) error
return generateError(cerr) return generateError(cerr)
} }
if strings.Compare(checkoutOpts.FromFile, "") != 0 { // Multiple checkouts to process
err := processManyCheckouts(crepo, destination, cancellable) if opts.FromFile != "" {
if err != nil { return processManyCheckouts(crepo, destination, cancellable)
return err
} }
} else {
// Simple single checkout
var resolvedCommit *C.char var resolvedCommit *C.char
defer C.free(unsafe.Pointer(resolvedCommit)) defer C.free(unsafe.Pointer(resolvedCommit))
if !glib.GoBool(glib.GBoolean(C.ostree_repo_resolve_rev(crepo, ccommit, C.FALSE, &resolvedCommit, &cerr))) { if !glib.GoBool(glib.GBoolean(C.ostree_repo_resolve_rev(crepo, ccommit, C.FALSE, &resolvedCommit, &cerr))) {
return generateError(cerr) return generateError(cerr)
} }
err := processOneCheckout(crepo, resolvedCommit, checkoutOpts.Subpath, destination, cancellable)
if err != nil { return processOneCheckout(crepo, resolvedCommit, destination, opts, cancellable)
return err
}
}
return nil
} }
// Processes one checkout from the repo // processOneCheckout processes one checkout from the repo
func processOneCheckout(crepo *C.OstreeRepo, resolvedCommit *C.char, subpath, destination string, cancellable *glib.GCancellable) error { func processOneCheckout(crepo *C.OstreeRepo, resolvedCommit *C.char, destination string, opts checkoutOptions, cancellable *glib.GCancellable) error {
cdest := C.CString(destination) cdest := C.CString(destination)
defer C.free(unsafe.Pointer(cdest)) defer C.free(unsafe.Pointer(cdest))
var gerr = glib.NewGError() var gerr = glib.NewGError()
cerr := (*C.GError)(gerr.Ptr()) cerr := (*C.GError)(gerr.Ptr())
defer C.free(unsafe.Pointer(cerr)) defer C.free(unsafe.Pointer(cerr))
var repoCheckoutAtOptions C.OstreeRepoCheckoutAtOptions
if checkoutOpts.UserMode { // Process options into bitflags
var repoCheckoutAtOptions C.OstreeRepoCheckoutAtOptions
if opts.UserMode {
repoCheckoutAtOptions.mode = C.OSTREE_REPO_CHECKOUT_MODE_USER repoCheckoutAtOptions.mode = C.OSTREE_REPO_CHECKOUT_MODE_USER
} }
if checkoutOpts.Union { if opts.Union {
repoCheckoutAtOptions.overwrite_mode = C.OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES repoCheckoutAtOptions.overwrite_mode = C.OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES
} }
checkedOut := glib.GoBool(glib.GBoolean(C.ostree_repo_checkout_at(crepo, &repoCheckoutAtOptions, C._at_fdcwd(), cdest, resolvedCommit, nil, &cerr))) // Checkout commit to destination
if !checkedOut { if !glib.GoBool(glib.GBoolean(C.ostree_repo_checkout_at(crepo, &repoCheckoutAtOptions, C._at_fdcwd(), cdest, resolvedCommit, nil, &cerr))) {
return generateError(cerr) return generateError(cerr)
} }
return nil return nil
} }
// process many checkouts // processManyCheckouts processes many checkouts in a single batch
func processManyCheckouts(crepo *C.OstreeRepo, target string, cancellable *glib.GCancellable) error { func processManyCheckouts(crepo *C.OstreeRepo, target string, cancellable *glib.GCancellable) error {
return nil return errors.New("batch checkouts processing: not implemented")
} }

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -125,6 +125,7 @@ func (repo *Repo) RegenerateSummary() error {
// Commits a directory, specified by commitPath, to an ostree repo as a given branch // Commits a directory, specified by commitPath, to an ostree repo as a given branch
func (repo *Repo) Commit(commitPath, branch string, opts commitOptions) (string, error) { func (repo *Repo) Commit(commitPath, branch string, opts commitOptions) (string, error) {
// TODO(lucab): `options` is global un-synchronized mutable state, get rid of it.
options = opts options = opts
var err error var err error
@ -196,7 +197,7 @@ func (repo *Repo) Commit(commitPath, branch string, opts commitOptions) (string,
} }
if options.AddDetachedMetadataString != nil { if options.AddDetachedMetadataString != nil {
_, err := parseKeyValueStrings(options.AddDetachedMetadataString) _, err = parseKeyValueStrings(options.AddDetachedMetadataString)
if err != nil { if err != nil {
goto out goto out
} }

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1,11 +1,8 @@
package otbuiltin package otbuiltin
import ( import (
"errors"
"strings" "strings"
"unsafe" "unsafe"
glib "github.com/ostreedev/ostree-go/pkg/glibobject"
) )
// #cgo pkg-config: ostree-1 // #cgo pkg-config: ostree-1
@ -15,43 +12,37 @@ import (
// #include "builtin.go.h" // #include "builtin.go.h"
import "C" import "C"
// Declare variables for options // initOptions contains all of the options for initializing an ostree repo
var initOpts initOptions //
// Note: while this is private, exported fields are public and part of the API.
// Contains all of the options for initializing an ostree repo
type initOptions struct { type initOptions struct {
Mode string // either bare, archive-z2, or bare-user // Mode defines repository mode: either bare, archive-z2, or bare-user
Mode string
repoMode C.OstreeRepoMode
} }
// Instantiates and returns an initOptions struct with default values set // NewInitOptions instantiates and returns an initOptions struct with default values set
func NewInitOptions() initOptions { func NewInitOptions() initOptions {
io := initOptions{} return initOptions{
io.Mode = "bare" Mode: "bare",
io.repoMode = C.OSTREE_REPO_MODE_BARE }
return io
} }
// Initializes a new ostree repository at the given path. Returns true // Init initializes a new ostree repository at the given path. Returns true
// if the repo exists at the location, regardless of whether it was initialized // if the repo exists at the location, regardless of whether it was initialized
// by the function or if it already existed. Returns an error if the repo could // by the function or if it already existed. Returns an error if the repo could
// not be initialized // not be initialized
func Init(path string, options initOptions) (bool, error) { func Init(path string, options initOptions) (bool, error) {
initOpts = options repoMode, err := parseRepoMode(options.Mode)
err := parseMode()
if err != nil { if err != nil {
return false, err return false, err
} }
// Create a repo struct from the path // Create a repo struct from the path
var cerr *C.GError
defer C.free(unsafe.Pointer(cerr))
cpath := C.CString(path) cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath)) defer C.free(unsafe.Pointer(cpath))
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) repo := C.ostree_repo_new(pathc)
// If the repo exists in the filesystem, return an error but set exists to true // If the repo exists in the filesystem, return an error but set exists to true
/* var exists C.gboolean = 0 /* var exists C.gboolean = 0
@ -63,28 +54,31 @@ func Init(path string, options initOptions) (bool, error) {
return false, generateError(cerr) return false, generateError(cerr)
}*/ }*/
cerr = nil var cErr *C.GError
created := glib.GoBool(glib.GBoolean(C.ostree_repo_create(crepo, initOpts.repoMode, nil, &cerr))) defer C.free(unsafe.Pointer(cErr))
if !created { if r := C.ostree_repo_create(repo, repoMode, nil, &cErr); !isOk(r) {
errString := generateError(cerr).Error() err := generateError(cErr)
if strings.Contains(errString, "File exists") { if strings.Contains(err.Error(), "File exists") {
return true, generateError(cerr) return true, err
} }
return false, generateError(cerr) return false, err
} }
return true, nil return true, nil
} }
// Converts the mode string to a C.OSTREE_REPO_MODE enum value // parseRepoMode converts a mode string to a C.OSTREE_REPO_MODE enum value
func parseMode() error { func parseRepoMode(modeLabel string) (C.OstreeRepoMode, error) {
if strings.EqualFold(initOpts.Mode, "bare") { var cErr *C.GError
initOpts.repoMode = C.OSTREE_REPO_MODE_BARE defer C.free(unsafe.Pointer(cErr))
} else if strings.EqualFold(initOpts.Mode, "bare-user") {
initOpts.repoMode = C.OSTREE_REPO_MODE_BARE_USER cModeLabel := C.CString(modeLabel)
} else if strings.EqualFold(initOpts.Mode, "archive-z2") { defer C.free(unsafe.Pointer(cModeLabel))
initOpts.repoMode = C.OSTREE_REPO_MODE_ARCHIVE_Z2
} else { var retMode C.OstreeRepoMode
return errors.New("Invalid option for mode") if r := C.ostree_repo_mode_from_string(cModeLabel, &retMode, &cErr); !isOk(r) {
// NOTE(lucab): zero-value for this C enum has no special/invalid meaning.
return C.OSTREE_REPO_MODE_BARE, generateError(cErr)
} }
return nil
return retMode, nil
} }

View file

@ -2,7 +2,6 @@ package otbuiltin
import ( import (
"fmt" "fmt"
"strings"
"time" "time"
"unsafe" "unsafe"
@ -16,13 +15,7 @@ import (
// #include "builtin.go.h" // #include "builtin.go.h"
import "C" import "C"
// Declare variables for options // LogEntry is a struct for the various pieces of data in a log entry
var logOpts logOptions
// Set the format of the strings in the log
const formatString = "2006-01-02 03:04;05 -0700"
// Struct for the various pieces of data in a log entry
type LogEntry struct { type LogEntry struct {
Checksum []byte Checksum []byte
Variant []byte Variant []byte
@ -39,24 +32,25 @@ func (l LogEntry) String() string {
return fmt.Sprintf("%s\n%s\n\n", l.Checksum, l.Variant) return fmt.Sprintf("%s\n%s\n\n", l.Checksum, l.Variant)
} }
type OstreeDumpFlags uint type ostreeDumpFlags uint
const ( const (
OSTREE_DUMP_NONE OstreeDumpFlags = 0 ostreeDumpNone ostreeDumpFlags = 0
OSTREE_DUMP_RAW OstreeDumpFlags = 1 << iota ostreeDumpRaw ostreeDumpFlags = 1 << iota
) )
// Contains all of the options for initializing an ostree repo // logOptions contains all of the options for initializing an ostree repo
type logOptions struct { type logOptions struct {
Raw bool // Show raw variant data // Raw determines whether to show raw variant data
Raw bool
} }
//Instantiates and returns a logOptions struct with default values set // NewLogOptions instantiates and returns a logOptions struct with default values set
func NewLogOptions() logOptions { func NewLogOptions() logOptions {
return logOptions{} return logOptions{}
} }
// Show the logs of a branch starting with a given commit or ref. Returns a // Log shows the logs of a branch starting with a given commit or ref. Returns a
// slice of log entries on success and an error otherwise // slice of log entries on success and an error otherwise
func Log(repoPath, branch string, options logOptions) ([]LogEntry, error) { func Log(repoPath, branch string, options logOptions) ([]LogEntry, error) {
// attempt to open the repository // attempt to open the repository
@ -69,12 +63,12 @@ func Log(repoPath, branch string, options logOptions) ([]LogEntry, error) {
defer C.free(unsafe.Pointer(cbranch)) defer C.free(unsafe.Pointer(cbranch))
var checksum *C.char var checksum *C.char
defer C.free(unsafe.Pointer(checksum)) defer C.free(unsafe.Pointer(checksum))
var flags OstreeDumpFlags = OSTREE_DUMP_NONE
var cerr *C.GError var cerr *C.GError
defer C.free(unsafe.Pointer(cerr)) defer C.free(unsafe.Pointer(cerr))
if logOpts.Raw { flags := ostreeDumpNone
flags |= OSTREE_DUMP_RAW if options.Raw {
flags |= ostreeDumpRaw
} }
if !glib.GoBool(glib.GBoolean(C.ostree_repo_resolve_rev(repo.native(), cbranch, C.FALSE, &checksum, &cerr))) { if !glib.GoBool(glib.GBoolean(C.ostree_repo_resolve_rev(repo.native(), cbranch, C.FALSE, &checksum, &cerr))) {
@ -84,84 +78,86 @@ func Log(repoPath, branch string, options logOptions) ([]LogEntry, error) {
return logCommit(repo, checksum, false, flags) return logCommit(repo, checksum, false, flags)
} }
func logCommit(repo *Repo, checksum *C.char, isRecursive bool, flags OstreeDumpFlags) ([]LogEntry, error) { func logCommit(repo *Repo, checksum *C.char, isRecursive bool, flags ostreeDumpFlags) ([]LogEntry, error) {
var variant *C.GVariant var variant *C.GVariant
var parent *C.char
defer C.free(unsafe.Pointer(parent))
var gerr = glib.NewGError() var gerr = glib.NewGError()
var cerr = (*C.GError)(gerr.Ptr()) var cerr = (*C.GError)(gerr.Ptr())
defer C.free(unsafe.Pointer(cerr)) defer C.free(unsafe.Pointer(cerr))
entries := make([]LogEntry, 0, 1)
var err error
if !glib.GoBool(glib.GBoolean(C.ostree_repo_load_variant(repo.native(), C.OSTREE_OBJECT_TYPE_COMMIT, checksum, &variant, &cerr))) { if !glib.GoBool(glib.GBoolean(C.ostree_repo_load_variant(repo.native(), C.OSTREE_OBJECT_TYPE_COMMIT, checksum, &variant, &cerr))) {
if isRecursive && glib.GoBool(glib.GBoolean(C.g_error_matches(cerr, C.g_io_error_quark(), C.G_IO_ERROR_NOT_FOUND))) { if isRecursive && glib.GoBool(glib.GBoolean(C.g_error_matches(cerr, C.g_io_error_quark(), C.G_IO_ERROR_NOT_FOUND))) {
return nil, nil return nil, nil
} }
return entries, generateError(cerr) return nil, generateError(cerr)
} }
nextLogEntry := dumpLogObject(C.OSTREE_OBJECT_TYPE_COMMIT, checksum, variant, flags) // Get the parent of this commit
parent := (*C.char)(C.ostree_commit_get_parent(variant))
// get the parent of this commit
parent = (*C.char)(C.ostree_commit_get_parent(variant))
defer C.free(unsafe.Pointer(parent)) defer C.free(unsafe.Pointer(parent))
entries := make([]LogEntry, 0, 1)
if parent != nil { if parent != nil {
var err error
entries, err = logCommit(repo, parent, true, flags) entries, err = logCommit(repo, parent, true, flags)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
entries = append(entries, *nextLogEntry)
nextLogEntry := dumpLogObject(C.OSTREE_OBJECT_TYPE_COMMIT, checksum, variant, flags)
entries = append(entries, nextLogEntry)
return entries, nil return entries, nil
} }
func dumpLogObject(objectType C.OstreeObjectType, checksum *C.char, variant *C.GVariant, flags OstreeDumpFlags) *LogEntry { func dumpLogObject(objectType C.OstreeObjectType, checksum *C.char, variant *C.GVariant, flags ostreeDumpFlags) LogEntry {
objLog := new(LogEntry) csum := []byte(C.GoString(checksum))
objLog.Checksum = []byte(C.GoString(checksum))
if (flags & OSTREE_DUMP_RAW) != 0 { if (flags & ostreeDumpRaw) != 0 {
dumpVariant(objLog, variant) return dumpVariant(variant, csum)
return objLog
} }
switch objectType { switch objectType {
case C.OSTREE_OBJECT_TYPE_COMMIT: case C.OSTREE_OBJECT_TYPE_COMMIT:
dumpCommit(objLog, variant, flags) return dumpCommit(variant, flags, csum)
return objLog
default: default:
return objLog return LogEntry{
Checksum: csum,
}
} }
} }
func dumpVariant(log *LogEntry, variant *C.GVariant) { func dumpVariant(variant *C.GVariant, csum []byte) LogEntry {
var byteswappedVariant *C.GVariant var logVariant []byte
if C.G_BYTE_ORDER != C.G_BIG_ENDIAN { if C.G_BYTE_ORDER != C.G_BIG_ENDIAN {
byteswappedVariant = C.g_variant_byteswap(variant) byteswappedVariant := C.g_variant_byteswap(variant)
log.Variant = []byte(C.GoString((*C.char)(C.g_variant_print(byteswappedVariant, C.TRUE)))) logVariant = []byte(C.GoString((*C.char)(C.g_variant_print(byteswappedVariant, C.TRUE))))
} else { } else {
log.Variant = []byte(C.GoString((*C.char)(C.g_variant_print(byteswappedVariant, C.TRUE)))) logVariant = []byte(C.GoString((*C.char)(C.g_variant_print(variant, C.TRUE))))
}
return LogEntry{
Checksum: csum,
Variant: logVariant,
} }
} }
func dumpCommit(log *LogEntry, variant *C.GVariant, flags OstreeDumpFlags) { func dumpCommit(variant *C.GVariant, flags ostreeDumpFlags, csum []byte) LogEntry {
var subject, body *C.char var subject *C.char
defer C.free(unsafe.Pointer(subject)) defer C.free(unsafe.Pointer(subject))
var body *C.char
defer C.free(unsafe.Pointer(body)) defer C.free(unsafe.Pointer(body))
var timestamp C.guint64 var timeBigE C.guint64
C._g_variant_get_commit_dump(variant, C.CString("(a{sv}aya(say)&s&stayay)"), &subject, &body, &timestamp) C._g_variant_get_commit_dump(variant, C.CString("(a{sv}aya(say)&s&stayay)"), &subject, &body, &timeBigE)
// Timestamp is now a Unix formatted timestamp as a guint64 // Translate to a host-endian epoch and convert to Go timestamp
timestamp = C._guint64_from_be(timestamp) timeHostE := C._guint64_from_be(timeBigE)
log.Timestamp = time.Unix((int64)(timestamp), 0) timestamp := time.Unix((int64)(timeHostE), 0)
if strings.Compare(C.GoString(subject), "") != 0 { return LogEntry{
log.Subject = C.GoString(subject) Timestamp: timestamp,
} Subject: C.GoString(subject),
Body: C.GoString(body),
if strings.Compare(C.GoString(body), "") != 0 {
log.Body = C.GoString(body)
} }
} }

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -145,7 +145,7 @@ func deleteCommit(repo *Repo, commitToDelete string, cancellable *glib.GCancella
} }
} }
if err := enableTombstoneCommits(repo); err != nil { if err := repo.enableTombstoneCommits(); err != nil {
return err return err
} }
@ -169,7 +169,7 @@ func pruneCommitsKeepYoungerThanDate(repo *Repo, date time.Time, cancellable *gl
var cerr = (*C.GError)(gerr.Ptr()) var cerr = (*C.GError)(gerr.Ptr())
defer C.free(unsafe.Pointer(cerr)) defer C.free(unsafe.Pointer(cerr))
if err := enableTombstoneCommits(repo); err != nil { if err := repo.enableTombstoneCommits(); err != nil {
return err return err
} }

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin

View file

@ -1 +0,0 @@
package otbuiltin