1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00
Commit graph

135 commits

Author SHA1 Message Date
Eelco Dolstra
9657feaf8c GitRepo::getRevCount(): Compute revcount in parallel
For repos with a lot of non-linearity in the commit graph (like
Nixpkgs), this speeds up getting the revcount a lot, e.g. `nix flake
metadata /path/to/nixpkgs?rev=9dc7035bbee85ffc740d893e02cb64460f11989f` went
from 9.1s to 3.7s.
2025-11-04 14:50:57 +01:00
Marcel
584a8e8a00
treewide: replace manual MiB calculations with renderSize 2025-10-27 16:04:19 +01:00
Sergei Zimmerman
5d1178b817
libfetchers/git-utils: Be more correct about validating refnames
Turns out there's a much better API for this that doesn't have the
footguns of the previous method.

isLegalRefName is somewhat of a misnomer, since it's mainly used to
validate user inputs that can be either references, branch names,
psedorefs or tags.
2025-10-15 21:54:09 +03:00
Eelco Dolstra
5f60602875 Reapply "Merge pull request #13938 from NixOS/import-thunk"
This reverts commit fd034814dc.
2025-09-22 11:48:58 +02:00
Sergei Zimmerman
fd034814dc
Revert "Merge pull request #13938 from NixOS/import-thunk"
This has multiple dangling pointer issues that lead to segfaults in e.g.:

nix eval --expr '(builtins.getFlake "github:nixos/nixpkgs/25.05")' --impure

This reverts commit ad175727e4, reversing
changes made to d314750174.
2025-09-18 01:52:46 +03:00
Eelco Dolstra
4b63ff63a4 Remove some unnecessary hash template arguments 2025-09-12 17:26:29 +02:00
Philipp Otterbein
9f2b6a1b94 replace more std::unordered_* types by faster boost hash maps 2025-09-10 23:04:44 +02:00
netadr
671c21db9f libfetchers: Fix SSH key identifiers for sk type keys
libfetchers: Mark ssh-ecdsa-sk key type mapping as a TODO for now
2025-09-03 22:56:33 +02:00
Sergei Zimmerman
e8e9376a7b
libfetchers: Remove badGitRefRegex and use libgit2 for reference validation
Fixes usage of `#` symbol in the reference name.
This also seems to identify several deficiencies in the libgit2 refname
validation code wrt to DEL symbol and a singular `@` symbol [1].

[1]: https://git-scm.com/docs/git-check-ref-format#_description
2025-08-11 02:38:45 +03:00
John Ericson
991831227e Clean up Base* code
Make it separate from Hash, since other things can be base-encoded too.

This isn't really needed for Nix, but it makes the code easier to read
e.g. for someone reimplementing this stuff in a different language. (Of
course, Base16/Base64 should be gotten off-the-shelf, but now the hash
code, which is more bespoke, is less cluttered with the parts that would
be from some library.)

Many reimplementations of "Nix32" and our hash type already exist, so
this cleanup is coming years too late, but I say better late than never
/ it is always good to nudge the code in the direction of being a
"living spec".

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
2025-08-06 11:51:44 -04:00
Farid Zakaria
33ceea6099 Unpeel reference for git+file
If the reference for git+file is an annotated tag, the revision will
differ than when it's fetched using other fetchers such as `github:`
since Github seems to automatiacally peel to the underlying commit.

Turns out that rev-parse has the capability through it's syntax to
request the underlying commit by "peeling" using the `^{commit}` syntax.

This is safe to apply in all scenarios where the goal is to get an
underlying commit.

fixes #11266
2025-07-21 21:10:41 -07:00
Graham Christensen
e4f62e4608 Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
2025-07-18 12:47:27 -04:00
Farid Zakaria
fb6f494d35 merge stderr to stdout so we can emit it 2025-07-16 08:04:16 -07:00
Farid Zakaria
8e8416387c Add error message when git returns non-0 for fetch
Users have complained that fetchGit is flaky however the culprit is
likely that `git fetch` was unable itself to download the repository for
whatever reason (i.e. poor network etc..)

Nothing was checking the status of `git fetch` and the error message
that would eventually surface to the users were that the commit was not
found.

Add explicit error checking for status code from `git fetch` and return
a message earlier on to indicate that the failure was from that point.

fixes #10431
2025-07-16 08:04:16 -07:00
Eelco Dolstra
4bce2d723d GitSourceAccessor: Make thread-safe 2025-06-04 21:39:15 +02:00
Eelco Dolstra
170f6021cf
Merge pull request #13265 from Mic92/fix-shallow-clone-subset
Improve errors when we are trying to access a git repository with partial history (+ fix fetchGit on these repos)
2025-05-26 14:53:08 +02:00
Jörg Thalheim
b1ccfaa080 git/revCount: improve error message when we have incomplete git history 2025-05-26 12:44:31 +02:00
Sergei Zimmerman
114de63d88
Fix various typos in source code
This only touches code comments, class names, documentation,
enumeration names and tests.
2025-05-25 20:14:11 +00:00
Sergei Zimmerman
8ee513379a
Use StringMap instead of std::map<std::string, std::string> throughout the codebase 2025-05-19 20:33:28 +00:00
Eelco Dolstra
efcb9e36a9 Remove global fetcher cache
The cache is now part of fetchers::Settings.
2025-05-17 19:54:32 +02:00
Eelco Dolstra
67e957b636 Apply makeNotAllowedError to empty repos 2025-04-02 19:57:49 +02:00
John Ericson
cc24766fa6 Expose the nix component in header include paths
For example, instead of doing

    #include "nix/store-config.hh"
    #include "nix/derived-path.hh"

Now do

    #include "nix/store/config.hh"
    #include "nix/store/derived-path.hh"

This was originally planned in the issue, and also recent requested by
Eelco.

Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.

Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!

Progress on #7876
2025-04-01 11:40:42 -04:00
John Ericson
f3e1c47f47 Separate headers from source files
The short answer for why we need to do this is so we can consistently do
`#include "nix/..."`. Without this change, there are ways to still make
that work, but they are hacky, and they have downsides such as making it
harder to make sure headers from the wrong Nix library (e..g.
`libnixexpr` headers in `libnixutil`) aren't being used.

The C API alraedy used `nix_api_*`, so its headers are *not* put in
subdirectories accordingly.

Progress on #7876

We resisted doing this for a while because it would be annoying to not
have the header source file pairs close by / easy to change file
path/name from one to the other. But I am ameliorating that with
symlinks in the next commit.
2025-03-31 12:20:25 -04:00
Jörg Thalheim
86de15f4fc git-utils: add trace context to writeFull 2025-03-27 11:26:30 +01:00
Eelco Dolstra
d4ecf15dad smudgeLfs: Use default value
Eventually this should probably become a struct of options.
2025-02-10 16:11:53 +01:00
Eelco Dolstra
d78daaa416 getLfsEndpointUrl(): Use our RAII helpers 2025-02-10 15:59:32 +01:00
Eelco Dolstra
9db070d7a2 Misc code cleanups 2025-02-10 15:46:46 +01:00
Leandro Reina
134530a534 Merge remote-tracking branch 'upstream/master' into lfs 2025-02-03 19:07:20 +01:00
Eelco Dolstra
3032512425 GitExportIgnoreSourceAccessor: Don't show «unknown»
In general we should set the path display prefix on the inner
accessor, so we now pass the display prefix to getAccessor().
2025-01-30 12:41:02 +01:00
Leandro Reina
6a3b4afc0a Merge remote-tracking branch 'upstream/master' into lfs 2025-01-27 14:44:41 +01:00
Eelco Dolstra
41983dba8f GitRepo::fetch(): Ignore $GIT_DIR
Fixes #12325.
2025-01-22 17:54:19 +01:00
Eelco Dolstra
bd10b859f7 GitRepo::fetch(): Cleanup 2025-01-22 17:42:52 +01:00
Leandro Reina
2a2518b408 LFS code review 2025-01-10 18:32:09 +01:00
Leandro Reina
7756b2286d Merge remote-tracking branch 'upstream/master' into lfs 2024-12-18 18:18:45 +01:00
Leandro Reina
b1663fa3fb Re-introduce git_attr_get_ext 2024-12-18 18:00:45 +01:00
Eelco Dolstra
33852ead6b Optimisation 2024-12-17 12:56:14 +01:00
Eelco Dolstra
b9f60faab5 Fix macOS build 2024-12-17 12:56:14 +01:00
Eelco Dolstra
7ba933e989 Cache calls to GitRepo::getWorkdirInfo()
A command like `nix flake metadata` was causing about 4 calls to
getWorkdirInfo(), which is slow for large repos (even when they're not
dirty).
2024-12-17 12:56:14 +01:00
Eelco Dolstra
331bf3e261 Git fetcher: Calculate a fingerprint for dirty workdirs
This restores evaluation caching for dirty Git workdirs.
2024-12-17 12:56:14 +01:00
Leandro Emmanuel Reina Kiperman
140b34b7ed
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-12-09 19:02:50 +01:00
Brian Camacho
79a6438c68 fix sizeCallback 2024-12-02 14:53:19 -05:00
Leandro Reina
93e63f78b3 FIx MacOS build 2024-11-21 13:53:46 +01:00
Leandro Reina
79d41062d0 Fix some errors, and add tests for them 2024-11-20 17:53:06 +01:00
Brian Camacho
6d0043902a Merge remote-tracking branch 'origin/master' into lfs 2024-11-17 12:16:15 -05:00
Brian Camacho
24453b79eb pass path.rel instead of path.abs to gitattr matcher 2024-11-17 02:39:47 -05:00
Brian Camacho
741a54df8f tweak url parsing; add test case 2024-11-07 23:29:39 -05:00
Robert Hensing
388271e8ec initRepoAtomically: Catch directory_not_empty 2024-11-06 23:52:48 +01:00
Brian Camacho
99705c6932 Merge remote-tracking branch 'origin/master' into lfs 2024-11-06 15:18:21 -05:00
Brian Camacho
d2d6f2086a Sink readFile impl for GitSourceAccessor 2024-11-05 02:27:54 -05:00
Brian Camacho
f4962fe59b working smudge for GitSourceAccessor 2024-11-01 03:37:48 -04:00