mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-28 06:35:27 -05:00
The Git project is not exactly the easiest project to get started in: it's written in C and POSIX shell, with bits of Perl, Rust and other languages sprinkled into it. On top of that, the project has grown somewhat organically over time, making the codebase hard to navigate. These are problems that we're aware of, and there have been and still are efforts to clean up some of the technical debt that is natural to exist an a project that is more than 20 years old. Furthermore, we provide resources to newcomers that help them out like our coding guidelines, code of conduct or "MyFirstContribution.adoc". But there is a rather practical problem: finding your way around in our project's tree is not easy. Doing a directory listing in the top-level directory will present you with more than 550 files, which makes it extremely hard for a newcomer to figure out what files they are even supposed to look at. This makes the onboarding experience somewhat harder than it really needs to be. This isn't only a problem for newcomers though, as I myself struggle to find the files I am looking for because of the sheer number of files. Besides the problem of discoverability it also creates a problem of structure. It is not obvious at all which files are part of "libgit.a" and which files are only linked into our final executables. So while we have this split in our build systems, that split is not evident at all in our tree. Introduce a new "lib/" directory and move all of our sources for "libgit.a" into it to fix these issues. It makes the split we have evident and reduces the number of files in our top-level tree from 550 files to ~80 files. This is still a lot of files, but it's significantly easier to navigate already. Furthermore, we can further iterate after this step and think about introducing a better structure for remaining files, as well. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
136 lines
4.1 KiB
C
136 lines
4.1 KiB
C
/*
|
|
* Copyright 2020 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style
|
|
* license that can be found in the LICENSE file or at
|
|
* https://developers.google.com/open-source/licenses/bsd
|
|
*/
|
|
|
|
#ifndef SYSTEM_H
|
|
#define SYSTEM_H
|
|
|
|
/*
|
|
* This header defines the platform-agnostic interface that is to be
|
|
* implemented by the project to make it work on their respective supported
|
|
* systems, and to integrate it into the project itself. This header is not
|
|
* expected to be changed by the individual project.
|
|
*/
|
|
|
|
#include "reftable-system.h"
|
|
|
|
/*
|
|
* Return a random 32 bit integer. This function is expected to return
|
|
* pre-seeded data.
|
|
*/
|
|
uint32_t reftable_rand(void);
|
|
|
|
/*
|
|
* An implementation-specific temporary file. By making this specific to the
|
|
* implementation it becomes possible to tie temporary files into any kind of
|
|
* signal or atexit handlers for cleanup on abnormal situations.
|
|
*/
|
|
struct reftable_tmpfile {
|
|
const char *path;
|
|
int fd;
|
|
void *priv;
|
|
};
|
|
#define REFTABLE_TMPFILE_INIT ((struct reftable_tmpfile) { .fd = -1, })
|
|
|
|
/*
|
|
* Create a temporary file from a pattern similar to how mkstemp(3p) would.
|
|
* The `pattern` shall not be modified. On success, the structure at `out` has
|
|
* been initialized such that it is ready for use. Returns 0 on success, a
|
|
* reftable error code on error.
|
|
*/
|
|
int tmpfile_from_pattern(struct reftable_tmpfile *out, const char *pattern);
|
|
|
|
/*
|
|
* Close the temporary file's file descriptor without removing the file itself.
|
|
* This is a no-op in case the file has already been closed beforehand. Returns
|
|
* 0 on success, a reftable error code on error.
|
|
*/
|
|
int tmpfile_close(struct reftable_tmpfile *t);
|
|
|
|
/*
|
|
* Close the temporary file and delete it. This is a no-op in case the file has
|
|
* already been deleted or renamed beforehand. Returns 0 on success, a reftable
|
|
* error code on error.
|
|
*/
|
|
int tmpfile_delete(struct reftable_tmpfile *t);
|
|
|
|
/*
|
|
* Rename the temporary file to the provided path. The temporary file must be
|
|
* active. Return 0 on success, a reftable error code on error. Deactivates the
|
|
* temporary file.
|
|
*/
|
|
int tmpfile_rename(struct reftable_tmpfile *t, const char *path);
|
|
|
|
/*
|
|
* An implementation-specific file lock. Same as with `reftable_tmpfile`,
|
|
* making this specific to the implementation makes it possible to tie this
|
|
* into signal or atexit handlers such that we know to clean up stale locks on
|
|
* abnormal exits.
|
|
*/
|
|
struct reftable_flock {
|
|
const char *path;
|
|
int fd;
|
|
void *priv;
|
|
};
|
|
#define REFTABLE_FLOCK_INIT ((struct reftable_flock){ .fd = -1, })
|
|
|
|
/*
|
|
* Acquire the lock for the given target path by exclusively creating a file
|
|
* with ".lock" appended to it. If that lock exists, we wait up to `timeout_ms`
|
|
* to acquire the lock. If `timeout_ms` is 0 we don't wait, if it is negative
|
|
* we block indefinitely.
|
|
*
|
|
* Return 0 on success, a reftable error code on error. Specifically,
|
|
* `REFTABLE_LOCK_ERROR` should be returned in case the target path is already
|
|
* locked.
|
|
*/
|
|
int flock_acquire(struct reftable_flock *l, const char *target_path,
|
|
long timeout_ms);
|
|
|
|
/*
|
|
* Close the lockfile's file descriptor without removing the lock itself. This
|
|
* is a no-op in case the lockfile has already been closed beforehand. Returns
|
|
* 0 on success, a reftable error code on error.
|
|
*/
|
|
int flock_close(struct reftable_flock *l);
|
|
|
|
/*
|
|
* Release the lock by unlinking the lockfile. This is a no-op in case the
|
|
* lockfile has already been released or committed beforehand. Returns 0 on
|
|
* success, a reftable error code on error.
|
|
*/
|
|
int flock_release(struct reftable_flock *l);
|
|
|
|
/*
|
|
* Commit the lock by renaming the lockfile into place. Returns 0 on success, a
|
|
* reftable error code on error.
|
|
*/
|
|
int flock_commit(struct reftable_flock *l);
|
|
|
|
/* Report the time in milliseconds. */
|
|
uint64_t reftable_time_ms(void);
|
|
|
|
struct reftable_mmap {
|
|
void *data;
|
|
size_t size;
|
|
void *priv;
|
|
};
|
|
|
|
/*
|
|
* Map the file into memory. Returns 0 on success, a reftable error code on
|
|
* error.
|
|
*/
|
|
int reftable_mmap(struct reftable_mmap *out, int fd, size_t len);
|
|
|
|
/*
|
|
* Unmap the file from memory. Returns 0 on success, a reftable error code on
|
|
* error.
|
|
*/
|
|
int reftable_munmap(struct reftable_mmap *mmap);
|
|
|
|
#endif
|