|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the swift-libgit2 open source project. |
| 4 | +// |
| 5 | +// Copyright (c) Margins Technologies LLC. |
| 6 | +// Licensed under the Apache License, Version 2.0. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +import CLibgit2 |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +/// Creates a blank repository with no backend or configuration. |
| 15 | +/// - Parameter out: The pointer in which to store the repository. The |
| 16 | +/// underlying type must be `git_repository`. |
| 17 | +/// - Returns: A ``GitErrorCode`` instance. |
| 18 | +/// |
| 19 | +/// ## Discussion |
| 20 | +/// |
| 21 | +/// A blank repository is useful if it needs to be associated with an object |
| 22 | +/// database and configuration store that are not backed by a file system. |
| 23 | +/// |
| 24 | +/// Since a blank repository has no physical location, some systems may fail |
| 25 | +/// to function properly. Locations under `$GIT_DIR`, `$GIT_COMMON_DIR`, and |
| 26 | +/// `$GIT_INFO_DIR` are impacted. |
| 27 | +/// |
| 28 | +/// - Note: This function supports only SHA-1 repositories. |
| 29 | +/// |
| 30 | +/// ## C Equivalent |
| 31 | +/// |
| 32 | +/// [`git_repository_new()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_new.html) |
| 33 | +public func gitRepositoryNew( |
| 34 | + out: UnsafeMutablePointer<OpaquePointer?> |
| 35 | +) -> GitErrorCode |
| 36 | +{ |
| 37 | + return withCConversion |
| 38 | + { |
| 39 | + return git_repository_new(out) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +/// Resets the internal state of the given repository. |
| 46 | +/// - Parameter repo: The repository to reset. The underlying type must be |
| 47 | +/// `git_repository`. |
| 48 | +/// - Returns: A ``GitErrorCode`` instance. |
| 49 | +/// |
| 50 | +/// ## Discussion |
| 51 | +/// |
| 52 | +/// - Note: ``gitRepositoryFree(repo:)`` performs this operation before |
| 53 | +/// deallocating the given repository. It is generally unnecessary to call |
| 54 | +/// this function. |
| 55 | +/// |
| 56 | +/// ## C Equivalent |
| 57 | +/// |
| 58 | +/// [`git_repository__cleanup()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository__cleanup.html) |
| 59 | +public func gitRepositoryCleanup( |
| 60 | + repo: OpaquePointer |
| 61 | +) -> GitErrorCode |
| 62 | +{ |
| 63 | + return withCConversion |
| 64 | + { |
| 65 | + return git_repository__cleanup(repo) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +/// Updates the file system configuration for the given open repository. |
| 72 | +/// - Parameters: |
| 73 | +/// - repo: The repository to use. The underlying type must be |
| 74 | +/// `git_repository`. |
| 75 | +/// - recurseSubmodules: Whether to recursively update submodules. |
| 76 | +/// - Returns: A ``GitErrorCode`` instance. |
| 77 | +/// |
| 78 | +/// ## Discussion |
| 79 | +/// |
| 80 | +/// When a repository is initialized, configuration values such as |
| 81 | +/// `core.ignorecase`, `core.filemode`, and `core.symlinks` are set based on |
| 82 | +/// the properties of the file system. If the repository is moved to a new file |
| 83 | +/// system, these properties may no longer be correct, and the repository may |
| 84 | +/// not behave as expected. This function reruns the phase of repository |
| 85 | +/// initialization that sets those configuration properties. |
| 86 | +/// |
| 87 | +/// ## C Equivalent |
| 88 | +/// |
| 89 | +/// [`git_repository_reinit_filesystem()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_reinit_filesystem.html) |
| 90 | +public func gitRepositoryReinitFileSystem( |
| 91 | + repo : OpaquePointer, |
| 92 | + recurseSubmodules : Bool |
| 93 | +) -> GitErrorCode |
| 94 | +{ |
| 95 | + return withCConversion |
| 96 | + { |
| 97 | + return git_repository_reinit_filesystem( |
| 98 | + repo, |
| 99 | + recurseSubmodules.int32Value |
| 100 | + ) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +/// Sets the configuration file of the given repository. |
| 107 | +/// - Parameters: |
| 108 | +/// - repo: The repository to update. The underlying type must be |
| 109 | +/// `git_repository`. |
| 110 | +/// - config: The configuration to use. The underlying type must be |
| 111 | +/// `git_config`. |
| 112 | +/// - Returns: A ``GitErrorCode`` instance. |
| 113 | +/// |
| 114 | +/// ## Discussion |
| 115 | +/// |
| 116 | +/// - Important: Ownership of the given configuration will not transfer to the |
| 117 | +/// repository. The caller must still free it. |
| 118 | +/// |
| 119 | +/// ## C Equivalent |
| 120 | +/// |
| 121 | +/// [`git_repository_set_config()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_set_config.html) |
| 122 | +public func gitRepositorySetConfig( |
| 123 | + repo : OpaquePointer, |
| 124 | + config : OpaquePointer |
| 125 | +) -> GitErrorCode |
| 126 | +{ |
| 127 | + return withCConversion |
| 128 | + { |
| 129 | + return git_repository_set_config( |
| 130 | + repo, |
| 131 | + config |
| 132 | + ) |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +/// Sets the object database of the given repository. |
| 139 | +/// - Parameters: |
| 140 | +/// - repo: The repository to update. The underlying type must be |
| 141 | +/// `git_repository`. |
| 142 | +/// - odb: The object database to use. The underlying type must be |
| 143 | +/// `git_odb`. |
| 144 | +/// - Returns: A ``GitErrorCode`` instance. |
| 145 | +/// |
| 146 | +/// ## Discussion |
| 147 | +/// |
| 148 | +/// - Important: Ownership of the given object database will not transfer to |
| 149 | +/// the repository. The caller must still free it. |
| 150 | +/// |
| 151 | +/// ## C Equivalent |
| 152 | +/// |
| 153 | +/// [`git_repository_set_odb()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_set_odb.html) |
| 154 | +public func gitRepositorySetODB( |
| 155 | + repo : OpaquePointer, |
| 156 | + odb : OpaquePointer |
| 157 | +) -> GitErrorCode |
| 158 | +{ |
| 159 | + return withCConversion |
| 160 | + { |
| 161 | + return git_repository_set_odb( |
| 162 | + repo, |
| 163 | + odb |
| 164 | + ) |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +/// Sets the reference database of the given repository. |
| 171 | +/// - Parameters: |
| 172 | +/// - repo: The repository to update. The underlying type must be |
| 173 | +/// `git_repository`. |
| 174 | +/// - refDB: The reference database to use. The underlying type must be |
| 175 | +/// `git_refdb`. |
| 176 | +/// - Returns: A ``GitErrorCode`` instance. |
| 177 | +/// |
| 178 | +/// ## Discussion |
| 179 | +/// |
| 180 | +/// - Important: Ownership of the given reference database will not transfer to |
| 181 | +/// the repository. The caller must still free it. |
| 182 | +/// |
| 183 | +/// ## C Equivalent |
| 184 | +/// |
| 185 | +/// [`git_repository_set_refdb()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_set_refdb.html) |
| 186 | +public func gitRepositorySetRefDB( |
| 187 | + repo : OpaquePointer, |
| 188 | + refDB : OpaquePointer |
| 189 | +) -> GitErrorCode |
| 190 | +{ |
| 191 | + return withCConversion |
| 192 | + { |
| 193 | + return git_repository_set_refdb( |
| 194 | + repo, |
| 195 | + refDB |
| 196 | + ) |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +/// Sets the index of the given repository. |
| 203 | +/// - Parameters: |
| 204 | +/// - repo: The repository to update. The underlying type must be |
| 205 | +/// `git_repository`. |
| 206 | +/// - index: The index to use. The underlying type must be `git_index`. |
| 207 | +/// - Returns: A ``GitErrorCode`` instance. |
| 208 | +/// |
| 209 | +/// ## Discussion |
| 210 | +/// |
| 211 | +/// - Important: Ownership of the given index will not transfer to the |
| 212 | +/// repository. The caller must still free it. |
| 213 | +/// |
| 214 | +/// ## C Equivalent |
| 215 | +/// |
| 216 | +/// [`git_repository_set_index()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_set_index.html) |
| 217 | +public func gitRepositorySetIndex( |
| 218 | + repo : OpaquePointer, |
| 219 | + index : OpaquePointer |
| 220 | +) -> GitErrorCode |
| 221 | +{ |
| 222 | + return withCConversion |
| 223 | + { |
| 224 | + return git_repository_set_index( |
| 225 | + repo, |
| 226 | + index |
| 227 | + ) |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | +/// Converts the given repository to a bare repository. |
| 234 | +/// - Parameter repo: The repository to update. The underlying type must be |
| 235 | +/// `git_repository`. |
| 236 | +/// - Returns: A ``GitErrorCode`` instance. |
| 237 | +/// |
| 238 | +/// ## Discussion |
| 239 | +/// |
| 240 | +/// This function will clear the working directory of the given repository, |
| 241 | +/// and set `core.bare` to `true`. |
| 242 | +/// |
| 243 | +/// - Note: This function will not update the index. Consider calling |
| 244 | +/// ``gitRepositorySetIndex(repo:index:)`` to set the index to `nil`, |
| 245 | +/// since a bare repository generally does not have an index. |
| 246 | +/// |
| 247 | +/// ## C Equivalent |
| 248 | +/// |
| 249 | +/// [`git_repository_set_bare()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_set_bare.html) |
| 250 | +public func gitRepositorySetBare( |
| 251 | + repo: OpaquePointer |
| 252 | +) -> GitErrorCode |
| 253 | +{ |
| 254 | + return withCConversion |
| 255 | + { |
| 256 | + return git_repository_set_bare(repo) |
| 257 | + } |
| 258 | +} |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | +/// Loads and caches all submodules of the given repository. |
| 263 | +/// - Parameter repo: The repository containing the submodules to cache. The |
| 264 | +/// underlying type must be `git_repository`. |
| 265 | +/// - Returns: A ``GitErrorCode`` instance. |
| 266 | +/// |
| 267 | +/// ## Discussion |
| 268 | +/// |
| 269 | +/// Since the `.gitmodules` file is unstructured, loading submodules is an |
| 270 | +/// `O(n)` operation. Any operation that requires accessing all submodules is |
| 271 | +/// `O(n²)`. This function loads and caches all submodules, so that |
| 272 | +/// subsequent calls to ``gitSubmoduleLookup(out:repo:name:)`` are `O(1)`. |
| 273 | +/// |
| 274 | +/// ## C Equivalent |
| 275 | +/// |
| 276 | +/// [`git_repository_submodule_cache_all()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_submodule_cache_all.html) |
| 277 | +public func gitRepositorySubmoduleCacheAll( |
| 278 | + repo: OpaquePointer |
| 279 | +) -> GitErrorCode |
| 280 | +{ |
| 281 | + return withCConversion |
| 282 | + { |
| 283 | + return git_repository_submodule_cache_all(repo) |
| 284 | + } |
| 285 | +} |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | +/// Clears the submodule cache of the given repository. |
| 290 | +/// - Parameter repo: The repository containing the submodule cache to clear. |
| 291 | +/// The underlying type must be `git_repository`. |
| 292 | +/// - Returns: A ``GitErrorCode`` instance. |
| 293 | +/// |
| 294 | +/// ## Discussion |
| 295 | +/// |
| 296 | +/// The submodule cache incorporates data from the repository's configuration |
| 297 | +/// and the state of the working tree, the index, and HEAD. Any time one of |
| 298 | +/// these has changed, the submodule cache may become invalid. |
| 299 | +/// |
| 300 | +/// ## C Equivalent |
| 301 | +/// |
| 302 | +/// [`git_repository_submodule_cache_clear()`](https://libgit2.org/docs/reference/main/sys/repository/git_repository_submodule_cache_clear.html) |
| 303 | +public func gitRepositorySubmoduleCacheClear( |
| 304 | + repo: OpaquePointer |
| 305 | +) -> GitErrorCode |
| 306 | +{ |
| 307 | + return withCConversion |
| 308 | + { |
| 309 | + return git_repository_submodule_cache_clear(repo) |
| 310 | + } |
| 311 | +} |
0 commit comments