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
- Variables
- func ContentHash(rules Rules, size int64, content io.Reader) (string, error)
- func IsSourceFile(rules Rules, path string, overrides map[string]string) bool
- type Edge
- type ExecGit
- type File
- type Freshness
- type Git
- type MetadataEntry
- type Node
- type Options
- type ProjectConfig
- type Report
- type Rules
- type Snapshot
- type UnresolvedRef
- type VerifyOptions
Constants ¶
const ( StatusFresh = "fresh" StatusStale = "stale" StatusUnverifiable = "unverifiable" )
Freshness statuses.
Variables ¶
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.
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.
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 ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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.
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.
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.