graphimport

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graphimport reads a CodeGraph SQLite index (.codegraph/codegraph.db) and converts its facts to the v2 graph artifact.

It links a pure-Go SQLite driver, so only the graphnest command-line tool may depend on it; server binaries must not (see boundary_test.go).

Index

Constants

View Source
const (
	StatusFresh        = "fresh"
	StatusStale        = "stale"
	StatusUnverifiable = "unverifiable"
)

Freshness statuses.

Variables

View Source
var (
	ErrNotCodeGraph      = errors.New("not a CodeGraph index")
	ErrUnsupportedSchema = errors.New("unsupported CodeGraph schema version")
	ErrIndexTooLarge     = errors.New("CodeGraph index exceeds import limits")
)

Errors returned by Read. Detail is wrapped with %w, so match with errors.Is.

View Source
var ErrUnknownProducer = errors.New("unknown CodeGraph producer version")

ErrUnknownProducer means no captured rules exist for a producer version, so an index it wrote cannot be verified.

View Source
var SupportedSchemaVersions = []int{9, 10, 11}

SupportedSchemaVersions lists the CodeGraph schema versions this reader accepts (9 = CodeGraph 1.6.0; 10 and 11 = 1.6.1 and 1.6.2).

Functions

func ContentHash

func ContentHash(rules Rules, size int64, content io.Reader) (string, error)

ContentHash returns the lowercase hex SHA-256 the producer stores for a file of size bytes. Over the size limit, rules with OversizeStamp hash "codegraph:oversize:<size>" without reading content; otherwise the hash covers the UTF-8 re-encoding of the WHATWG UTF-8 decoding of the bytes (Node's Buffer.toString('utf8')): each maximal invalid subsequence becomes U+FFFD and a BOM is kept.

func IsSourceFile

func IsSourceFile(rules Rules, path string, overrides map[string]string) bool

IsSourceFile mirrors the producer's isSourceFile: Play routes, Shopify JSON, Erlang .app files, else the lowercase last-dot extension in the rules' extension map or in overrides.

Types

type Edge

type Edge struct {
	ID                   int64
	Source, Target, Kind string
	Metadata             *string
	Line, Col            *int64
	Provenance           *string
}

Edge mirrors the edges table of schema 9.

type ExecGit

type ExecGit struct{}

ExecGit implements Git with the git command-line tool.

func (ExecGit) Archive

func (ExecGit) Archive(ctx context.Context, repo, commit string) (io.ReadCloser, error)

Archive runs git -C repo archive --format=tar commit and streams its stdout.

func (ExecGit) Ignored

func (ExecGit) Ignored(ctx context.Context, patterns string, ignoreCase bool, paths []string) ([]string, error)

Ignored writes patterns to a .gitignore in a temporary repository and asks git check-ignore which of paths they ignore. Neither the user's nor the system's git configuration applies.

type File

type File struct {
	Path, ContentHash, Language string
	Size, ModifiedAt, IndexedAt int64
	NodeCount                   *int64
	Errors                      *string
	Generated                   int64
}

File mirrors the files table of schema 9.

type Freshness

type Freshness struct {
	Status      string   `json:"status"` // "fresh", "stale" or "unverifiable"
	Commit      string   `json:"commit"`
	Producer    string   `json:"producer"`      // indexed_with_version
	Compared    int      `json:"compared"`      // indexed files found at the commit and hashed
	Modified    []string `json:"modified"`      // indexed files whose content at the commit hashes differently
	NotInCommit []string `json:"not_in_commit"` // indexed files absent from the commit tree: untracked or deleted content
	NotIndexed  []string `json:"not_indexed"`   // files at the commit the producer would index that the index lacks
	Unverified  []string `json:"unverified"`    // indexed paths that are symlinks or submodules at the commit
	Virtual     int      `json:"virtual"`       // node file paths that are not files in the index
	Detail      string   `json:"detail"`
}

Freshness is the result of checking an index against the content of a commit.

func Verify

func Verify(ctx context.Context, git Git, repo, commit string, s *Snapshot, options VerifyOptions) (*Freshness, error)

Verify checks snapshot s against the content of commit in repo using the rules of the producer that wrote it. It streams the commit once and never writes to the repository.

ponytail: only the root .gitignore applies (as in the producer's flat matcher); includeIgnored, embedded repos and .git/info/exclude are not modelled, and any string is accepted as an extension override language.

type Git

type Git interface {
	// Archive streams the tree of commit as a tar archive (git archive --format=tar).
	Archive(ctx context.Context, repo, commit string) (io.ReadCloser, error)
	// Ignored evaluates gitignore patterns against relative paths and returns the ignored ones.
	Ignored(ctx context.Context, patterns string, ignoreCase bool, paths []string) ([]string, error)
}

Git is what freshness verification needs from a repository.

type MetadataEntry

type MetadataEntry struct {
	Key, Value string
	UpdatedAt  int64
}

MetadataEntry mirrors the project_metadata table of schema 9.

type Node

type Node struct {
	ID, Kind, Name, QualifiedName, FilePath, Language string
	StartLine, EndLine, StartColumn, EndColumn        int64
	Docstring, Signature, Visibility                  *string
	IsExported, IsAsync, IsStatic, IsAbstract         *int64
	Decorators, TypeParameters, ReturnType            *string
	UpdatedAt                                         int64
}

Node mirrors the nodes table of schema 9.

type Options

type Options struct {
	Repository       string            // artifact repository identity
	Commit           string            // 40 lowercase hex characters
	Producer         *graphv2.Producer // artifact producer; nil means "codegraph" at project_metadata indexed_with_version
	IdentityProducer *graphv2.Producer // producer for edge/unresolved occurrence identities; defaults to Producer
	IdentityScope    string            // repository argument of graphartifact.IdentityV2; defaults to Repository
	ImportedAt       *int64            // artifact import time; nil leaves it unset
}

Options configures Convert.

type ProjectConfig

type ProjectConfig struct {
	Extensions       map[string]string
	Exclude, Include []string
}

ProjectConfig is the part of codegraph.json at the commit that changes file selection. Malformed or absent means zero config.

type Report

type Report struct {
	Nodes, Edges, Files, Unresolved, Metadata, SynthesisInputs int
	NodeKinds, EdgeKinds                                       map[string]int
}

Report counts what Convert produced.

func Convert

func Convert(s *Snapshot, options Options) (*graphv2.Artifact, *Report, error)

Convert maps a CodeGraph snapshot to a v2 artifact without altering any fact. Each synthesis input becomes a "codegraph.synthesis-input" extension on its file. Indexes, FTS tables and name_segment_vocab are derived data and are deliberately not facts. The artifact content hash is left empty.

type Rules

type Rules struct {
	Version               string
	MaxSourceFileSize     int64
	OversizeStamp         bool // 1.6.1+: files over the limit hash "codegraph:oversize:<size>"
	ExtensionMap          map[string]string
	DefaultIgnorePatterns []string
	IgnoreCase            bool
}

Rules are the file-selection and hashing rules of one pinned CodeGraph version.

func RulesFor

func RulesFor(version string) (Rules, error)

RulesFor returns the rules for a producer version recorded in project_metadata indexed_with_version: "1.6.0" and "1.6.1"/"1.6.2". Unknown versions return ErrUnknownProducer (unverifiable), never a guess.

type Snapshot

type Snapshot struct {
	Path          string
	SchemaVersion int
	Nodes         []Node
	Edges         []Edge
	Files         []File
	Unresolved    []UnresolvedRef
	Metadata      []MetadataEntry
	// SynthesisInputs are the file paths of the synthesis_inputs table (schema 10 and 11); nil for schema 9.
	SynthesisInputs []string
	// RoundedTimestamps counts timestamp values CodeGraph stored as fractional
	// milliseconds (Node's mtimeMs kept as SQLite REAL) that were rounded.
	RoundedTimestamps int
}

Snapshot is one consistent read of a CodeGraph index. Rows keep rowid order.

func Read

func Read(ctx context.Context, path string, limits graphartifact.Limits) (*Snapshot, error)

Read loads the CodeGraph index at path in one read-only transaction. It never creates, writes, checkpoints or locks the file for writing.

func (*Snapshot) MetadataValue

func (s *Snapshot) MetadataValue(key string) (string, bool)

MetadataValue returns the project_metadata value stored under key.

type UnresolvedRef

type UnresolvedRef struct {
	ID                                       int64
	FromNodeID, ReferenceName, ReferenceKind string
	Line, Col                                int64
	Candidates                               *string
	FilePath, Language, Status, NameTail     string
}

UnresolvedRef mirrors the unresolved_refs table of schema 9.

type VerifyOptions

type VerifyOptions struct {
	DataDir string // the .codegraph directory name; default ".codegraph"
}

VerifyOptions configures Verify.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL