- .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 is the main
function for the zoekt-archive-index
command, a tool used for indexing archives within the Zoekt search engine project. Let’s break down what it does:
Main Function
Command-line argument parsing: The code parses command-line flags using
flag
. These flags control various aspects of the indexing process:-incremental
: If set, only changes since the specified commit will be indexed.-name
: The name of the repository being indexed.-url
: The URL of the repository.-branch
: The branch being indexed.-commit
: The specific commit to index.-strip_components
: The number of leading path elements to remove from file paths during indexing.-download-limit-mbps
: The maximum download speed in megabits per second, if any.GOMAXPROCS tuning: The code uses
maxprocs.Set()
to attempt to set theGOMAXPROCS
environment variable to a value that matches the container’s CPU quota (if it’s running in a container). This helps optimize resource utilization.Logging: The code sets up basic logging with timestamps and file names.
Error handling: It verifies that exactly one archive URL is provided as an argument. If not, it exits with an error message.
Archive indexing:
The code builds an
archive.Options
struct to configure the indexing process, using values from the command-line flags.It calls the
archive.Index()
function, passing the archive options and the indexing options (bopts
which is likely defined in thecmd
package). Thearchive.Index()
function handles downloading the archive, extracting it, and indexing its contents.Error handling: If
archive.Index()
returns an error, the code logs it and exits.
Additional Notes
- Dependencies: The code relies on the
github.com/sourcegraph/zoekt/cmd
andgithub.com/sourcegraph/zoekt/internal/archive
packages. - Sourcegraph-specific logic: The code includes a call to
limitHTTPDefaultClient()
, which seems to be a function that might limit the download speed of the archive. This indicates the code may be specifically tailored for use within Sourcegraph.
In summary, this main
function orchestrates the indexing process for archives. It parses user input, configures indexing options, and calls the appropriate function to perform the indexing work.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph