Skip to content

Commit

Permalink
Add spatial-filter extension in contrib/filter-extensions
Browse files Browse the repository at this point in the history
See Makefile for build instructions.
  • Loading branch information
olsen232 authored and rcoup committed May 15, 2024
1 parent a55d758 commit 5be46a8
Show file tree
Hide file tree
Showing 4 changed files with 539 additions and 0 deletions.
39 changes: 39 additions & 0 deletions contrib/filter-extensions/spatial/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Run this from the main git directory. That way we inherit useful variables.
#
# make FILTER_EXTENSIONS=contrib/filter-extensions/spatial/spatial.a \
# LDFLAGS=-lstdc++ \
# EXTENSION_LIBS=-lsqlite3
#

ifneq ($(findstring s,$(MAKEFLAGS)),s)
ifndef V
QUIET_CC = @echo ' ' CC $@;
QUIET_CXX = @echo ' ' CXX $@;
QUIET_AR = @echo ' ' AR $@;
endif
endif

FILTER_STATIC_LIB = spatial.a

FILTER_CFLAGS = -std=c99 -I../../..
FILTER_CXXFLAGS = -std=c++11

all: $(FILTER_STATIC_LIB)
ifeq ($(MAKELEVEL),0)
$(error "Run via parent git make")
endif
@:

$(FILTER_STATIC_LIB): spatial_filter.o adapter_functions.o
$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^

spatial_filter.o: spatial_filter.cpp
$(QUIET_CXX)$(CXX) -c $(ALL_CFLAGS) $(FILTER_CFLAGS) $(ALL_CXXFLAGS) $(FILTER_CXXFLAGS) $<

adapter_functions.o: adapter_functions.c
$(QUIET_CC)$(CC) -c $(ALL_CFLAGS) $(FILTER_CFLAGS) $<

clean:
$(RM) *.a *.o

.PHONY: all clean
41 changes: 41 additions & 0 deletions contrib/filter-extensions/spatial/adapter_functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <git-compat-util.h>
#include <hash.h>
#include <object.h>
#include <repository.h>
#include <trace.h>

#include "adapter_functions.h"

// Allows access to C structs or functions that are defined
// in C++ incompatible headers.

void sf_trace_printf(const char* format, ...) {
static struct trace_key key = TRACE_KEY_INIT(FILTER);
struct strbuf buf = STRBUF_INIT;
va_list args;
va_start(args, format);
strbuf_vaddf(&buf, format, args);
va_end(args);
trace_strbuf(&key, &buf);
strbuf_release(&buf);
}

const struct object_id* sf_obj2oid(const struct object *obj) {
return &obj->oid;
}

const unsigned char* sf_oid2hash(const struct object_id *oid) {
return oid->hash;
}

unsigned sf_obj2type(const struct object *obj) {
return obj->type;
}

const char* sf_repo2gitdir(const struct repository *repo) {
return repo->gitdir;
}

int sf_repo2hashsz(const struct repository *repo) {
return repo->hash_algo->rawsz;
}
29 changes: 29 additions & 0 deletions contrib/filter-extensions/spatial/adapter_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef SPATIAL_FILTER_ADAPTER_FUNCTIONS_H
#define SPATIAL_FILTER_ADAPTER_FUNCTIONS_H

// C++ compatible header that allows access to C structs
// or functions that are defined in C++ incompatible headers.

// From trace.h
uint64_t getnanotime(void);

// Delegates to trace_strbuf from trace.h
void sf_trace_printf(const char* format, ...);

struct object;
struct object_id;

// Accessors for struct object from object.h
const struct object_id* sf_obj2oid(const struct object *obj);
unsigned sf_obj2type(const struct object *obj);

// Accessors for struct object_id from hash.h
const unsigned char* sf_oid2hash(const struct object_id *oid);

struct repository;

// Accessors for struct repository from repository.h
const char* sf_repo2gitdir(const struct repository *repo);
int sf_repo2hashsz(const struct repository *repo);

#endif /* SPATIAL_FILTER_ADAPTER_FUNCTIONS_H */
Loading

0 comments on commit 5be46a8

Please sign in to comment.