- .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 Go code implements a command-line tool to mirror GitLab repositories to a local directory. It leverages the gitlab
Go library to interact with the GitLab API.
Key Functionality:
- Initialization:
- Parses command-line flags for:
dest
: Destination directory for the cloned repos.url
: GitLab API URL (defaults tohttps://gitlab.com/api/v4/
).token
: Path to a file containing the GitLab API token (can also be set in ~/.netrc).membership
: Mirror only repos the user is a member of.public
: Mirror only public repos.delete
: Delete local repos that are no longer present on GitLab.name
: Regexp to filter repos by name.exclude
: Regexp to exclude repos by name.- Creates the destination directory if it doesn’t exist.
- Reads the API token from the specified file.
- Initializes a GitLab client using the provided token and API URL.
- Fetching GitLab Projects:
- Uses the GitLab client to list all projects using the
ListProjectsOptions
struct. - Applies filters based on
membership
,public
,name
, andexclude
flags. - Iterates through the list of projects, skipping projects without a default branch (likely disabled repositories).
- Stores all fetched projects in a
gitlabProjects
slice.
- Cloning Repositories:
- Iterates over the
gitlabProjects
slice. - Parses the project’s HTTP URL.
- Defines a map of configuration options for
zoekt
(a code search engine) to store metadata about the repo. - Calls
gitindex.CloneRepo
to clone the repository to the destination directory, including the defined config. - Prints the path of the cloned repository to the console.
- Deleting Stale Repositories:
- If the
delete
flag is set, it checks for stale repos: - Creates a set of all project URLs from the
gitlabProjects
slice. - Calls
gitindex.DeleteRepos
to remove any repositories in the destination directory that are not present in the set.
Code Details:
main()
function: Orchestrates the entire process.deleteStaleProjects()
function: Deletes local repos that are no longer present on GitLab.fetchProjects()
function: Handles fetching projects from GitLab and cloning them.marshalBool()
function: Converts a boolean value to a string representation (either “1” or “0”) for use in the configuration map.
Overall, this code provides a robust and configurable solution for mirroring GitLab repositories locally, enabling efficient access and analysis of codebases.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph