- .github
- .vscode
- build
-
cmd
- zoekt
- zoekt-archive-index
- zoekt-dynamic-indexserver
- zoekt-git-clone
- zoekt-git-index
- zoekt-index
- zoekt-indexserver
- zoekt-merge-index
- zoekt-mirror-bitbucket-server
- zoekt-mirror-gerrit
- zoekt-mirror-github
- zoekt-mirror-gitiles
- zoekt-mirror-gitlab
- zoekt-repo-index
-
zoekt-sourcegraph-indexserver
-
json_schemas
- CdsConfig.json
- EdsLoadBalancingPolicyConfig.json
- GrpcLbConfig.json
- LeastRequestLocalityLoadBalancingPolicyConfig.json
- LoadBalancingConfig.json
- LrsLoadBalancingPolicyConfig.json
- MethodConfig.json
- OutlierDetectionLoadBalancingConfig.json
- OverrideHostLoadBalancingPolicyConfig.json
- PickFirstConfig.json
- PriorityLoadBalancingPolicyConfig.json
- RingHashLoadBalancingConfig.json
- RlsLoadBalancingPolicyConfig.json
- RoundRobinConfig.json
- ServiceConfig.json
- WeightedRoundRobinLbConfig.json
- WeightedTargetLoadBalancingPolicyConfig.json
- XdsClusterImplLoadBalancingPolicyConfig.json
- XdsClusterManagerLoadBalancingPolicyConfig.json
- XdsClusterResolverLoadBalancingPolicyConfig.json
- XdsConfig.json
- XdsServer.json
- XdsWrrLocalityLoadBalancingPolicyConfig.json
- update.sh
- protos
- backoff.go
- backoff_test.go
- cleanup.go
- cleanup_test.go
- debug.go
- default_grpc_service_configuration.json
- index.go
- index_mutex.go
- index_test.go
- main.go
- main_test.go
- merge.go
- merge_test.go
- meta.go
- meta_test.go
- meta_unix.go
- meta_windows.go
- owner.go
- owner_test.go
- queue.go
- queue_test.go
- sg.go
- sg_test.go
-
json_schemas
- zoekt-test
- zoekt-webserver
- flags.go
- ctags
- debugserver
- doc
- gitindex
- grpc
- ignore
-
internal
- archive
-
e2e
-
testdata
- Get_databaseuser.txt
- InternalDoer.txt
- Repository_metadata_Write_rbac.txt
- assets_are_not_configured_for_this_binary.txt
- bufio_buffer.txt
- bufio_flush_writer.txt
- bytes_buffer.txt
- coverage_data_writer.txt
- generate_unit_test.txt
- graphql_type_User.txt
- r_cody_sourcegraph_url.txt
- rank_stats.txt
- sourcegraphserver_docker_image_build.txt
- test_server.txt
- time_compare.txt
- zoekt_searcher.txt
- doc.go
- e2e_rank_test.go
- e2e_test.go
-
testdata
- languages
- mockSearcher
- otlpenv
- profiler
- syntaxutil
- tracer
- json
- query
- shards
- testdata
- trace
- web
- .bazelignore
- .dockerignore
- .gitignore
- .tool-versions
- Dockerfile
- Dockerfile.indexserver
- Dockerfile.webserver
- LICENSE
- README.md
- all.bash
- api.go
- api_proto.go
- api_proto_test.go
- api_test.go
- bits.go
- bits_test.go
- btree.go
- btree_test.go
- contentprovider.go
- contentprovider_test.go
- eval.go
- eval_test.go
- flake.lock
- flake.nix
- gen-proto.sh
- go.mod
- go.sum
- hititer.go
- hititer_test.go
- index_test.go
- indexbuilder.go
- indexdata.go
- indexdata_test.go
- indexfile_other.go
- indexfile_unix.go
- install-ctags-alpine.sh
- limit.go
- limit_test.go
- marshal.go
- marshal_test.go
- matchiter.go
- matchtree.go
- matchtree_test.go
- merge.go
- merge_test.go
- read.go
- read_test.go
- score.go
- score_test.go
- section.go
- shell.nix
- toc.go
- tombstones.go
- tombstones_test.go
- tombstones_unix.go
- tombstones_windows.go
- write.go
Explanation
This code implements a command-line tool zoekt-git-index
which indexes Git repositories for use with the Zoekt search engine. Here’s a breakdown:
Functionality:
- Parses Command-Line Arguments:
-cpuprofile
: Enables CPU profiling for performance analysis.-allow_missing_branches
: Allows indexing even if branches specified in-branches
are missing.-submodules
: Controls whether to recurse into submodules during indexing (default: true).-branches
: Specifies the Git branches to index (default: HEAD).-prefix
: Specifies a prefix for branch names (default: refs/heads/).-incremental
: Enables incremental indexing, only indexing changed files (default: true).-repo_cache
: Specifies a directory where bare Git repositories are stored for submodule resolution.-delta
: Enables delta build mode for incremental indexing, using existing index data.-delta_threshold
: Sets the maximum number of existing index shards before attempting a delta build (default: 0, disabling fallback).-offline_ranking
: Specifies a file containing offline ranking information for documents.-offline_ranking_version
: Specifies a version string for the offline ranking information.-language_map
: Maps languages to their corresponding ctags processor.[repoDir...]
: Specifies the paths to the Git repositories to index.
Sets GOMAXPROCS: Adjusts the number of goroutines to match container CPU limits.
CPU Profiling (Optional): If
-cpuprofile
is specified, starts CPU profiling.Repository Name Resolution:
- Derives repository names from input paths, potentially using the
-repo_cache
directory.
- Language Map:
- Parses the
-language_map
argument to create actags.LanguageMap
mapping languages to ctags processors.
- Iterates over Repositories:
- For each repository path:
- Creates a
gitindex.Options
struct with the parsed command-line arguments. - Calls
gitindex.IndexGitRepo
to perform indexing, passing thegitindex.Options
.
- Logs Errors:
- Prints errors encountered during indexing to the console.
- Exits with Status:
- Returns an exit status based on the success or failure of indexing operations.
Key Components:
gitindex.Options
: Struct representing indexing options, including branches, submodule handling, incremental indexing, and delta build settings.gitindex.IndexGitRepo
: Function responsible for indexing a Git repository based on the provided options.ctags.LanguageMap
: Maps languages to ctags processors for syntax highlighting.cmd.OptionsFromFlags
: Function from thezoekt/cmd
package, likely used to handle command-line arguments.
Overall:
The code provides a robust tool for indexing Git repositories for Zoekt search. It offers various options for customization, including incremental indexing, delta build modes, offline ranking, and language-specific ctags processors. The use of gitindex.Options
and clear error handling ensures a well-structured and maintainable implementation.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph