RFC on packfile URIs and .gitmodules check
Subsystems (2)
Someone at $DAYJOB noticed that if a .gitmodules-containing tree and the .gitmodules blob itself are sent in 2 separate packfiles during a fetch (which can happen when packfile URIs are used), transfer.fsckobjects causes the fetch to fail. You can reproduce it as follows (as of the time of writing):
$ git -c fetch.uriprotocols=https -c transfer.fsckobjects=true clone https://chromium.googlesource.com/chromiumos/codesearch Cloning into 'codesearch'... remote: Total 2242 (delta 0), reused 2242 (delta 0) Receiving objects: 100% (2242/2242), 1.77 MiB | 4.62 MiB/s, done. error: object 1f155c20935ee1154a813a814f03ef2b3976680f: gitmodulesMissing: unable to read .gitmodules blob fatal: fsck error in pack objects fatal: index-pack failed
This happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in gitmodules_found in fsck.c). Later, index-pack runs fsck_finish() which checks if the target exists, but it doesn't, so it reports the failure.
One option is for fetch to do its own pass of checking all downloaded objects once all packfiles have been downloaded, but that seems wasteful as all trees would have to be re-inflated.
Another option is to do it within the connectivity check instead - so, update rev-list and the object walking mechanism to be able to detect .gitmodules in trees and fsck the target blob whenever such an entry occurs. This has the advantage that there is no extra re-inflation, although it might be strange to have object walking be able to fsck.
The simplest solution would be to just relax this - check the blob if it exists, but if it doesn't, it's OK. Some things in favor of this solution:
- This is something we already do in the partial clone case (although it could be argued that in this case, we're already trusting the server for far more than .gitmodules, so just because it's OK in the partial clone case doesn't mean that it's OK in the regular case).
- Also, the commit message for this feature (from ed8b10f631 ("fsck: check .gitmodules content", 2018-05-21)) gives a rationale of a newer server being able to protect older clients.
- Servers using receive-pack (instead of fetch-pack) to obtain objects would still be protected, since receive-pack still only accepts one packfile at a time (and there are currently no plans to expand this).
- Also, malicious .gitobjects files could still be crafted that pass fsck checking - for example, by containing a URL (of another server) that refers to a repo with a .gitobjects that would fail fsck.
So I would rather go with just relaxing the check, but if consensus is that we should still do it, I'll investigate doing it in the connectivity check.
Quoted 14 lines · Jonathan Tan
Someone at $DAYJOB noticed that if a .gitmodules-containing tree and the .gitmodules blob itself are sent in 2 separate packfiles during a fetch (which can happen when packfile URIs are used), transfer.fsckobjects causes the fetch to fail. You can reproduce it as follows (as of the time of writing):
$ git -c fetch.uriprotocols=https -c transfer.fsckobjects=true clone https://chromium.googlesource.com/chromiumos/codesearch Cloning into 'codesearch'... remote: Total 2242 (delta 0), reused 2242 (delta 0) Receiving objects: 100% (2242/2242), 1.77 MiB | 4.62 MiB/s, done. error: object 1f155c20935ee1154a813a814f03ef2b3976680f: gitmodulesMissing: unable to read .gitmodules blob fatal: fsck error in pack objects fatal: index-pack failed
Quoted 6 lines
This happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in
gitmodules_foundinfsck.c). Later, index-pack runsfsck_finish()which checks if the target exists, but it doesn't, so it reports the failure.
Is this because the gitmodules blob is contained in the base image served via the pack URI mechansim, and the "dynamic" packfile for the latest part of the history refers to the gitmodules file that is unchanged, hence the latter one lacks it?
Quoted 27 lines
Another option is to do it within the connectivity check instead - so, update rev-list and the object walking mechanism to be able to detect .gitmodules in trees and fsck the target blob whenever such an entry occurs. This has the advantage that there is no extra re-inflation, although it might be strange to have object walking be able to fsck.
The simplest solution would be to just relax this - check the blob if it exists, but if it doesn't, it's OK. Some things in favor of this solution:
- This is something we already do in the partial clone case (although it could be argued that in this case, we're already trusting the server for far more than .gitmodules, so just because it's OK in the partial clone case doesn't mean that it's OK in the regular case).
- Also, the commit message for this feature (from
ed8b10f631("fsck: check .gitmodules content", 2018-05-21)) gives a rationale of a newer server being able to protect older clients.
- Servers using receive-pack (instead of fetch-pack) to obtain objects would still be protected, since receive-pack still only accepts one packfile at a time (and there are currently no plans to expand this).
- Also, malicious .gitobjects files could still be crafted that pass fsck checking - for example, by containing a URL (of another server) that refers to a repo with a .gitobjects that would fail fsck.
Quoted 3 lines
So I would rather go with just relaxing the check, but if consensus is that we should still do it, I'll investigate doing it in the connectivity check.
You've listed two possible solutions, i.e.
(1) punt and declare that we assume an missing and uncheckable blob is OK,
(2) defer the check after transfer completes.
Between the two, my gut feeling is that the latter is preferrable. If we assume an missing and uncheckable one is OK, then even if a blob is available to be checked, there is not much point in checking, no?
As long as the quarantine of incoming pack works correctly, streaming the incoming packdata (and packfile downloaded out of line via a separate mechanism like pack URI) to index-pack that does not check to complete the transfer, with a separate step to check the sanity of these packs as a whole, should not harm the repository even if it is interrupted in the middle, after transfer is done but before checking says it is OK.
As a potential third option, I wonder if it is easier for everybody involved (including third-party implementation of their index-pack/fsck equivalent) if we made it a rule that a pack that has a tree that refers to .git<something> must include the blob for it?
Thanks.
Quoted 23 lines · Junio C Hamano
Quoted 14 lines · Jonathan Tan
Someone at $DAYJOB noticed that if a .gitmodules-containing tree and the .gitmodules blob itself are sent in 2 separate packfiles during a fetch (which can happen when packfile URIs are used), transfer.fsckobjects causes the fetch to fail. You can reproduce it as follows (as of the time of writing):
$ git -c fetch.uriprotocols=https -c transfer.fsckobjects=true clone https://chromium.googlesource.com/chromiumos/codesearch Cloning into 'codesearch'... remote: Total 2242 (delta 0), reused 2242 (delta 0) Receiving objects: 100% (2242/2242), 1.77 MiB | 4.62 MiB/s, done. error: object 1f155c20935ee1154a813a814f03ef2b3976680f: gitmodulesMissing: unable to read .gitmodules blob fatal: fsck error in pack objects fatal: index-pack failedQuoted 6 lines
This happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in
gitmodules_foundinfsck.c). Later, index-pack runsfsck_finish()which checks if the target exists, but it doesn't, so it reports the failure.
Quoted 4 lines
Is this because the gitmodules blob is contained in the base image served via the pack URI mechansim, and the "dynamic" packfile for the latest part of the history refers to the gitmodules file that is unchanged, hence the latter one lacks it?
That seems like a likely explanation, although this seems ultimately up to what the pack CDN serves.
Quoted 11 lines
You've listed two possible solutions, i.e.
(1) punt and declare that we assume an missing and uncheckable blob is OK,
(2) defer the check after transfer completes.
Between the two, my gut feeling is that the latter is preferrable. If we assume an missing and uncheckable one is OK, then even if a blob is available to be checked, there is not much point in checking, no?
I'm going to second this. If this were a more benign check, then I'd perhaps feel differently, but .gitmodules fsck checks seem to get hardened fairly often during security releases, and so it seems important to keep performing them when the user asked for it.
Quoted 7 lines
As long as the quarantine of incoming pack works correctly, streaming the incoming packdata (and packfile downloaded out of line via a separate mechanism like pack URI) to index-pack that does not check to complete the transfer, with a separate step to check the sanity of these packs as a whole, should not harm the repository even if it is interrupted in the middle, after transfer is done but before checking says it is OK.
Agreed. Bear in mind that I am pretty unfamiliar with this code, and so I'm not sure if it's 'easy' or not to change it in this way. The obvious downside, which Jonathan notes, is that you almost certainly have to reinflate all of the trees again.
But, since the user is asking for transfer.fsckObjects explicitly, I don't think that it's a problem.
Quoted 5 lines
As a potential third option, I wonder if it is easier for everybody involved (including third-party implementation of their index-pack/fsck equivalent) if we made it a rule that a pack that has a tree that refers to .git<something> must include the blob for it?
Interesting, but I'm sure CDN administrators would prefer to have as few restrictions in place as possible.
A potential fourth option that I can think of is that we can try to eagerly perform the .gitmodules fsck checks as we receive objects, under the assumption that the .gitmoudles blob and the tree which contains it appear in the same pack.
If they do, then we ought to be able to check them as we currently do (and avoid leaving them to the slow post-processing step). Any blobs that we _can't_ find get placed into an array, and then that array is iterated over after we have received all packs, including from the CDN. Any blobs that couldn't be found in the pack transferred from the remote, the CDN, or the local repository (and isn't explicitly excluded via an object --filter) is declared missing.
Thoughts?
Quoted 1 line
Thanks.
Thanks,
Taylor
Quoted 9 lines · Taylor Blau
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Jonathan Tan
Someone at $DAYJOB noticed that if a .gitmodules-containing tree and the .gitmodules blob itself are sent in 2 separate packfiles during a fetch (which can happen when packfile URIs are used), transfer.fsckobjects causes the fetch to fail. You can reproduce it as follows (as of the time of writing):
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
$ git -c fetch.uriprotocols=https -c transfer.fsckobjects=true clone https://chromium.googlesource.com/chromiumos/codesearch Cloning into 'codesearch'... remote: Total 2242 (delta 0), reused 2242 (delta 0) Receiving objects: 100% (2242/2242), 1.77 MiB | 4.62 MiB/s, done. error: object 1f155c20935ee1154a813a814f03ef2b3976680f: gitmodulesMissing: unable to read .gitmodules blob fatal: fsck error in pack objects fatal: index-pack failed
I'm contributing a quick suggestion for just this item:
Quoted 26 lines
Quoted 11 lines
Quoted 6 lines
This happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in
gitmodules_foundinfsck.c). Later, index-pack runsfsck_finish()which checks if the target exists, but it doesn't, so it reports the failure.Is this because the gitmodules blob is contained in the base image served via the pack URI mechansim, and the "dynamic" packfile for the latest part of the history refers to the gitmodules file that is unchanged, hence the latter one lacks it?
That seems like a likely explanation, although this seems ultimately up to what the pack CDN serves.
Quoted 11 lines
You've listed two possible solutions, i.e.
(1) punt and declare that we assume an missing and uncheckable blob is OK,
(2) defer the check after transfer completes.
Between the two, my gut feeling is that the latter is preferrable. If we assume an missing and uncheckable one is OK, then even if a blob is available to be checked, there is not much point in checking, no?
Quoted 4 lines
I'm going to second this. If this were a more benign check, then I'd perhaps feel differently, but .gitmodules fsck checks seem to get hardened fairly often during security releases, and so it seems important to keep performing them when the user asked for it.
It might be nice to teach 'index-pack' a mode that says certain errors should be reported as warnings by writing the problematic OIDs to stdout/stderr. Then, the second check after all packs are present can focus on those problematic objects instead of re-scanning everything.
Thanks,
-Stolee
Quoted 33 lines
I'm contributing a quick suggestion for just this item:
Quoted 26 lines
Quoted 11 lines
Quoted 6 lines
This happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in
gitmodules_foundinfsck.c). Later, index-pack runsfsck_finish()which checks if the target exists, but it doesn't, so it reports the failure.Is this because the gitmodules blob is contained in the base image served via the pack URI mechansim, and the "dynamic" packfile for the latest part of the history refers to the gitmodules file that is unchanged, hence the latter one lacks it?
That seems like a likely explanation, although this seems ultimately up to what the pack CDN serves.
Quoted 11 lines
You've listed two possible solutions, i.e.
(1) punt and declare that we assume an missing and uncheckable blob is OK,
(2) defer the check after transfer completes.
Between the two, my gut feeling is that the latter is preferrable. If we assume an missing and uncheckable one is OK, then even if a blob is available to be checked, there is not much point in checking, no?
Quoted 4 lines
I'm going to second this. If this were a more benign check, then I'd perhaps feel differently, but .gitmodules fsck checks seem to get hardened fairly often during security releases, and so it seems important to keep performing them when the user asked for it.
Quoted 5 lines
It might be nice to teach 'index-pack' a mode that says certain errors should be reported as warnings by writing the problematic OIDs to stdout/stderr. Then, the second check after all packs are present can focus on those problematic objects instead of re-scanning everything.
My initial reaction was that stdout is already used to report the hash part of the generated name and that stderr is already used for whatever warnings there are, but looking at the documentation, index-pack --fsck-objects is "[for] internal use only", so it might be fine to extend the output format in this case and report the problematic OIDs after the hash. I'll take a look.
Quoted 6 lines · Jonathan Tan
Quoted 5 lines
It might be nice to teach 'index-pack' a mode that says certain errors should be reported as warnings by writing the problematic OIDs to stdout/stderr. Then, the second check after all packs are present can focus on those problematic objects instead of re-scanning everything.
Quoted 6 lines
My initial reaction was that stdout is already used to report the hash part of the generated name and that stderr is already used for whatever warnings there are, but looking at the documentation, index-pack --fsck-objects is "[for] internal use only", so it might be fine to extend the output format in this case and report the problematic OIDs after the hash. I'll take a look.
If I am not mistaken, Taylor also mentioned the possibility to give "these objects need reinspecting" to a later process, and it is an excellent suggestion. And I think it is perfectly fine to adjust the internal format used purely for internal use.
Thanks.
Quoted 7 lines
Quoted 4 lines
Is this because the gitmodules blob is contained in the base image served via the pack URI mechansim, and the "dynamic" packfile for the latest part of the history refers to the gitmodules file that is unchanged, hence the latter one lacks it?
That seems like a likely explanation, although this seems ultimately up to what the pack CDN serves.
In this case, yes, that is what is happening.
Quoted 12 lines
Quoted 11 lines
You've listed two possible solutions, i.e.
(1) punt and declare that we assume an missing and uncheckable blob is OK,
(2) defer the check after transfer completes.
Between the two, my gut feeling is that the latter is preferrable. If we assume an missing and uncheckable one is OK, then even if a blob is available to be checked, there is not much point in checking, no?
Quoted 4 lines
I'm going to second this. If this were a more benign check, then I'd perhaps feel differently, but .gitmodules fsck checks seem to get hardened fairly often during security releases, and so it seems important to keep performing them when the user asked for it.
That makes sense.
Quoted 8 lines
Quoted 7 lines
As long as the quarantine of incoming pack works correctly, streaming the incoming packdata (and packfile downloaded out of line via a separate mechanism like pack URI) to index-pack that does not check to complete the transfer, with a separate step to check the sanity of these packs as a whole, should not harm the repository even if it is interrupted in the middle, after transfer is done but before checking says it is OK.
Quoted 7 lines
Agreed. Bear in mind that I am pretty unfamiliar with this code, and so I'm not sure if it's 'easy' or not to change it in this way. The obvious downside, which Jonathan notes, is that you almost certainly have to reinflate all of the trees again.
But, since the user is asking for transfer.fsckObjects explicitly, I don't think that it's a problem.
We might be able to avoid the reinflate if we do it as part of the connectivity check or somehow teach index-pack a way to communicate the dangling .gitmodules links (as you suggest below).
Quoted 8 lines
Quoted 5 lines
As a potential third option, I wonder if it is easier for everybody involved (including third-party implementation of their index-pack/fsck equivalent) if we made it a rule that a pack that has a tree that refers to .git<something> must include the blob for it?
Interesting, but I'm sure CDN administrators would prefer to have as few restrictions in place as possible.
That rule would help, but it also seems inelegant in that if we put commits that have the same .gitmodules in 2 or more different packs, there would be identical objects across those packs (besides the reason Taylor mentioned).
Quoted 13 lines
A potential fourth option that I can think of is that we can try to eagerly perform the .gitmodules fsck checks as we receive objects, under the assumption that the .gitmoudles blob and the tree which contains it appear in the same pack.
If they do, then we ought to be able to check them as we currently do (and avoid leaving them to the slow post-processing step). Any blobs that we _can't_ find get placed into an array, and then that array is iterated over after we have received all packs, including from the CDN. Any blobs that couldn't be found in the pack transferred from the remote, the CDN, or the local repository (and isn't explicitly excluded via an object --filter) is declared missing.
Quoted 1 line
Thoughts?
The hard part is communicating this array to the parent fetch process. Stolee has a suggestion [1] which I will reply to directly.
Quoted 52 lines · Jonathan Tan
Someone at $DAYJOB noticed that if a .gitmodules-containing tree and the .gitmodules blob itself are sent in 2 separate packfiles during a fetch (which can happen when packfile URIs are used), transfer.fsckobjects causes the fetch to fail. You can reproduce it as follows (as of the time of writing):
$ git -c fetch.uriprotocols=https -c transfer.fsckobjects=true clone https://chromium.googlesource.com/chromiumos/codesearch Cloning into 'codesearch'... remote: Total 2242 (delta 0), reused 2242 (delta 0) Receiving objects: 100% (2242/2242), 1.77 MiB | 4.62 MiB/s, done. error: object 1f155c20935ee1154a813a814f03ef2b3976680f: gitmodulesMissing: unable to read .gitmodules blob fatal: fsck error in pack objects fatal: index-pack failedThis happens because the fsck part is currently being done in index-pack, which operates on one pack at a time. When index-pack sees the tree, it runs fsck on it (like any other object), and the fsck subsystem remembers the .gitmodules target (specifically, in
gitmodules_foundinfsck.c). Later, index-pack runsfsck_finish()which checks if the target exists, but it doesn't, so it reports the failure.One option is for fetch to do its own pass of checking all downloaded objects once all packfiles have been downloaded, but that seems wasteful as all trees would have to be re-inflated.
Another option is to do it within the connectivity check instead - so, update rev-list and the object walking mechanism to be able to detect .gitmodules in trees and fsck the target blob whenever such an entry occurs. This has the advantage that there is no extra re-inflation, although it might be strange to have object walking be able to fsck.
The simplest solution would be to just relax this - check the blob if it exists, but if it doesn't, it's OK. Some things in favor of this solution:
- This is something we already do in the partial clone case (although it could be argued that in this case, we're already trusting the server for far more than .gitmodules, so just because it's OK in the partial clone case doesn't mean that it's OK in the regular case).
- Also, the commit message for this feature (from
ed8b10f631("fsck: check .gitmodules content", 2018-05-21)) gives a rationale of a newer server being able to protect older clients.
- Servers using receive-pack (instead of fetch-pack) to obtain objects would still be protected, since receive-pack still only accepts one packfile at a time (and there are currently no plans to expand this).
- Also, malicious .gitobjects files could still be crafted that pass fsck checking - for example, by containing a URL (of another server) that refers to a repo with a .gitobjects that would fail fsck.
Quoted 3 lines
So I would rather go with just relaxing the check, but if consensus is that we should still do it, I'll investigate doing it in the connectivity check.
Would this still behave if the $DAYJOB's packfile-uri server support was behaving as documented in packfile-uri.txt, or just because it has outside-spec behavior?
I.e. the spec[1] says this:
This is the implementation: a feature, marked experimental, that allows the server to be configured by one or more uploadpack.blobPackfileUri=<sha1> <uri> entries. Whenever the list of objects to be sent is assembled, all such blobs are excluded, replaced with URIs. The client will download those URIs, expecting them to each point to packfiles containing single blobs.
Which I can't see leaving an opening for more than packfile-uri being to serve up packfiles which each contain a single blob.
In that case it seems to me we'd be OK (but I haven't tested), because fsck_finish() will call read_object_file() which'll try to read that "blob from the object store when it encounters the ".gitmodules" tree, and because we'd have already downloaded the packfile with the blob before moving onto the main dialog.
But as we discussed on-list before[2] this isn't the way packfile-uri actually works in the wild. It's really just sending some arbitrary data in a pack in that URI, with a server that knows what's in that pack and will send the rest in such a way that everything ends up being connected.
As far as I can tell the only reason this is called "packfile URI" and behaves this way in git.git is because of the convenience of intrumenting pack-objects.c with an "oidset excluded_by_config" to not stream those blobs in a pack, but it isn't how the only (I'm pretty sure) production server implementation in the wild behaves at all.
So *poke* about the reply I had in [3] late last year. I think the first thing worth doing here is fixing the docs so they describe how this works. You didn't get back on that (and I also forgot about it until this thread), but it would be nice to know what you think about the suggested prose there.
Re-reading it I'd add something like this to the spec:
A. That the config is called "uploadpack.blobPackfileUri" in git.git
has nothing to do with how this is expected to behave on the wire. It's just to serve the narrow support pack-objects.c has for crafting such a pack.
B. It's then called "packfile-uris" on the wire, nothing to do with
blobs. Just packs with a checksum that we'll validate. An older versions of this spec said "[a] packfiles containing single blobs" but it can be any combination of blob/tree/commit data.
C. A client is then expected to deal with any combination of data
ordered/sliced/split up etc. in any possible way from such a combination of "packfile-uris" and PACK dialog, as long as the end result is valid.
Except that the result of this discussion will perhaps be a more narrow definition for "C".
1. https://github.com/git/git/blob/cd8402e0fd8cfc0ec9fb10e22ffb6aabd992eae1/Documentation/technical/packfile-uri.txt#L37-L41
2. https://lore.kernel.org/git/[email protected]/
3. https://lore.kernel.org/git/[email protected]/
PATCH 1/1 Doc: clarify contents of packfile sent as URI
Clarify that, when the packfile-uri feature is used, the client should not assume that the extra packfiles downloaded would only contain a single blob, but support packfiles containing multiple objects of all types.
--- Documentation/technical/packfile-uri.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Documentation/technical/packfile-uri.txt +5 -2
@@ -37,8 +37,11 @@ at least so that we can test the client. This is the implementation: a feature, marked experimental, that allows the server to be configured by one or more `uploadpack.blobPackfileUri=<sha1> <uri>` entries. Whenever the list of objects to be sent is assembled, all such -blobs are excluded, replaced with URIs. The client will download those URIs, -expecting them to each point to packfiles containing single blobs. +blobs are excluded, replaced with URIs. As noted in "Future work" below, the +server can evolve in the future to support excluding other objects (or other +implementations of servers could be made that support excluding other objects) +without needing a protocol change, so clients should not expect that packfiles +downloaded in this way only contain single blobs. Client design -------------
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Quoted 13 lines
Would this still behave if the $DAYJOB's packfile-uri server support was behaving as documented in packfile-uri.txt, or just because it has outside-spec behavior?
I.e. the spec[1] says this:
This is the implementation: a feature, marked experimental, that allows the server to be configured by one or more
uploadpack.blobPackfileUri=<sha1> <uri>entries. Whenever the list of objects to be sent is assembled, all such blobs are excluded, replaced with URIs. The client will download those URIs, expecting them to each point to packfiles containing single blobs.
Quoted 2 lines
Which I can't see leaving an opening for more than packfile-uri being to serve up packfiles which each contain a single blob.
I meant to leave an opening by referring to this just as a Minimum Viable Product and by explaining in Future Work that the protocol allows evolution of (among other things) which objects the server sends through a URI without any protocol changes.
But in any case, this will also happen even if we constrain ourselves to excluding single blobs and sending them via other packfiles instead - see below.
Quoted 5 lines
In that case it seems to me we'd be OK (but I haven't tested), because
fsck_finish()will callread_object_file()which'll try to read that "blob from the object store when it encounters the ".gitmodules" tree, and because we'd have already downloaded the packfile with the blob before moving onto the main dialog.
We wouldn't be OK, actually. Suppose we have a separate packfile containing only the ".gitmodules" blob - when we call fsck_finish(), we would not have downloaded the other packfile yet. Git processes the entire fetch response by piping the inline packfile (after demux) into index-pack (which is the one that calls fsck_finish()) before it downloads any of the other packfile(s).
Quoted 11 lines
But as we discussed on-list before[2] this isn't the way packfile-uri actually works in the wild. It's really just sending some arbitrary data in a pack in that URI, with a server that knows what's in that pack and will send the rest in such a way that everything ends up being connected.
As far as I can tell the only reason this is called "packfile URI" and behaves this way in git.git is because of the convenience of intrumenting
pack-objects.cwith an "oidsetexcluded_by_config" to not stream those blobs in a pack, but it isn't how the only (I'm pretty sure) production server implementation in the wild behaves at all.
I don't know if this is the only production server implementation, but yes, this particular one (googlesource.com) can put objects of multiple types in the other packfile, not only a single blob. There is some JGit code here [1] that can send a URI corresponding to a "CachedPack" (which may contain all objects, not only blobs) if that pack is also available through a URI.
[1] https://gerrit.googlesource.com/jgit/+/a004820858b54d18c6f72fc94dc33bce8b606d66
Quoted 5 lines
So *poke* about the reply I had in [3] late last year. I think the first thing worth doing here is fixing the docs so they describe how this works. You didn't get back on that (and I also forgot about it until this thread), but it would be nice to know what you think about the suggested prose there.
Rereading that, the issue is that uploadpack.blobPackfileUri is indeed how the current Git server handles it - it excludes a blob and sends a URI instead. The client is not supposed to see how the server has configured it, and should not be constrained by the fact that the server that is being shipped with it only excludes single blobs.
Quoted 6 lines
Re-reading it I'd add something like this to the spec:
A. That the config is called "uploadpack.blobPackfileUri" in git.git
has nothing to do with how this is expected to behave on the wire. It's just to serve the narrow supportpack-objects.chas for crafting such a pack.
Yes, that's true.
Quoted 4 lines
B. It's then called "packfile-uris" on the wire, nothing to do with
blobs. Just packs with a checksum that we'll validate. An older versions of this spec said "[a] packfiles containing single blobs" but it can be any combination of blob/tree/commit data.
Yes, we can delete that line.
Quoted 7 lines
C. A client is then expected to deal with any combination of data
ordered/sliced/split up etc. in any possible way from such a combination of "packfile-uris" and PACK dialog, as long as the end result is valid.Except that the result of this discussion will perhaps be a more narrow definition for "C".
Yes. I think all these can be done just by changing the last sentence in "Server design" - I'll send a patch.
Quoted 6 lines · Jonathan Tan
We wouldn't be OK, actually. Suppose we have a separate packfile containing only the ".gitmodules" blob - when we call
fsck_finish(), we would not have downloaded the other packfile yet. Git processes the entire fetch response by piping the inline packfile (after demux) into index-pack (which is the one that callsfsck_finish()) before it downloads any of the other packfile(s).
Is that order documented as a requirement for implementation?
Naïvely, I would expect that a CDN offload would be to relieve servers from the burden of having to repack ancient part of the history all the time for any new "clone" clients and that is what the "here is a URI, go fetch it because I won't give you objects that already appear there" feature is about. Because we expect that the offloaded contents would not be up-to-date, the traditional packfile transfer would then is used to complete the history with objects necessary for the parts of the history newer than the offloaded contents.
And from that viewpoint, it sounds totally backwards to start processing the up-to-the-minute fresh packfile that came via the traditional packfile transfer before the CDN offloaded contents are fetched and stored safely in our repository.
We probably want to finish interaction with the live server as quickly as possible---it would go counter to that wish if we force the live part of the history hang in flight, unprocessed, while the client downloads offloaded bulk from CDN and processes it, making the server side stuck waiting for some write(2) to go through.
But I still wonder if it is an option to locally delay the processing of the up-to-the-minute-fresh part.
Instead of feeding what comes from them directly to "index-pack --fsck-objects", would it make sense to spool it to a temporary, so that we can release the server early, but then make sure to fetch and process packfile URI material before coming back to process the spooled packdata. That would allow the newer part of the history to have newer trees that still reference the same old .gitmodules that is found in the frozen packfile that comes from CDN, no?
Or can there be a situation where some objects in CDN pack are referred to by objects in the up-to-the-minute-fresh pack (e.g. a ".gitmodules" blob in CDN pack is still unchanged and used in an updated tree in the latest revision) and some other objects in CDN pack refer to an object in the live part of the history? If there is such a cyclic dependency, "index-pack --fsck" one pack at a time would not work, but I doubt such a cycle can arise.
Thanks.
Quoted 43 lines
Quoted 6 lines · Jonathan Tan
We wouldn't be OK, actually. Suppose we have a separate packfile containing only the ".gitmodules" blob - when we call
fsck_finish(), we would not have downloaded the other packfile yet. Git processes the entire fetch response by piping the inline packfile (after demux) into index-pack (which is the one that callsfsck_finish()) before it downloads any of the other packfile(s).Is that order documented as a requirement for implementation?
Naïvely, I would expect that a CDN offload would be to relieve servers from the burden of having to repack ancient part of the history all the time for any new "clone" clients and that is what the "here is a URI, go fetch it because I won't give you objects that already appear there" feature is about. Because we expect that the offloaded contents would not be up-to-date, the traditional packfile transfer would then is used to complete the history with objects necessary for the parts of the history newer than the offloaded contents.
And from that viewpoint, it sounds totally backwards to start processing the up-to-the-minute fresh packfile that came via the traditional packfile transfer before the CDN offloaded contents are fetched and stored safely in our repository.
We probably want to finish interaction with the live server as quickly as possible---it would go counter to that wish if we force the live part of the history hang in flight, unprocessed, while the client downloads offloaded bulk from CDN and processes it, making the server side stuck waiting for some write(2) to go through.
But I still wonder if it is an option to locally delay the processing of the up-to-the-minute-fresh part.
Instead of feeding what comes from them directly to "index-pack --fsck-objects", would it make sense to spool it to a temporary, so that we can release the server early, but then make sure to fetch and process packfile URI material before coming back to process the spooled packdata. That would allow the newer part of the history to have newer trees that still reference the same old .gitmodules that is found in the frozen packfile that comes from CDN, no?
Quoted 7 lines
Or can there be a situation where some objects in CDN pack are referred to by objects in the up-to-the-minute-fresh pack (e.g. a ".gitmodules" blob in CDN pack is still unchanged and used in an updated tree in the latest revision) and some other objects in CDN pack refer to an object in the live part of the history? If there is such a cyclic dependency, "index-pack --fsck" one pack at a time would not work, but I doubt such a cycle can arise.
My intention is that the order of the packfiles (and cyclic dependencies) would not matter, so we wouldn't need to delay any processing of the up-to-the-minute-fresh part. I'm currently working on getting index-pack to output a list of the dangling .gitmodules files, so that fetch-pack (its consumer) can do one final fsck on those files.
Another way, as you said, is to say that the order of the packfiles matters (which potentially allows some simplification on the client side) but I don't think that we need to lose this flexibility.
Quoted 10 lines · Jonathan Tan
Quoted 9 lines
Jonathan Tan <[email protected]> writes:
Or can there be a situation where some objects in CDN pack are referred to by objects in the up-to-the-minute-fresh pack (e.g. a ".gitmodules" blob in CDN pack is still unchanged and used in an updated tree in the latest revision) and some other objects in CDN pack refer to an object in the live part of the history? If there is such a cyclic dependency, "index-pack --fsck" one pack at a time would not work, but I doubt such a cycle can arise.
Quoted 5 lines
My intention is that the order of the packfiles (and cyclic dependencies) would not matter...
I'm currently working on
getting index-pack to output a list of the dangling .gitmodules files, so that fetch-pack (its consumer) can do one final fsck on those files.
In other words, it essentially becomes "we check everything we obtained as a single unit across multiple packs, but for performance we'll let index-pack work as much as possible on each individual pack while it has necessary data in its core, and then we conclude by checking the objects on the 'boundaries' that cannot be validated using info that is only in one pack".
That does sound like the right approach. THanks.
cover Check .gitmodules when using packfile URIs
In reply to Jonathan TanThis patch set resolves the .gitmodules-and-tree-in-separate-packfiles issue I mentioned in [1] by having index-pack print out all dangling .gitmodules (instead of returning with an error code) and then teaching fetch-pack to read those and run its own fsck checks after all index-pack invocations are complete.
As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.
I also discovered a bug in that different index-pack arguments were used when processing the inline packfile and when processing the ones referenced by URIs. Patch 1-3 fixes that bug by passing the arguments to use as a space-separated URL-encoded list. (URL-encoded so that we can have spaces in the arguments.) Again, if anyone has a better idea, I'm interested. It is only in patch 4 that we have the dangling .gitmodules fix.
[1] https://lore.kernel.org/git/[email protected]/
Jonathan Tan (4):
http: allow custom index-pack args
http-fetch: allow custom index-pack args
fetch-pack: with packfile URIs, use index-pack arg
fetch-pack: print and use dangling .gitmodules
Documentation/git-http-fetch.txt | 9 ++- Documentation/git-index-pack.txt | 7 +- builtin/index-pack.c | 9 ++- builtin/receive-pack.c | 2 +- fetch-pack.c | 106 ++++++++++++++++++++++++++----- fsck.c | 16 +++-- fsck.h | 8 +++ http-fetch.c | 35 +++++++++- http.c | 15 +++-- http.h | 10 +-- pack-write.c | 8 ++- pack.h | 2 +- t/t5550-http-fetch-dumb.sh | 3 +- t/t5702-protocol-v2.sh | 47 ++++++++++++++ 14 files changed, 232 insertions(+), 45 deletions(-)
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
PATCH 1/4 http: allow custom index-pack args
Currently, when fetching, packfiles referenced by URIs are run through index-pack without any arguments other than --stdin and --keep, no matter what arguments are used for the packfile that is inline in the fetch response. As a preparation for ensuring that all packs (whether inline or not) use the same index-pack arguments, teach the http subsystem to allow custom index-pack arguments.
http-fetch has been updated to use the new API. For now, it passes --keep alone instead of --keep with a process ID, but this is only temporary because http-fetch itself will be taught to accept index-pack parameters (instead of using a hardcoded constant) in a subsequent commit.
--- http-fetch.c | 6 +++++- http.c | 15 ++++++++------- http.h | 10 +++++----- 3 files changed, 18 insertions(+), 13 deletions(-)
http-fetch.c +5 -1
@@ -43,6 +43,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,return rc; } +static const char *index_pack_args[] = + {"index-pack" ,"--stdin" ,"--keep" ,NULL }; +static void fetch_single_packfile (struct object_id *packfile_hash,const char *url) {struct http_pack_request *preq;
@@ -55,7 +58,8 @@ static void fetch_single_packfile(struct object_id *packfile_hash,if (preq ==NULL )die ("couldn't create http pack request" ); preq->slot->results = &results; - preq->generate_keep =1 ; + preq->index_pack_args = index_pack_args; + preq->preserve_index_pack_stdout =1 ;if (start_active_slot (preq->slot)) {run_active_slot (preq->slot);
http.c +8 -7
@@ -2259,6 +2259,9 @@ void release_http_pack_request(struct http_pack_request *preq)free (preq); } +static const char *default_index_pack_args[] = + {"index-pack" ,"--stdin" ,NULL }; +int finish_http_pack_request (struct http_pack_request *preq) {struct child_process ip =CHILD_PROCESS_INIT ;
@@ -2270,17 +2273,15 @@ int finish_http_pack_request(struct http_pack_request *preq) tmpfile_fd =xopen (preq->tmpfile.buf,O_RDONLY ); -strvec_push (&ip.args,"index-pack" ); -strvec_push (&ip.args,"--stdin" ); ip.git_cmd =1 ; ip.in = tmpfile_fd; -if (preq->generate_keep) { -strvec_pushf (&ip.args,"--keep=git %" PRIuMAX, - (uintmax_t )getpid ()); + ip.argv = preq->index_pack_args ? preq->index_pack_args + : default_index_pack_args; + +if (preq->preserve_index_pack_stdout) ip.out =0 ; - }else { +else ip.no_stdout =1 ; - }if (run_command (&ip)) { ret =-1 ;
http.h +5 -5
@@ -218,12 +218,12 @@ struct http_pack_request {char *url;/* -* If this is true, finish_http_pack_request() will pass "--keep" to -* index-pack, resulting in the creation of a keep file, and will not -* suppress its stdout (that is, the "keep\t<hash>\n" line will be -* printed to stdout). +* index-pack command to run. Must be terminated by NULL. +* +* If NULL, defaults to {"index-pack", "--stdin", NULL}. */ - unsigned generate_keep : 1; +const char **index_pack_args; + unsigned preserve_index_pack_stdout : 1;FILE *packfile;struct strbuf tmpfile;
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
PATCH 2/4 http-fetch: allow custom index-pack args
In reply to Jonathan TanThis is the next step in teaching fetch-pack to pass its index-pack arguments when processing packfiles referenced by URIs.
The "--keep" in fetch-pack.c will be replaced with a full message in a subsequent commit.
--- Documentation/git-http-fetch.txt | 9 ++++++-- fetch-pack.c | 1 + http-fetch.c | 35 +++++++++++++++++++++++++++----- t/t5550-http-fetch-dumb.sh | 3 ++- 4 files changed, 40 insertions(+), 8 deletions(-)
Documentation/git-http-fetch.txt +7 -2
@@ -41,11 +41,16 @@ commit-id:: <commit-id>['\t'<filename-as-in--w>] --packfile=<hash>:: - Instead of a commit id on the command line (which is not expected in + For internal use only. Instead of a commit id on the command line (which is not expected in this case), 'git http-fetch' fetches the packfile directly at the given URL and uses index-pack to generate corresponding .idx and .keep files. The hash is used to determine the name of the temporary file and is - arbitrary. The output of index-pack is printed to stdout. + arbitrary. The output of index-pack is printed to stdout. Requires + --index-pack-args. + +--index-pack-args=<args>:: + For internal use only. The command to run on the contents of the + downloaded pack. Arguments are URL-encoded separated by spaces. --recover:: Verify that everything reachable from target is fetched. Used after
fetch-pack.c +1 -0
@@ -1645,6 +1645,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,strvec_pushf (&cmd.args,"--packfile=%.*s" , (int ) the_hash_algo->hexsz, packfile_uris.items[i].string); +strvec_push (&cmd.args,"--index-pack-args=index-pack --stdin --keep" );strvec_push (&cmd.args, uri); cmd.git_cmd =1 ; cmd.no_stdin =1 ;
http-fetch.c +30 -5
@@ -3,6 +3,7 @@#include "exec-cmd.h" #include "http.h" #include "walker.h" +#include "strvec.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url" ;
@@ -43,11 +44,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,return rc; } -static const char *index_pack_args[] = - {"index-pack" ,"--stdin" ,"--keep" ,NULL }; -static void fetch_single_packfile (struct object_id *packfile_hash, -const char *url) { +const char *url, +const char **index_pack_args) {struct http_pack_request *preq;struct slot_results results;int ret;
@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)int packfile =0 ;int nongit;struct object_id packfile_hash; +const char *index_pack_args =NULL ;setup_git_directory_gently (&nongit);
@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv) packfile =1 ;if (parse_oid_hex (p, &packfile_hash, &end) || *end)die (_ ("argument to --packfile must be a valid hash (got '%s')" ), p); + }else if (skip_prefix (argv[arg],"--index-pack-args=" , &p)) { + index_pack_args = p; } arg++; }
@@ -128,10 +130,33 @@ int cmd_main(int argc, const char **argv)git_config (git_default_config,NULL );if (packfile) { -fetch_single_packfile (&packfile_hash, argv[arg]); +struct strvec encoded =STRVEC_INIT ; +char **raw; +int i; + +if (!index_pack_args) +die (_ ("--packfile requires --index-pack-args" )); + +strvec_split (&encoded, index_pack_args); + +CALLOC_ARRAY (raw, encoded.nr +1 ); +for (i =0 ; i < encoded.nr; i++) + raw[i] =url_percent_decode (encoded.v[i]); + +fetch_single_packfile (&packfile_hash, argv[arg], + (const char **) raw); + +for (i =0 ; i < encoded.nr; i++) +free (raw[i]); +free (raw); +strvec_clear (&encoded); +return 0 ; } +if (index_pack_args) +die (_ ("--index-pack-args can only be used with --packfile" )); +if (commits_on_stdin) { commits =walker_targets_stdin (&commit_id, &write_ref); }else {
t/t5550-http-fetch-dumb.sh +2 -1
@@ -224,7 +224,8 @@ test_expect_success 'http-fetch --packfile' ' git init packfileclient && p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) && - git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out && + git -C packfileclient http-fetch --packfile=$ARBITRARY \ + --index-pack-args="index-pack --stdin --keep" "$HTTPD_URL"/dumb/repo_pack.git/$p >out && grep "^keep.[0-9a-f]\{16,\}$" out && cut -c6- out >packhash &&
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
Re: [PATCH 2/4] http-fetch: allow custom index-pack args
Documentation/git-http-fetch.txt commit-id:: · line 44
Quoted 3 lines · Jonathan Tan
--packfile=<hash>::
Documentation/git-http-fetch.txt +1
-1- Instead of a commit id on the command line (which is not expected in + For internal use only. Instead of a commit id on the command line (which is not expected in
Leaves the rest at ~79 and this long line at ~100. Perhaps a follow-up change to re-word-wrap would be in order?
Re: [PATCH 2/4] http-fetch: allow custom index-pack args
Quoted 8 lines · Jonathan Tan
Documentation/git-http-fetch.txt commit-id:: · line 44
Quoted 4 lines
--packfile=<hash>::
Documentation/git-http-fetch.txt +1
-1- Instead of a commit id on the command line (which is not expected in + For internal use only. Instead of a commit id on the command line (which is not expected inLeaves the rest at ~79 and this long line at ~100. Perhaps a follow-up change to re-word-wrap would be in order?
Hmm...I'll split that onto two lines then. I don't think it's worth the extra commit in history to have it exactly wrapped right, so I'll forgo the follow-up change for now.
Re: [PATCH 2/4] http-fetch: allow custom index-pack args
In reply to Jonathan TanQuoted 24 lines · Jonathan Tan
This is the next step in teaching fetch-pack to pass its index-pack arguments when processing packfiles referenced by URIs.
The "--keep" in
fetch-pack.cwill be replaced with a full message in a subsequent commit.Signed-off-by Jonathan Tan <[email protected]>--- Documentation/git-http-fetch.txt | 9 ++++++-- fetch-pack.c | 1 + http-fetch.c | 35 +++++++++++++++++++++++++++----- t/t5550-http-fetch-dumb.sh | 3 ++- 4 files changed, 40 insertions(+), 8 deletions(-)Documentation/git-http-fetch.txt +1
-1@@ -41,11 +41,16 @@ commit-id:: <commit-id>['\t'<filename-as-in--w>] --packfile=<hash>:: - Instead of a commit id on the command line (which is not expected in + For internal use only. Instead of a commit id on the command line (which is not expected in
Documentation/git-http-fetch.txt commit-id:: · line 53
Quoted 10 lines
Documentation/git-http-fetch.txt +6
-1this case), 'git http-fetch' fetches the packfile directly at the given URL and uses index-pack to generate corresponding .idx and .keep files. The hash is used to determine the name of the temporary file and is - arbitrary. The output of index-pack is printed to stdout. + arbitrary. The output of index-pack is printed to stdout. Requires + --index-pack-args. + +--index-pack-args=<args>:: + For internal use only. The command to run on the contents of the + downloaded pack. Arguments are URL-encoded separated by spaces.
I'm a bit skeptical of using URL encoding to work around embedded spaces. I believe in Emily's config-based hooks series, she wrote an argument parser to pull repeated arguments into a strvec, could you do something like that here?
I'm sympathetic to the idea that since this is an internal-only flag, we can be a bit weird with the argument format, though.
Quoted 109 lines
Documentation/git-http-fetch.txt +0
-0--recover:: Verify that everything reachable from target is fetched. Used afterfetch-pack.c +1
-0@@ -1645,6 +1645,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,strvec_pushf (&cmd.args,"--packfile=%.*s" , (int ) the_hash_algo->hexsz, packfile_uris.items[i].string); +strvec_push (&cmd.args,"--index-pack-args=index-pack --stdin --keep" );strvec_push (&cmd.args, uri); cmd.git_cmd =1 ; cmd.no_stdin =1 ;http-fetch.c +30
-5@@ -3,6 +3,7 @@#include "exec-cmd.h" #include "http.h" #include "walker.h" +#include "strvec.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url" ;@@ -43,11 +44,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,return rc; } -static const char *index_pack_args[] = - {"index-pack" ,"--stdin" ,"--keep" ,NULL }; -static void fetch_single_packfile (struct object_id *packfile_hash, -const char *url) { +const char *url, +const char **index_pack_args) {struct http_pack_request *preq;struct slot_results results;int ret;@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)int packfile =0 ;int nongit;struct object_id packfile_hash; +const char *index_pack_args =NULL ;setup_git_directory_gently (&nongit);@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv) packfile =1 ;if (parse_oid_hex (p, &packfile_hash, &end) || *end)die (_ ("argument to --packfile must be a valid hash (got '%s')" ), p); + }else if (skip_prefix (argv[arg],"--index-pack-args=" , &p)) { + index_pack_args = p; } arg++; }@@ -128,10 +130,33 @@ int cmd_main(int argc, const char **argv)git_config (git_default_config,NULL );if (packfile) { -fetch_single_packfile (&packfile_hash, argv[arg]); +struct strvec encoded =STRVEC_INIT ; +char **raw; +int i; + +if (!index_pack_args) +die (_ ("--packfile requires --index-pack-args" )); + +strvec_split (&encoded, index_pack_args); + +CALLOC_ARRAY (raw, encoded.nr +1 ); +for (i =0 ; i < encoded.nr; i++) + raw[i] =url_percent_decode (encoded.v[i]); + +fetch_single_packfile (&packfile_hash, argv[arg], + (const char **) raw); + +for (i =0 ; i < encoded.nr; i++) +free (raw[i]); +free (raw); +strvec_clear (&encoded); +return 0 ; } +if (index_pack_args) +die (_ ("--index-pack-args can only be used with --packfile" )); +if (commits_on_stdin) { commits =walker_targets_stdin (&commit_id, &write_ref); }else {t/t5550-http-fetch-dumb.sh +2
-1@@ -224,7 +224,8 @@ test_expect_success 'http-fetch --packfile' ' git init packfileclient && p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) && - git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out && + git -C packfileclient http-fetch --packfile=$ARBITRARY \ + --index-pack-args="index-pack --stdin --keep" "$HTTPD_URL"/dumb/repo_pack.git/$p >out && grep "^keep.[0-9a-f]\{16,\}$" out && cut -c6- out >packhash &&Signature · 1 line
2.30.0.280.ga3ce27912f-goog
Re: [PATCH 2/4] http-fetch: allow custom index-pack args
Quoted 11 lines · Josh Steadmon
Documentation/git-http-fetch.txt commit-id:: · line 53
Quoted 3 lines
+--index-pack-args=<args>::
Documentation/git-http-fetch.txt +2
-0+ For internal use only. The command to run on the contents of the + downloaded pack. Arguments are URL-encoded separated by spaces.I'm a bit skeptical of using URL encoding to work around embedded spaces. I believe in Emily's config-based hooks series, she wrote an argument parser to pull repeated arguments into a strvec, could you do something like that here?
I'm sympathetic to the idea that since this is an internal-only flag, we can be a bit weird with the argument format, though.
We tend to prefer quote.c::sq_quote*() suite of quoting; does this codepath have very different constraints that require different encoding?
Thanks.
Re: [PATCH 2/4] http-fetch: allow custom index-pack args
Quoted 11 lines
Quoted 9 lines · Josh Steadmon
Documentation/git-http-fetch.txt commit-id:: · line 53
Quoted 3 lines
+--index-pack-args=<args>::
Documentation/git-http-fetch.txt +2
-0+ For internal use only. The command to run on the contents of the + downloaded pack. Arguments are URL-encoded separated by spaces.I'm a bit skeptical of using URL encoding to work around embedded spaces. I believe in Emily's config-based hooks series, she wrote an argument parser to pull repeated arguments into a strvec, could you do something like that here?
Quoted 6 lines
Quoted 2 lines
I'm sympathetic to the idea that since this is an internal-only flag, we can be a bit weird with the argument format, though.
We tend to prefer quote.c::sq_quote*() suite of quoting; does this codepath have very different constraints that require different encoding?
My main issue was that I needed to join arbitrary strings and then split them, which is why I URL-encoded them (so that they would no longer contain spaces) and then used spaces as the "join" separator. With Josh's suggestion, I wouldn't need any sort of encoding or quoting, so I think I'll use that.
PATCH 3/4 fetch-pack: with packfile URIs, use index-pack arg
In reply to Jonathan TanUnify the index-pack arguments used when processing the inline pack and when downloading packfiles referenced by URIs. This is done by teaching get_pack() to also store the index-pack arguments whenever at least one packfile URI is given, and then when processing the packfile URI(s), using the stored arguments.
--- fetch-pack.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
fetch-pack.c +26 -9
@@ -797,12 +797,13 @@ static void write_promisor_file(const char *keep_name, }/* -* Pass 1 as "only_packfile" if the pack received is the only pack in this -* fetch request (that is, if there were no packfile URIs provided). +* If packfile URIs were provided, pass a non-NULL pointer to index_pack_args. +* The string to pass as the --index-pack-args argument to http-fetch will be +* stored there. (It must be freed by the caller.) */ static int get_pack (struct fetch_pack_args *args,int xd[2 ],struct string_list *pack_lockfiles, -int only_packfile, +char **index_pack_args,struct ref **sought,int nr_sought) {struct async demux;
@@ -845,7 +846,7 @@ static int get_pack(struct fetch_pack_args *args,strvec_push (&cmd.args, alternate_shallow_file); } -if (do_keep || args->from_promisor) { +if (do_keep || args->from_promisor || index_pack_args) {if (pack_lockfiles) cmd.out =-1 ; cmd_name ="index-pack" ;
@@ -863,7 +864,7 @@ static int get_pack(struct fetch_pack_args *args,"--keep=fetch-pack %" PRIuMAX" on %s" , (uintmax_t)getpid(), hostname); } -if (only_packfile && args->check_self_contained_and_connected) +if (!index_pack_args && args->check_self_contained_and_connected)strvec_push (&cmd.args,"--check-self-contained-and-connected" );else /*
@@ -901,7 +902,7 @@ static int get_pack(struct fetch_pack_args *args, : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0) { -if (args->from_promisor || !only_packfile) +if (args->from_promisor || index_pack_args)/* * We cannot use --strict in index-pack because it * checks both broken objects and links, but we only
@@ -913,6 +914,19 @@ static int get_pack(struct fetch_pack_args *args, fsck_msg_types.buf); } +if (index_pack_args) { +struct strbuf joined =STRBUF_INIT ; +int i; + +for (i =0 ; i < cmd.args.nr; i++) { +if (i) +strbuf_addch (&joined,' ' ); +strbuf_addstr_urlencode (&joined, cmd.args.v[i], + is_rfc3986_unreserved); + } + *index_pack_args =strbuf_detach (&joined,NULL ); + } + cmd.in = demux.out; cmd.git_cmd =1 ;if (start_command (&cmd))
@@ -1084,7 +1098,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, alternate_shallow_file =setup_temporary_shallow (si->shallow); else alternate_shallow_file =NULL ; -if (get_pack (args, fd, pack_lockfiles,1 , sought, nr_sought)) +if (get_pack (args, fd, pack_lockfiles,NULL , sought, nr_sought))die (_ ("git fetch-pack: fetch failed." )); all_done:
@@ -1535,6 +1549,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,int seen_ack =0 ;struct string_list packfile_uris =STRING_LIST_INIT_DUP ;int i; +char *index_pack_args =NULL ; negotiator = &negotiator_alloc;fetch_negotiator_init (r, negotiator);
@@ -1624,7 +1639,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,receive_packfile_uris (&reader, &packfile_uris);process_section_header (&reader,"packfile" ,0 );if (get_pack (args, fd, pack_lockfiles, - !packfile_uris.nr, sought, nr_sought)) + packfile_uris.nr ? &index_pack_args :NULL , + sought, nr_sought))die (_ ("git fetch-pack: fetch failed." ));do_check_stateless_delimiter (args, &reader);
@@ -1645,7 +1661,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,strvec_pushf (&cmd.args,"--packfile=%.*s" , (int ) the_hash_algo->hexsz, packfile_uris.items[i].string); -strvec_push (&cmd.args,"--index-pack-args=index-pack --stdin --keep" ); +strvec_pushf (&cmd.args,"--index-pack-args=%s" , index_pack_args);strvec_push (&cmd.args, uri); cmd.git_cmd =1 ; cmd.no_stdin =1 ;
@@ -1681,6 +1697,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, packname)); }string_list_clear (&packfile_uris,0 ); +FREE_AND_NULL (index_pack_args);if (negotiator) negotiator->release (negotiator);
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
PATCH 4/4 fetch-pack: print and use dangling .gitmodules
In reply to Jonathan TanTeach index-pack to print dangling .gitmodules links after its "keep" or "pack" line instead of declaring an error, and teach fetch-pack to check such lines printed.
This allows the tree side of the .gitmodules link to be in one packfile and the blob side to be in another without failing the fsck check, because it is now fetch-pack which checks such objects after all packfiles have been downloaded and indexed (and not index-pack on an individual packfile, as it is before this commit).
--- Documentation/git-index-pack.txt | 7 ++- builtin/index-pack.c | 9 +++- builtin/receive-pack.c | 2 +- fetch-pack.c | 78 +++++++++++++++++++++++++++----- fsck.c | 16 +++++-- fsck.h | 8 ++++ pack-write.c | 8 +++- pack.h | 2 +- t/t5702-protocol-v2.sh | 47 +++++++++++++++++++ 9 files changed, 155 insertions(+), 22 deletions(-)
Documentation/git-index-pack.txt +6 -1
@@ -78,7 +78,12 @@ OPTIONS Die if the pack contains broken links. For internal use only. --fsck-objects:: - Die if the pack contains broken objects. For internal use only. + For internal use only. ++ +Die if the pack contains broken objects. If the pack contains a tree +pointing to a .gitmodules blob that does not exist, prints the hash of +that blob (for the caller to check) after the hash that goes into the +name of the pack/idx file (see "Notes"). --threads=<n>:: Specifies the number of threads to spawn when resolving
builtin/index-pack.c +7 -2
@@ -1888,8 +1888,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)else close (input_fd); -if (do_fsck_object &&fsck_finish (&fsck_options)) -die (_ ("fsck error in pack objects" )); +if (do_fsck_object) { +struct fsck_options fo =FSCK_OPTIONS_STRICT ; + + fo.print_dangling_gitmodules =1 ; +if (fsck_finish (&fo)) +die (_ ("fsck error in pack objects" )); + }free (objects);strbuf_release (&index_name_buf);
builtin/receive-pack.c +1 -1
@@ -2275,7 +2275,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) status =start_command (&child);if (status)return "index-pack fork failed" ; - pack_lockfile =index_pack_lockfile (child.out); + pack_lockfile =index_pack_lockfile (child.out,NULL );close (child.out); status =finish_command (&child);if (status)
fetch-pack.c +66 -12
159 lines not on this page · raw message
fsck.c +12 -4
@@ -1243,6 +1243,11 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } +void register_found_gitmodules (const struct object_id *oid) +{ +oidset_insert (&gitmodules_found, oid); +} +int fsck_finish (struct fsck_options *options) {int ret =0 ;
@@ -1262,10 +1267,13 @@ int fsck_finish(struct fsck_options *options)if (!buf) {if (is_promisor_object (oid))continue ; - ret |=report (options, - oid,OBJ_BLOB , -FSCK_MSG_GITMODULES_MISSING , -"unable to read .gitmodules blob" ); +if (options->print_dangling_gitmodules) +printf ("%s\n" ,oid_to_hex (oid)); +else + ret |=report (options, + oid,OBJ_BLOB , +FSCK_MSG_GITMODULES_MISSING , +"unable to read .gitmodules blob" );continue ; }
fsck.h +8 -0
@@ -41,6 +41,12 @@ struct fsck_options {int *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; + +/* +* If 1, print the hashes of missing .gitmodules blobs instead of +* considering them to be errors. +*/ + unsigned print_dangling_gitmodules:1; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
@@ -62,6 +68,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); +void register_found_gitmodules (const struct object_id *oid); +/* * Some fsck checks are context-dependent, and may end up queued; run this * after completing all fsck_object() calls in order to resolve any remaining
pack-write.c +7 -1
@@ -272,7 +272,7 @@ void fixup_pack_header_footer(int pack_fd,fsync_or_die (pack_fd, pack_name); } -char *index_pack_lockfile (int ip_out) +char *index_pack_lockfile (int ip_out,int *is_well_formed) {char packname[GIT_MAX_HEXSZ +6 ];const int len = the_hash_algo->hexsz +6 ;
@@ -286,11 +286,17 @@ char *index_pack_lockfile(int ip_out)*/ if (read_in_full (ip_out, packname, len) == len && packname[len-1 ] =='\n' ) {const char *name; + +if (is_well_formed) + *is_well_formed =1 ; packname[len-1 ] =0 ;if (skip_prefix (packname,"keep\t" , &name))return xstrfmt ("%s/pack/pack-%s.keep" ,get_object_directory (), name); +return NULL ; } +if (is_well_formed) + *is_well_formed =0 ;return NULL ; }
pack.h +1 -1
@@ -85,7 +85,7 @@ int verify_pack_index(struct packed_git *);int verify_pack (struct repository *,struct packed_git *,verify_fn fn,struct progress *,uint32_t );off_t write_pack_header (struct hashfile *f,uint32_t );void fixup_pack_header_footer (int ,unsigned char *,const char *,uint32_t ,unsigned char *,off_t ); -char *index_pack_lockfile (int fd); +char *index_pack_lockfile (int fd,int *is_well_formed);/* * The "hdr" output buffer should be at least this big, which will handle sizes
t/t5702-protocol-v2.sh +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
t/t5702-protocol-v2.sh test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' · line 959
Quoted 9 lines · Jonathan Tan
t/t5702-protocol-v2.sh +6
-0+ sane_unset GIT_TEST_SIDEBAND_ALL && + git -c protocol.version=2 -c transfer.fsckobjects=1 \ + -c fetch.uriprotocols=http,https \ + clone "$HTTPD_URL/smart/http_parent" http_child && + + # Ensure that there are exactly 4 files (2 .pack and 2 .idx).
Ehh, please don't. We may add multi-pack-index there, or perhaps reverse index files in the future. If you care about having two packs logically because you are exercising the out-of-band prepackaged packfile plus the dynamic transfer, make sure you have two packs (and probably the idx files that go with them). Don't assume there will be one .idx each for them *AND* nothing else there.
t/t5702-protocol-v2.sh test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' · line 962
Quoted 3 lines
t/t5702-protocol-v2.sh +3
-0+ ls http_child/.git/objects/pack/* >filelist && + test_line_count = 4 filelist +'
IOW,
d=http_child/.git/objects/pack/ ls "$d"/*.pack "$d"/*.idx >filelist && test_line_count = 4 filelist
or something like that.
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
Quoted 26 lines · Junio C Hamano
t/t5702-protocol-v2.sh
Quoted 9 lines · Jonathan Tan
t/t5702-protocol-v2.sh +6
-0+ sane_unset GIT_TEST_SIDEBAND_ALL && + git -c protocol.version=2 -c transfer.fsckobjects=1 \ + -c fetch.uriprotocols=http,https \ + clone "$HTTPD_URL/smart/http_parent" http_child && + + # Ensure that there are exactly 4 files (2 .pack and 2 .idx).Ehh, please don't. We may add multi-pack-index there, or perhaps reverse index files in the future. If you care about having two packs logically because you are exercising the out-of-band prepackaged packfile plus the dynamic transfer, make sure you have two packs (and probably the idx files that go with them). Don't assume there will be one .idx each for them *AND* nothing else there.
t/t5702-protocol-v2.sh
Quoted 3 lines
t/t5702-protocol-v2.sh +3
-0+ ls http_child/.git/objects/pack/* >filelist && + test_line_count = 4 filelist +'IOW,
Quoted 5 lines
d=http_child/.git/objects/pack/ ls "$d"/*.pack "$d"/*.idx >filelist && test_line_count = 4 filelistor something like that.
FYI, I have the following queued to make the tip of 'seen' pass the tests.
---- >8 -------- >8 -------- >8 -------- >8 -------- >8 -------- >8 ----
From: Junio C Hamano <[email protected]>
Date: Mon, 25 Jan 2021 17:27:10 -0800
Subject: [PATCH] SQUASH??? test fix
--- t/t5702-protocol-v2.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
t/t5702-protocol-v2.sh +9 -6
@@ -847,8 +847,9 @@ test_expect_success 'part of packfile response provided as URI' ' test -f hfound && test -f h2found && - # Ensure that there are exactly 6 files (3 .pack and 3 .idx). - ls http_child/.git/objects/pack/* >filelist && + # Ensure that there are exactly 3 packfiles with associated .idx + ls http_child/.git/objects/pack/*.pack \ + http_child/.git/objects/pack/*.idx >filelist && test_line_count = 6 filelist '
@@ -901,8 +902,9 @@ test_expect_success 'packfile-uri with transfer.fsckobjects' ' -c fetch.uriprotocols=http,https \ clone "$HTTPD_URL/smart/http_parent" http_child && - # Ensure that there are exactly 4 files (2 .pack and 2 .idx). - ls http_child/.git/objects/pack/* >filelist && + # Ensure that there are exactly 2 packfiles with associated .idx + ls http_child/.git/objects/pack/*.pack \ + http_child/.git/objects/pack/*.idx >filelist && test_line_count = 4 filelist '
@@ -956,8 +958,9 @@ test_expect_success 'packfile-uri with transfer.fsckobjects succeeds when .gitmo -c fetch.uriprotocols=http,https \ clone "$HTTPD_URL/smart/http_parent" http_child && - # Ensure that there are exactly 4 files (2 .pack and 2 .idx). - ls http_child/.git/objects/pack/* >filelist && + # Ensure that there are exactly 2 packfiles with associated .idx + ls http_child/.git/objects/pack/*.pack \ + http_child/.git/objects/pack/*.idx >filelist && test_line_count = 4 filelist '
Signature · 1 line
2.30.0-509-gbbf2750a06
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
Quoted 14 lines
Quoted 14 lines
Ehh, please don't. We may add multi-pack-index there, or perhaps reverse index files in the future. If you care about having two packs logically because you are exercising the out-of-band prepackaged packfile plus the dynamic transfer, make sure you have two packs (and probably the idx files that go with them). Don't assume there will be one .idx each for them *AND* nothing else there.
Review
Quoted 3 lines
(quoted diff) +3
-0+ ls http_child/.git/objects/pack/* >filelist && + test_line_count = 4 filelist +'IOW,
Quoted 8 lines
Quoted 5 lines
d=http_child/.git/objects/pack/ ls "$d"/*.pack "$d"/*.idx >filelist && test_line_count = 4 filelistor something like that.
FYI, I have the following queued to make the tip of 'seen' pass the tests.
[snip]
OK - I'll include these changes in the next version.
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
In reply to Jonathan Tanfsck.c int fsck_error_function(struct fsck_options *o, · line 1250
Quoted 5 lines · Jonathan Tan
fsck.c +5
-0+void register_found_gitmodules (const struct object_id *oid) +{ +oidset_insert (&gitmodules_found, oid); +} +
In fsck.c we only use this variable to insert into it, or in fsck_blob() to do the actual check, but then we either abort early if we've found it, or right after that:
if (object_on_skiplist(options, oid))
return 0;
So (along with comments I have below...) you could just use the existing "skiplist" option instead, no?
Quoted 39 lines
int
fsck_finish(struct fsck_options *options)
{fsck.c +7
-4int ret =0 ;@@ -1262,10 +1267,13 @@ int fsck_finish(struct fsck_options *options)if (!buf) {if (is_promisor_object (oid))continue ; - ret |=report (options, - oid,OBJ_BLOB , -FSCK_MSG_GITMODULES_MISSING , -"unable to read .gitmodules blob" ); +if (options->print_dangling_gitmodules) +printf ("%s\n" ,oid_to_hex (oid)); +else + ret |=report (options, + oid,OBJ_BLOB , +FSCK_MSG_GITMODULES_MISSING , +"unable to read .gitmodules blob" );continue ; }fsck.h +6
-0@@ -41,6 +41,12 @@ struct fsck_options {int *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; + +/* +* If 1, print the hashes of missing .gitmodules blobs instead of +* considering them to be errors. +*/ + unsigned print_dangling_gitmodules:1; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
fsck.h int fsck_walk(struct object *obj, void *data, struct fsck_options *options); · line 75
Quoted 8 lines
fsck.h +2
-0@@ -62,6 +68,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); +void register_found_gitmodules (const struct object_id *oid); +/* * Some fsck checks are context-dependent, and may end up queued; run this * after completing all fsck_object() calls in order to resolve any remaining
This whole thing seems just like the bad path I took in earlier rounds of my in-flight mktag series. You don't need this new custom API. You just setup an error handler for your fsck which ignores / prints / logs / whatever the OIDs you want if you get a FSCK_MSG_GITMODULES_MISSING error, which you then "return 0" on.
If you don't have FSCK_MSG_GITMODULES_MISSING punt and call fsck_error_function().
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
Quoted 11 lines · Jonathan Tan
fsck.c int fsck_error_function(struct fsck_options *o, · line 1250
Quoted 6 lines
fsck.c +5
-0+void register_found_gitmodules (const struct object_id *oid) +{ +oidset_insert (&gitmodules_found, oid); +} +In
fsck.cwe only use this variable to insert into it, or infsck_blob()to do the actual check, but then we either abort early if we've found it, or right after that:
By "this variable", do you mean gitmodules_found? fsck_finish() consumes it.
Quoted 5 lines
if (
object_on_skiplist(options, oid))
return 0;So (along with comments I have below...) you could just use the existing "skiplist" option instead, no?
I don't understand this part (in particular, the part you quoted). About "skiplist", I'll reply to your other email [1] which has more details.
[1] https://lore.kernel.org/git/[email protected]/
Quoted 8 lines
This whole thing seems just like the bad path I took in earlier rounds of my in-flight mktag series. You don't need this new custom API. You just setup an error handler for your fsck which ignores / prints / logs / whatever the OIDs you want if you get a
FSCK_MSG_GITMODULES_MISSINGerror, which you then "return 0" on.If you don't have
FSCK_MSG_GITMODULES_MISSINGpunt and callfsck_error_function().
I tried that first, and the issue is that IDs like FSCK_MSG_GITMODULES_MISSING are internal to fsck.c. As for whether we should start exposing the IDs publicly, I think we should wait until a few new cases like this come up, so that we more fully understand the requirements first.
Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules
On Thu, Jan 28 2021, Jonathan Tan wrote:
Sorry I managed to miss this at the time. Hopefully a late reply is better than never.
Quoted 12 lines
Quoted 11 lines · Jonathan Tan
fsck.c int fsck_error_function(struct fsck_options *o, · line 1250
Quoted 6 lines
fsck.c +5
-0+void register_found_gitmodules (const struct object_id *oid) +{ +oidset_insert (&gitmodules_found, oid); +} +In
fsck.cwe only use this variable to insert into it, or infsck_blob()to do the actual check, but then we either abort early if we've found it, or right after that:
Quoted 2 lines
By "this variable", do you mean
gitmodules_found?fsck_finish()consumes it.
Yes, consumes it to emit errors with report(), no?
Quoted 10 lines
Quoted 5 lines
if (
object_on_skiplist(options, oid))
return 0;So (along with comments I have below...) you could just use the existing "skiplist" option instead, no?
I don't understand this part (in particular, the part you quoted). About "skiplist", I'll reply to your other email [1] which has more details.
*nod*
Quoted 6 lines
Quoted 6 lines
This whole thing seems just like the bad path I took in earlier rounds of my in-flight mktag series. You don't need this new custom API. You just setup an error handler for your fsck which ignores / prints / logs / whatever the OIDs you want if you get a
FSCK_MSG_GITMODULES_MISSINGerror, which you then "return 0" on.
Quoted 8 lines
Quoted 2 lines
If you don't have
FSCK_MSG_GITMODULES_MISSINGpunt and callfsck_error_function().I tried that first, and the issue is that IDs like
FSCK_MSG_GITMODULES_MISSINGare internal tofsck.c. As for whether we should start exposing the IDs publicly, I think we should wait until a few new cases like this come up, so that we more fully understand the requirements first.
The requirement is that you want the objects ids we'd otherwise error about in fsck_finish(). Yeah we don't pass the "fsck_msg_id" down in the "report()" function, but you can reliably strstr() it out of the message. We document & hard rely on that already, since it's also a config key.
But yeah, we could just change the report function to pass down the id and move the relevant macros from fsck.c to fsck.h. I think that would be a smaller change conceptually than a special-case flag in fsck_options for something we could otherwise do with the error reporting.
cover fsck: API improvements
Jonathan Tan pointed out that the fsck error_func doesn't pass you the ID of the fsck failure in [1]. This series improves the API so it does, and moves the gitmodules_{found,done} variables into the fsck_options struct.
The result is that instead of the "print_dangling_gitmodules" member in that series we can just implement that with the diff at the end of this cover letter (goes on top of a merge of this series & "seen"), and without any changes to fsck_finish().
This conflicts with other in-flight fsck changes but the conflict is rather trivial. Jeff King has another concurrent series to add a couple of new fsck checks, those need to be moved to fsck.h, and there's another trivial conflict in 2 hunks due to the gitmodules_{found,done} move.
1. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (14):
fsck.h: indent arguments to of fsck_set_msg_type fsck.h: use use "enum object_type" instead of "int" fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: move definition of msg_id into append_msg_id() fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.c: add an fsck_set_msg_type() API that takes enums fsck.h: update FSCK_OPTIONS_* for object_name
fsck.c: move gitmodules_{found,done} into fsck_options
builtin/fsck.c | 7 +- builtin/index-pack.c | 3 +- builtin/mktag.c | 7 +- builtin/unpack-objects.c | 3 +- fsck.c | 160 ++++++++++++--------------------------- fsck.h | 98 +++++++++++++++++++++--- 6 files changed, 152 insertions(+), 126 deletions(-)
builtin/index-pack.c +16 -4
@@ -1713,6 +1713,20 @@ static void show_pack_info(int stat_only) } } +static int index_pack_fsck_error_func (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +} +int cmd_index_pack (int argc,const char **argv,const char *prefix) {int i, fix_thin_pack =0 , verify =0 , stat_only =0 , rev_index;
@@ -1934,10 +1948,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)close (input_fd);if (do_fsck_object) { -struct fsck_options fo =FSCK_OPTIONS_STRICT ; - - fo.print_dangling_gitmodules =1 ; -if (fsck_finish (&fo)) + fsck_options.error_func = index_pack_fsck_error_func; +if (fsck_finish (&fsck_options))die (_ ("fsck error in pack objects" )); }
fetch-pack.c +19 -3
@@ -40,6 +40,7 @@ static struct shallow_lock shallow_lock;static const char *alternate_shallow_file;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;/* Remember to update object flag allocation in object.h */ #define COMPLETE (1U << 0)
@@ -993,19 +994,34 @@ static int cmp_ref_by_name(const void *a_, const void *b_)return strcmp (a->name, b->name); } +static int fetch_pack_fsck_error_func (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +} +static void fsck_gitmodules_oids (struct oidset *gitmodules_oids) {struct oidset_iter iter;const struct object_id *oid; -struct fsck_options fo =FSCK_OPTIONS_STRICT ;if (!oidset_size (gitmodules_oids))return ;oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (oid); -if (fsck_finish (&fo)) +oidset_insert (&fsck_options.gitmodules_found, oid); + + fsck_options.error_func = fetch_pack_fsck_error_func; +if (fsck_finish (&fsck_options))die ("fsck failed" ); }
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH 00/14] fsck: API improvements
Quoted 10 lines · Ævar Arnfjörð Bjarmason
Jonathan Tan pointed out that the fsck
error_funcdoesn't pass you the ID of the fsck failure in [1]. This series improves the API so it does, and moves the gitmodules_{found,done} variables into thefsck_optionsstruct.The result is that instead of the "
print_dangling_gitmodules" member in that series we can just implement that with the diff at the end of this cover letter (goes on top of a merge of this series & "seen"), and without any changes tofsck_finish().
Quoted 7 lines
This conflicts with other in-flight fsck changes but the conflict is rather trivial. Jeff King has another concurrent series to add a couple of new fsck checks, those need to be moved to
fsck.h, and there's another trivial conflict in 2 hunks due to the gitmodules_{found,done} move.
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Re: [PATCH 00/14] fsck: API improvements
Quoted 18 lines · Junio C Hamano
Quoted 16 lines · Ævar Arnfjörð Bjarmason
Jonathan Tan pointed out that the fsck
error_funcdoesn't pass you the ID of the fsck failure in [1]. This series improves the API so it does, and moves the gitmodules_{found,done} variables into thefsck_optionsstruct.The result is that instead of the "
print_dangling_gitmodules" member in that series we can just implement that with the diff at the end of this cover letter (goes on top of a merge of this series & "seen"), and without any changes tofsck_finish().This conflicts with other in-flight fsck changes but the conflict is rather trivial. Jeff King has another concurrent series to add a couple of new fsck checks, those need to be moved to
fsck.h, and there's another trivial conflict in 2 hunks due to the gitmodules_{found,done} move.
Quoted 4 lines
Quoted 1 line
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Patches 01..09 & 13/14 can live conflict-free with what's in "seen" now (I'd have made the 13th the 10th in v1 if I'd noticed). Then I could re-roll the remainder of this once the other topics land.
Re: [PATCH 00/14] fsck: API improvements
Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Not really. I am not sure your recent patches are getting sufficient review bandwidth they deserve.
Quoted 3 lines
Patches 01..09 & 13/14 can live conflict-free with what's in "seen" now (I'd have made the 13th the 10th in v1 if I'd noticed). Then I could re-roll the remainder of this once the other topics land.
Re: [PATCH 00/14] fsck: API improvements
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Not really. I am not sure your recent patches are getting sufficient review bandwidth they deserve.
FWIW, I just read through v2 (without having looked at all at v1 yet!), and they all seemed like quite reasonable cleanups. I left a few small comments that might be worth a quick re-roll, but I would also be OK with the patches being picked up as-is.
-Peff
Re: [PATCH 00/14] fsck: API improvements
Quoted 10 lines · Jeff King
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Quoted 7 lines
Quoted 2 lines
Not really. I am not sure your recent patches are getting sufficient review bandwidth they deserve.
FWIW, I just read through v2 (without having looked at all at v1 yet!), and they all seemed like quite reasonable cleanups. I left a few small comments that might be worth a quick re-roll, but I would also be OK with the patches being picked up as-is.
That's good to hear. I shouldn't even have bothered to answer the question, if the v2 were to have sent to the list without waiting for my reply ;-)
Re: [PATCH 00/14] fsck: API improvements
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jeff King
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Not really. I am not sure your recent patches are getting sufficient review bandwidth they deserve.
Quoted 8 lines
Quoted 4 lines
FWIW, I just read through v2 (without having looked at all at v1 yet!), and they all seemed like quite reasonable cleanups. I left a few small comments that might be worth a quick re-roll, but I would also be OK with the patches being picked up as-is.
That's good to hear. I shouldn't even have bothered to answer the question, if the v2 were to have sent to the list without waiting for my reply ;-)
FWIW it's not that I didn't care about the reply, but I'm somewhat intermittently available time/network wise in the coming days. And there's the TZ difference between us.
I sent v1 thinking you might be willing to pick it up & resolve the conflict, but since you expressed an interest in deferring it until conflicting work landed figured I'd ask (and then just sent the patches) if you'd be interested in a conflict-free version to queue alongside those changes.
If it was still "nah" fair enough, I'd just wait. But if not those patches would be there to pickup.
Thanks a lot to you & Jeff for the review on v2. I won't have time to address all that today, and in any case I got the message that maybe I should stop firehosing the list with patch series's for a bit :)
Re: [PATCH 00/14] fsck: API improvements
In reply to Jeff KingQuoted 10 lines · Jeff King
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
Let's get this reviewed now, but with expectation that it will be rebased after the dust settles.
Makes sense. Pending a review of this would you be interested in queuing a v2 of this that doesn't conflict with in-flight topics?
Quoted 7 lines
Quoted 2 lines
Not really. I am not sure your recent patches are getting sufficient review bandwidth they deserve.
FWIW, I just read through v2 (without having looked at all at v1 yet!), and they all seemed like quite reasonable cleanups. I left a few small comments that might be worth a quick re-roll, but I would also be OK with the patches being picked up as-is.
Yeah, all except for a handful minor nits looked good.
Thanks for writing and reviewing. Perhaps a final reroll to tie the loose ends, or is it just a matter of signing off one of them and droping a couple of other ones (which other ones)?
PATCH v2 1/10 fsck.h: indent arguments to of fsck_set_msg_type
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH v2 2/10 fsck.h: use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -197,7 +197,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH v2 3/10 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "tmp", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
--- fsck.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *tmp; +ALLOC_ARRAY (tmp,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + tmp[i] =fsck_msg_type (i, options); + options->msg_type = tmp; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 03/10] fsck.c: rename variables in fsck_set_msg_type() for less confusion
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Rename variables in a function added in
0282f4dced0(fsck: offer a function to demote fsck errors to warnings, 2015-06-22).It was needlessly confusing that it took a "
msg_type" argument, but then later declared another "msg_type" of a different type.Let's rename that to "tmp", and rename "id" to "
msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
I think this is an improvement, though maybe "severity" would be a less-generic term than "type".
fsck.c int is_valid_msg_type(const char *msg_id, const char *msg_type) · line 208
Quoted 6 lines
void fsck_set_msg_type(struct
fsck_options*options,fsck.c +2
-2- const char *msg_id, const char *msg_type) + const char *msg_id_str, const char *msg_type_str) { - int id = parse_msg_id(msg_id), type; + int msg_id = parse_msg_id(msg_id_str), msg_type;
I always get nervous when a refactoring renames something away from "foo", and then renames another thing _to_ "foo". Any untouched bits of code are vulnerable to confusing them.
But I think the types are sufficiently different that we can mostly rely on the compiler (though things like numeric or bool comparisons can work with either pointers or ints), and the fact that we can see the entire function is small enough that we can see the entire thing in the context here.
So I think it is OK.
-Peff
PATCH v2 4/10 fsck.c: move definition of msg_id into append_msg_id()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report().
--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fsck.c +3 -2
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH v2 5/10 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fsck.c +8 -8
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 05/10] fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
Quoted 6 lines · Ævar Arnfjörð Bjarmason
Rename the remaining variables of type
fsck_msg_idfrom "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Up to this point I have no objections to the patches themselves, but this one is not signed off.
Quoted 52 lines
fsck.c +8
-8@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
PATCH v2 6/10 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
--- builtin/fsck.c | 2 +- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 17 ++++++++++------- 4 files changed, 23 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/mktag.c +2 -1
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,10 +161,10 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; +enum fsck_msg_type msg_type;assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );
@@ -182,7 +179,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return msg_type; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -205,7 +202,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -216,7 +214,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *tmp; +enum fsck_msg_type *tmp;ALLOC_ARRAY (tmp,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) tmp[i] =fsck_msg_type (i, options);
@@ -296,7 +294,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1262,7 +1261,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -7
@@ -3,10 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 - +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +32,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 06/10] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
Quoted 2 lines · Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_typeenum.
Makes sense. As with my previous comment, I wonder if "severity" is a more descriptive term.
Quoted 9 lines
fsck.h +0
-1@@ -3,10 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1
fsck.h line 12
Quoted 10 lines
fsck.h +7
-3-#define FSCK_WARN 2 -#define FSCK_IGNORE 3 - +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};
You kept the values the same as they were before, which is good in a refactoring step, but...wow, the ordering is weird and confusing.
In FATAL/ERROR/WARN/IGNORE the number increases as severity decreases. Maybe reversed from how I'd do it, but at least the order makes sense. But somehow INFO is on the far side of FATAL?
Again, not something to address in this patch, but I hope something we could maybe deal with in the longer term (perhaps along with fixing the weird "INFO is a warning from the user's perspective, but WARNING is generally an error" behavior).
I also know that this is assigning WARN and IGNORE based on counting-by-one from ERROR, so it's correct. But I think it would be more obvious if you simply filled in the values manually, so a reader does not have to wonder why some are assigned and some are not.
-Peff
Re: [PATCH v2 06/10] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
Quoted 40 lines · Jeff King
Quoted 2 lines · Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_typeenum.Makes sense. As with my previous comment, I wonder if "severity" is a more descriptive term.
Quoted 9 lines
fsck.h +0
-1@@ -3,10 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1fsck.h line 12
Quoted 10 lines
fsck.h +7
-3-#define FSCK_WARN 2 -#define FSCK_IGNORE 3 - +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};You kept the values the same as they were before, which is good in a refactoring step, but...wow, the ordering is weird and confusing.
In FATAL/ERROR/WARN/IGNORE the number increases as severity decreases. Maybe reversed from how I'd do it, but at least the order makes sense. But somehow INFO is on the far side of FATAL?
Again, not something to address in this patch, but I hope something we could maybe deal with in the longer term (perhaps along with fixing the weird "INFO is a warning from the user's perspective, but WARNING is generally an error" behavior).
Quoted 4 lines
I also know that this is assigning WARN and IGNORE based on counting-by-one from ERROR, so it's correct. But I think it would be more obvious if you simply filled in the values manually, so a reader does not have to wonder why some are assigned and some are not.
I had the same reaction, plus "Wow, we had FSCK_* constants in two different places and without colliding? Have we been lucky? Declaring it in one place, whether we use enum or not (as enum is not very useful in C as a type checking vehicle), makes a lot of sense but why does this come this late in the series, instead of being at the front as a trivial low-hanging fruit?"
Thanks.
PATCH v2 7/10 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -203,11 +203,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 07/10] fsck.c: call parse_msg_type() early in fsck_set_msg_type()
Quoted 3 lines · Ævar Arnfjörð Bjarmason
There's no reason to defer the calling of
parse_msg_type()until after we've checked if the "id < 0". This is not a hot codepath, andparse_msg_type()itself may die on invalid input.
That explains why this change can be done, but does not justify why it is a good change. Unlike all the previous steps, I would rather say this is borderline needless churn.
Let's keep reading as the picture may change as we touch more code around this area.
Thanks.
Quoted 23 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fsck.c +1
-2@@ -203,11 +203,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
PATCH v2 8/10 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 08/10] fsck.c: undefine temporary STR macro after use
Quoted 16 lines · Ævar Arnfjörð Bjarmason
In
f417eed8cde(fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for theMSG_IDmacro inc99ba492f1c(fsck: introduce identifiers for fsck messages, 2015-06-22).Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.c | 1 + 1 file changed, 1 insertion(+)fsck.c +0
-0
fsck.c static struct { · line 103
Quoted 4 lines
fsck.c +1
-0@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STR
Good clean-up.
Quoted 3 lines
fsck.c +0
-0static void prepare_msg_ids (void ) {
v2 cover fsck: API improvements (no conflicts with 'seen')
In reply to Ævar Arnfjörð BjarmasonAs suggested in
https://lore.kernel.org/git/[email protected]/ a version of this that doesn't conflict with other in-flight topics. I can submit the rest later.
Ævar Arnfjörð Bjarmason (10):
fsck.h: indent arguments to of fsck_set_msg_type fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: move definition of msg_id into append_msg_id() fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.h: update FSCK_OPTIONS_* for object_name
builtin/fsck.c | 5 ++-- builtin/index-pack.c | 3 +- builtin/mktag.c | 3 +- builtin/unpack-objects.c | 3 +- fsck.c | 60 ++++++++++++++++++++-------------------- fsck.h | 26 +++++++++-------- 6 files changed, 54 insertions(+), 46 deletions(-)
Range-diff:
-: ----------- > 1: 88b347b74ed fsck.h: indent arguments to of fsck_set_msg_type 1: 1a60d65d2ca ! 2: 868eac3d4d1 fsck.h: use use "enum object_type" instead of "int"
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- fsck.h: use use "enum object_type" instead of "int"
+ fsck.h: use "enum object_type" instead of "int"
Change the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in
2: 24761f269b7 = 3: f599dc6c8f3 fsck.c: rename variables in fsck_set_msg_type() for less confusion
3: fb4c66f9305 = 4: 33f3b1942c1 fsck.c: move definition of msg_id into append_msg_id()
4: a129dbd9964 = 5: 28c9245e418 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
5: d9bee41072e = 6: d25037c6f18 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
6: 423568026c3 = 7: 66d0f1047cc fsck.c: call parse_msg_type() early in fsck_set_msg_type()
7: cb43e832738 = 8: 7643a5bf211 fsck.c: undefine temporary STR macro after use
8: 2cd14cb4e2a = 9: 7c64e2267ce fsck.c: give "FOREACH_MSG_ID" a more specific name
9: 1ada154ef23 < -: ----------- fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
10: c4179445f22 < -: ----------- fsck.c: pass along the fsck_msg_id in the fsck_error callback
11: c1fc724f0e8 < -: ----------- fsck.c: add an fsck_set_msg_type() API that takes enums
12: 8de91fac068 = 10: a98a3512629 fsck.h: update FSCK_OPTIONS_* for object_name
13: 29ff97856ff < -: ----------- fsck.c: move gitmodules_{found,done} into fsck_optionsSignature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen')
Quoted 4 lines · Ævar Arnfjörð Bjarmason
As suggested in
https://lore.kernel.org/git/[email protected]/ a version of this that doesn't conflict with other in-flight topics. I can submit the rest later.
And a bystander does not have a clue what this thing is about, beyond that it tweaks fsck API, how urgent it would be, what benefit it brings to us?
That kind of things are expected to be described here.
The cover letter of v1 does not do much better job, either, but is it fair to understand that this primarily is about allowing the callback functions (which handle various problems fsck machinery finds) to learn what error it encountered, so that things like "enumerate missing .gitmodules blobs" 384c9d1c (fetch-pack: print and use dangling .gitmodules, 2021-01-23) wants to do does not have to be written by inserting a very narrow custom code into the general error reporting codepath, but by customizing the error reporting function?
If so, can we at least say something a bit more specific and focused, than the overly broad "API improvements"?
THanks.
v3 cover fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonNow that jt/transfer-fsck-across-packs has been merged to master here's a re-roll of v1[1]+v2[2] of this series. v2 was slimmed-down + had a trivial typo fix, so I've done the range-diff against v1.
This makes the recent fetch-pack work use the fsck_msg_id API to distinguish messages, and has other various cleanups and improvements to make the fsck API easier to use in the future.
There's a an easy merge conflict here with other in-flight changes to fsck. I figured it was better to send this now than wait for those to land.
1. https://lore.kernel.org/git/[email protected]/
2. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (22):
fsck.h: update FSCK_OPTIONS_* for object_name
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro fsck.h: indent arguments to of fsck_set_msg_type
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: move definition of msg_id into append_msg_id() fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.h: re-order and re-assign "enum fsck_msg_type" fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.c: add an fsck_set_msg_type() API that takes enums fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
Makefile | 1 + builtin/fsck.c | 7 +- builtin/index-pack.c | 30 ++----- builtin/mktag.c | 7 +- builtin/unpack-objects.c | 3 +- fetch-pack.c | 6 +- fsck-cb.c | 16 ++++ fsck.c | 175 ++++++++++++--------------------------- fsck.h | 132 ++++++++++++++++++++++++++--- 9 files changed, 211 insertions(+), 166 deletions(-) create mode 100644 fsck-cb.c
Range-diff:
13: 8de91fac068 = 1: 9d809466bd1 fsck.h: update FSCK_OPTIONS_* for object_name
-: ----------- > 2: 33e8b6d6545 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
-: ----------- > 3: c23f7ce9e4a fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
-: ----------- > 4: 5dde68df6c3 fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
1: 88b347b74ed = 5: 7ae35a6e9d2 fsck.h: indent arguments to of fsck_set_msg_type
2: 1a60d65d2ca ! 6: dfb5f754b37 fsck.h: use use "enum object_type" instead of "int" @@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- fsck.h: use use "enum object_type" instead of "int"
+ fsck.h: use "enum object_type" instead of "int"
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
3: 24761f269b7 ! 7: fd58ec73c6b fsck.c: rename variables in fsck_set_msg_type() for less confusion
@@ Commit message
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
- Let's rename that to "tmp", and rename "id" to "msg_id" and "msg_id"
- to "msg_id_str" etc. This will make a follow-up change smaller.
+ Let's rename that to "severity", and rename "id" to "msg_id" and
+ "msg_id" to "msg_id_str" etc. This will make a follow-up change
+ smaller.
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
-+ int *tmp;
-+ ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
++ int *severity;
++ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
-+ tmp[i] = fsck_msg_type(i, options);
-+ options->msg_type = tmp;
++ severity[i] = fsck_msg_type(i, options);
++ options->msg_type = severity;
}
- options->msg_type[id] = type;
4: fb4c66f9305 = 8: 48cb4d3bb70 fsck.c: move definition of msg_id into append_msg_id()
5: a129dbd9964 ! 9: 2c80ad32038 fsck.c: rename remaining fsck_msg_id "id" to "msg_id" @@ Commit message
"msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
+ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
+
## fsck.c ##
@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
-: ----------- > 10: 92dfbdfb624 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
6: d9bee41072e ! 11: c1c476af69b fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum @@ Commit message
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
+ The reason these were defined in two different places is because we
+ use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
+ used by external callbacks.
+
+ Untangling that would take some more work, since we expose the new
+ "enum fsck_msg_type" to both. Similar to "enum object_type" it's not
+ worth structuring the API in such a way that only those who need
+ FSCK_{ERROR,WARN} pass around a different type.
+
## builtin/fsck.c ##
@@ builtin/fsck.c: static int objerror(struct object *obj, const char *err)
switch (msg_type) {
case FSCK_WARN:
+ ## builtin/index-pack.c ##
+@@ builtin/index-pack.c: static void show_pack_info(int stat_only)
+ static int print_dangling_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+- int msg_type, const char *message)
++ enum fsck_msg_type msg_type,
++ const char *message)
+ {
+ /*
+ * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
+
## builtin/mktag.c ##
@@ builtin/mktag.c: static int mktag_config(const char *var, const char *value, void *cb)
static int mktag_fsck_error_func(struct fsck_options *o,
@@ fsck.c: void list_config_fsck_msg_ids(struct string_list *list, const char *pref
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
-- int msg_type;
-+ enum fsck_msg_type msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
+ if (!options->msg_type) {
+- int msg_type = msg_id_info[msg_id].msg_type;
++ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
+
+ if (options->strict && msg_type == FSCK_WARN)
+ msg_type = FSCK_ERROR;
@@ fsck.c: static int fsck_msg_type(enum fsck_msg_id msg_id,
- return msg_type;
+ return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
-- int *tmp;
-+ enum fsck_msg_type *tmp;
- ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
+- int *severity;
++ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- tmp[i] = fsck_msg_type(i, options);
+ severity[i] = fsck_msg_type(i, options);
@@ fsck.c: static int report(struct fsck_options *options,
{
va_list ap;
@@ fsck.h
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
--
+enum fsck_msg_type {
-+ FSCK_INFO = -2,
++ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
+
struct fsck_options;
struct object;
-
@@ fsck.h: typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
-: ----------- > 12: d55587719a5 fsck.h: re-order and re-assign "enum fsck_msg_type"
7: 423568026c3 = 13: 32828d1c78c fsck.c: call parse_msg_type() early in fsck_set_msg_type()
8: cb43e832738 = 14: 5c62066235c fsck.c: undefine temporary STR macro after use
9: 2cd14cb4e2a = 15: f8e50fbf7d3 fsck.c: give "FOREACH_MSG_ID" a more specific name
10: 1ada154ef23 ! 16: cd74dee8769 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
@@ fsck.c
## fsck.h ##
@@ fsck.h: enum fsck_msg_type {
FSCK_WARN,
- FSCK_IGNORE
};
-+
+
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \11: c4179445f22 ! 17: 234e287d081 fsck.c: pass along the fsck_msg_id in the fsck_error callback
@@ builtin/fsck.c: static int objerror(struct object *obj, const char *err)
switch (msg_type) {
case FSCK_WARN:
+ ## builtin/index-pack.c ##
+@@ builtin/index-pack.c: static int print_dangling_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
++ enum fsck_msg_id msg_id,
+ const char *message)
+ {
+ /*
+@@ builtin/index-pack.c: static int print_dangling_gitmodules(struct fsck_options *o,
+ printf("%s\n", oid_to_hex(oid));
+ return 0;
+ }
+- return fsck_error_function(o, oid, object_type, msg_type, message);
++ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+ }
+
+ int cmd_index_pack(int argc, const char **argv, const char *prefix)
+
## builtin/mktag.c ##
@@ builtin/mktag.c: static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
12: c1fc724f0e8 ! 18: 8049dc07391 fsck.c: add an fsck_set_msg_type() API that takes enums
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
+{
+ if (!options->msg_type) {
+ int i;
-+ enum fsck_msg_type *tmp;
-+ ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
++ enum fsck_msg_type *severity;
++ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
-+ tmp[i] = fsck_msg_type(i, options);
-+ options->msg_type = tmp;
++ severity[i] = fsck_msg_type(i, options);
++ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
- if (!options->msg_type) {
- int i;
-- enum fsck_msg_type *tmp;
-- ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
+- enum fsck_msg_type *severity;
+- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
-- tmp[i] = fsck_msg_type(i, options);
-- options->msg_type = tmp;
+- severity[i] = fsck_msg_type(i, options);
+- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;14: 29ff97856ff ! 19: 4224a29d15c fsck.c: move gitmodules_{found,done} into fsck_options
@@ Commit message
fsck_options struct. It makes sense to keep all the context in the same place.
+ This requires changing the recently added register_found_gitmodules()
+ function added in 5476e1efde (fetch-pack: print and use dangling
+ .gitmodules, 2021-02-22) to take fsck_options. That function will be
+ removed in a subsequent commit, but as it'll require the new
+ gitmodules_found attribute of "fsck_options" we need this intermediate
+ step first.
+
+ ## fetch-pack.c ##
+@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) +
+ oidset_iter_init(gitmodules_oids, &iter);
+ while ((oid = oidset_iter_next(&iter)))
+- register_found_gitmodules(oid);
++ register_found_gitmodules(&fo, oid);
+ if (fsck_finish(&fo))
+ die("fsck failed");
+ }
+
## fsck.c ##
@@
#include "credential.h"
@@ fsck.c: static int fsck_blob(const struct object_id *oid, const char *buf,
if (object_on_skiplist(options, oid))
return 0;
+@@ fsck.c: int fsck_error_function(struct fsck_options *o,
+ return 1;
+ }
+
+-void register_found_gitmodules(const struct object_id *oid)
++void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
+ {
+- oidset_insert(&gitmodules_found, oid);
++ oidset_insert(&options->gitmodules_found, oid);
+ }
+
+ int fsck_finish(struct fsck_options *options)
@@ fsck.c: int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
@@ fsck.h: struct fsck_options {
kh_oid_map_t *object_names;
};
--#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } --#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL } -+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL } -+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL } +@@ fsck.h: struct fsck_options {
+ .walk = NULL, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
+ .object_names = NULL,
+ #define FSCK_OPTIONS_COMMON_ERROR_FUNC \
+ FSCK_OPTIONS_COMMON \
+@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
+ int fsck_object(struct object *obj, void *data, unsigned long size,
+ struct fsck_options *options);
+
+-void register_found_gitmodules(const struct object_id *oid);
++void register_found_gitmodules(struct fsck_options *options,
++ const struct object_id *oid);
- /* descend in all linked child objects
- * the return value is:
+ /*
+ * fsck a tag, and pass info about it back to the caller. This is
-: ----------- > 20: 40b13468129 fetch-pack: don't needlessly copy fsck_options -: ----------- > 21: 8e418abfbd7 fetch-pack: use file-scope static struct for fsck_options -: ----------- > 22: 113de190f7d fetch-pack: use new fsck API to printing dangling submodules
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
Re: [PATCH v3 00/22] fsck: API improvements
Quoted 2 lines · Ævar Arnfjörð Bjarmason
Now that jt/transfer-fsck-across-packs has been merged to master here's a re-roll of v1[1]+v2[2] of this series.
It unfortunately is not a good time to review or helping any work on this series, as the base topic introduced an unpleasant regression and needs to either probably gain a band-aid (or reverted in the worst case); of course, it would be appreciated to help resolve the issues on that topic ;-)
Thanks.
Re: [PATCH v3 00/22] fsck: API improvements
Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Ævar Arnfjörð Bjarmason
Now that jt/transfer-fsck-across-packs has been merged to master here's a re-roll of v1[1]+v2[2] of this series.
It unfortunately is not a good time to review or helping any work on this series, as the base topic introduced an unpleasant regression and needs to either probably gain a band-aid (or reverted in the worst case); of course, it would be appreciated to help resolve the issues on that topic ;-)
I should have mentioned: I saw the bug & proposed fix thread for that. I see that 2aec3bc4b64 (fetch-pack: do not mix --pack_header and packfile uri, 2021-03-04) down into next is now merged down to next.
My reading of that thread is that the reported bug is solved, but perhaps we're not 100% happy with the solution?
In any case, that patch does not conflict with this series, and all tests pass with/without the two merged together.
I don't forese an issue with the two stepping on each other's toes, since I'm just modifying the rather low-level fsck interface of spewing out .gitmodules entries, not touching the logic of what's then done with that information...
v4 cover fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonA re-send of a rebased v3, which I sent at:
http://lore.kernel.org/git/[email protected] as seen in the range-diff there are no changes since v3. I'm just sending this as a post-release bump of this, per
https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (22):
fsck.h: update FSCK_OPTIONS_* for object_name
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro fsck.h: indent arguments to of fsck_set_msg_type
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: move definition of msg_id into append_msg_id() fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.h: re-order and re-assign "enum fsck_msg_type" fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.c: add an fsck_set_msg_type() API that takes enums fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
Makefile | 1 + builtin/fsck.c | 7 +- builtin/index-pack.c | 30 ++----- builtin/mktag.c | 7 +- builtin/unpack-objects.c | 3 +- fetch-pack.c | 6 +- fsck-cb.c | 16 ++++ fsck.c | 175 ++++++++++++--------------------------- fsck.h | 132 ++++++++++++++++++++++++++--- 9 files changed, 211 insertions(+), 166 deletions(-) create mode 100644 fsck-cb.c
Range-diff:
1: 9d809466bd = 1: 9cd942b526 fsck.h: update FSCK_OPTIONS_* for object_name
2: 33e8b6d654 = 2: d67966b838 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
3: c23f7ce9e4 = 3: 211472e0c5 fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
4: 5dde68df6c = 4: 70afee988d fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
5: 7ae35a6e9d = 5: 1337d53352 fsck.h: indent arguments to of fsck_set_msg_type
6: dfb5f754b3 = 6: e4ef107bb4 fsck.h: use "enum object_type" instead of "int"
7: fd58ec73c6 = 7: 20bac3207e fsck.c: rename variables in fsck_set_msg_type() for less confusion
8: 48cb4d3bb7 = 8: 09c3bba9e9 fsck.c: move definition of msg_id into append_msg_id()
9: 2c80ad3203 = 9: 8067df53a2 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
10: 92dfbdfb62 = 10: bdf5e13f3d fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
11: c1c476af69 = 11: b03caa237f fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
12: d55587719a = 12: 7b1d13b4cc fsck.h: re-order and re-assign "enum fsck_msg_type"
13: 32828d1c78 = 13: a8e4ca7b19 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
14: 5c62066235 = 14: 214c375a20 fsck.c: undefine temporary STR macro after use
15: f8e50fbf7d = 15: 19a2499a80 fsck.c: give "FOREACH_MSG_ID" a more specific name
16: cd74dee876 = 16: 6e1a7b6274 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
17: 234e287d08 = 17: 42af4e164c fsck.c: pass along the fsck_msg_id in the fsck_error callback
18: 8049dc0739 = 18: fa47f473a8 fsck.c: add an fsck_set_msg_type() API that takes enums
19: 4224a29d15 = 19: 4cc3880cc4 fsck.c: move gitmodules_{found,done} into fsck_options
20: 40b1346812 = 20: fd219d318a fetch-pack: don't needlessly copy fsck_options
21: 8e418abfbd = 21: e4cd8c250e fetch-pack: use file-scope static struct for fsck_options
22: 113de190f7 = 22: fdbc3c304c fetch-pack: use new fsck API to printing dangling submodulesSignature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 00/22] fsck: API improvements
Quoted 21 lines · Ævar Arnfjörð Bjarmason
A re-send of a rebased v3, which I sent at:
http://lore.kernel.org/git/[email protected] as seen in the range-diff there are no changes since v3. I'm just sending this as a post-release bump of this, per
https://lore.kernel.org/git/[email protected]/Ævar Arnfjörð Bjarmason (22):
fsck.h: update FSCK_OPTIONS_* forobject_name
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}fsck.h: add aFSCK_OPTIONS_COMMON_ERROR_FUNCmacrofsck.h: indent arguments to offsck_set_msg_type
fsck.h: use "enumobject_type" instead of "int"
fsck.c: rename variables infsck_set_msg_type()for less confusionfsck.c: move definition ofmsg_idintoappend_msg_id()fsck.c: rename remainingfsck_msg_id"id" to "msg_id"fsck.c: refactorfsck_msg_type()to limit scope of "intmsg_type"fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enumfsck.h: re-order and re-assign "enumfsck_msg_type"fsck.c: callparse_msg_type()early infsck_set_msg_type()fsck.c: undefine temporary STR macro after use
Quoted 8 lines
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: moveFOREACH_FSCK_MSG_ID&fsck_msg_idfrom *.c to *.hfsck.c: pass along thefsck_msg_idin thefsck_errorcallbackfsck.c: add anfsck_set_msg_type()API that takes enumsfsck.c: move gitmodules_{found,done} intofsck_options
fetch-pack: don't needlessly copyfsck_options
fetch-pack: use file-scope static struct forfsck_options
fetch-pack: use new fsck API to printing dangling submodules
This series is carefully organized and motivated. It was quite easy to read.
My complaints were minor. One was that patches 1-4 seemed to be unnecessarily granular. I'm not sure that having four patches like that will be more helpful for inspecting the history in the future. But, I don't care enough to say this should be re-rolled.
Finally, the last issue is that fsck-cb.c is loosely justified with only one method inside. If you have plans in the near future to add similar methods there, then I think that is fine. Otherwise, it would be simpler to avoid the extra file and code move.
Thanks,
-Stolee
v5 cover fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonA v5 with changes suggested by Derrick Stolee. Link to v4:
https://lore.kernel.org/git/[email protected]/
Changes:
* 1/19 is new, it's a simple refactoring of some git_config() code in fsck.c code I changed recently.
* Squashed the first 4x patches of incrementally redefining two macros into one.
* Squashed a whitespace-only change into another patch that changed the same code.
* Got rid of fsck-cb.c, that one function just lives at the bottom of fsck.c now.
Ævar Arnfjörð Bjarmason (19):
fsck.c: refactor and rename common config callback fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: move definition of msg_id into append_msg_id() fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.h: re-order and re-assign "enum fsck_msg_type" fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.c: add an fsck_set_msg_type() API that takes enums fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
builtin/fsck.c | 14 ++- builtin/index-pack.c | 30 +----- builtin/mktag.c | 14 ++- builtin/unpack-objects.c | 3 +- fetch-pack.c | 6 +- fsck.c | 197 +++++++++++++++------------------------ fsck.h | 131 +++++++++++++++++++++++--- 7 files changed, 213 insertions(+), 182 deletions(-)
Range-diff:
1: 9cd942b526 < -: ---------- fsck.h: update FSCK_OPTIONS_* for object_name
2: d67966b838 < -: ---------- fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
3: 211472e0c5 < -: ---------- fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
4: 70afee988d < -: ---------- fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
5: 1337d53352 < -: ---------- fsck.h: indent arguments to of fsck_set_msg_type
-: ---------- > 1: fe33015e0d fsck.c: refactor and rename common config callback
-: ---------- > 2: 72f2e53afa fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
6: e4ef107bb4 = 3: 237a280686 fsck.h: use "enum object_type" instead of "int"
7: 20bac3207e ! 4: 13b76c73dd fsck.c: rename variables in fsck_set_msg_type() for less confusion @@ Commit message
"msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
+ While I'm at it properly indent the fsck_set_msg_type() argument list.
+
## fsck.c ##
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
-+ const char *msg_id_str, const char *msg_type_str)
++ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
+
+ ## fsck.h ##
+@@ fsck.h: struct fsck_options;
+ struct object;
+
+ void fsck_set_msg_type(struct fsck_options *options,
+- const char *msg_id, const char *msg_type);
++ const char *msg_id, const char *msg_type);
+ void fsck_set_msg_types(struct fsck_options *options, const char *values);
+ int is_valid_msg_type(const char *msg_id, const char *msg_type); +
8: 09c3bba9e9 = 5: 4ae83403b7 fsck.c: move definition of msg_id into append_msg_id()
9: 8067df53a2 = 6: 82107f1dac fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
10: bdf5e13f3d = 7: 796096bf73 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
11: b03caa237f ! 8: 3664abb23d fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum @@ builtin/index-pack.c: static void show_pack_info(int stat_only)
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
## builtin/mktag.c ##
-@@ builtin/mktag.c: static int mktag_config(const char *var, const char *value, void *cb) +@@ builtin/mktag.c: static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
@@ fsck.c: static int fsck_msg_type(enum fsck_msg_id msg_id,
return FSCK_ERROR;
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
12: 7b1d13b4cc = 9: 81e6d7ab45 fsck.h: re-order and re-assign "enum fsck_msg_type" 13: a8e4ca7b19 ! 10: 5c2e8e7b84 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
@@ Commit message
## fsck.c ##
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
14: 214c375a20 = 11: 7ffbf9af3f fsck.c: undefine temporary STR macro after use 15: 19a2499a80 = 12: 12ff0f75eb fsck.c: give "FOREACH_MSG_ID" a more specific name 16: 6e1a7b6274 = 13: 0c49dd5164 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h 17: 42af4e164c = 14: 900263f503 fsck.c: pass along the fsck_msg_id in the fsck_error callback 18: fa47f473a8 ! 15: 5f270e88a0 fsck.c: add an fsck_set_msg_type() API that takes enums
@@ builtin/mktag.c: int cmd_mktag(int argc, const char **argv, const char *prefix)
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
- git_config(mktag_config, NULL);
+ git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
## fsck.c ##
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
+}
+
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
19: 4cc3880cc4 = 16: 539d019712 fsck.c: move gitmodules_{found,done} into fsck_options
20: fd219d318a = 17: 1acf744236 fetch-pack: don't needlessly copy fsck_options
21: e4cd8c250e = 18: b47c3d5ac6 fetch-pack: use file-scope static struct for fsck_options
22: fdbc3c304c ! 19: f05fa5c3ec fetch-pack: use new fsck API to printing dangling submodules @@ Commit message
manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
- Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
- would be to either define this directly in fsck.c as a public API, or
- to create some library shared by fetch-pack.c ad builtin/index-pack.
+ I'm sticking this callback in fsck.c. Perhaps in the future we'd like
+ to accumulate such callbacks into another file (maybe fsck-cb.c,
+ similar to parse-options-cb.c?), but while we've got just the one
+ let's just put it into fsck.c.
- I expect that there won't be many of these fsck utility functions in
- the future, so just having a single fsck-cb.c makes sense.
+ A better alternative in this case would be some library some more
+ obvious library shared by fetch-pack.c ad builtin/index-pack.c, but
+ there isn't such a thing.
- ## Makefile ##
-@@ Makefile: LIB_OBJS += fetch-negotiator.o
- LIB_OBJS += fetch-pack.o
- LIB_OBJS += fmt-merge-msg.o
- LIB_OBJS += fsck.o
-+LIB_OBJS += fsck-cb.o
- LIB_OBJS += fsmonitor.o
- LIB_OBJS += gettext.o
- LIB_OBJS += gpg-interface.o
-
## builtin/index-pack.c ##
@@ builtin/index-pack.c: static int nr_threads;
static int from_stdin;
@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
die("fsck failed");
}
- ## fsck-cb.c (new) ##
-@@
-+#include "git-compat-util.h"
-+#include "fsck.h"
+ ## fsck.c ##
+@@ fsck.c: int fsck_error_function(struct fsck_options *o,
+ return 1;
+ }
+
+-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid) +-{
+- oidset_insert(&options->gitmodules_found, oid);
+-}
+-
+ int fsck_finish(struct fsck_options *options)
+ {
+ int ret = 0;
+@@ fsck.c: int git_fsck_config(const char *var, const char *value, void *cb) +
+ return git_default_config(var, value, cb);
+ }
++
++/*
++ * Custom error callbacks that are used in more than one place.
++ */
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
@@ fsck-cb.c (new)
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
- ## fsck.c ##
-@@ fsck.c: int fsck_error_function(struct fsck_options *o,
- return 1;
- }
-
--void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid) --{
-- oidset_insert(&options->gitmodules_found, oid);
--}
--
- int fsck_finish(struct fsck_options *options)
- {
- int ret = 0;
-
## fsck.h ##
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *optio
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
@@ fsck.h: const char *fsck_describe_object(struct fsck_options *options,
- int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options);
+ */
+ int git_fsck_config(const char *var, const char *value, void *cb);
+/*
-+ * Initializations for callbacks in fsck-cb.c
++ * Custom error callbacks that are used in more than one place.
+ */
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ FSCK_OPTIONS_COMMON \
+}
-+
-+/*
-+ * Error callbacks in fsck-cb.c
-+ */
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v5 00/19] fsck: API improvements
Quoted 7 lines · Ævar Arnfjörð Bjarmason
A v5 with changes suggested by Derrick Stolee. Link to v4:
https://lore.kernel.org/git/[email protected]/Changes:
* 1/19 is new, it's a simple refactoring of some
git_config()code infsck.ccode I changed recently.
This new patch is simple, as advertised.
Quoted 2 lines
* Squashed the first 4x patches of incrementally redefining two macros into one.
Thanks.
Quoted 5 lines
* Squashed a whitespace-only change into another patch that changed the same code.
* Got rid of
fsck-cb.c, that one function just lives at the bottom offsck.cnow.
I was late in giving you confirmation that fsck.c is a good place, but you got there, anyway. Thanks!
This version LGTM.
-Stolee
Re: [PATCH v5 00/19] fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonQuoted 7 lines · Ævar Arnfjörð Bjarmason
A v5 with changes suggested by Derrick Stolee. Link to v4:
https://lore.kernel.org/git/[email protected]/Changes:
* 1/19 is new, it's a simple refactoring of some
git_config()code infsck.ccode I changed recently.
The new step makes sense. I think the series and my comment e-mails crossed, and all of my comments on the previous round still applies (including the fsck-cb.c thing, which I think should be added to its sole user index-pack.c, not to fsck.c).
Thanks, will queue.
v6 cover fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonTo recap on the goals in v1[1] this series gets rid of the need to have the rececently added "print_dangling_gitmodules" function in favor of a better fsck API to get at that information.
Changes since v5[2]:
* Addressed all outstanding feedback AFAICT
* The fields we init to 0/NULL in the new designated initializer are gone
* There were comments on the refactoring of append_msg_id(), It turns out that we can entirely remove that function. So a new commit go added + one ejected to do that.
* Clarifications in commit messages.
* I'd still left behind a remnant of the old "print_dangling_gitmodules" code in v5's last commit. I.e. we had code that was accumulating its own list of gitmodules OIDs and then injecting into the fsck state, now that the fsck state tracks those itself we can that list directly instead.
1. https://lore.kernel.org/git/[email protected]/
2. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (19):
fsck.c: refactor and rename common config callback fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.c: remove (mostly) redundant append_msg_id() function fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.h: re-order and re-assign "enum fsck_msg_type" fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.c: add an fsck_set_msg_type() API that takes enums fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
builtin/fsck.c | 14 ++- builtin/index-pack.c | 30 +----- builtin/mktag.c | 14 ++- builtin/unpack-objects.c | 3 +- fetch-pack.c | 31 ++---- fsck.c | 207 +++++++++++++-------------------------- fsck.h | 127 +++++++++++++++++++++--- 7 files changed, 210 insertions(+), 216 deletions(-)
Range-diff:
1: fe33015e0d9 = 1: 579af32ab3e fsck.c: refactor and rename common config callback
2: 72f2e53afac ! 2: b17c982293e fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
@@ Commit message
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
- designated initializers.
-
- While I'm at it add the "object_names" member to the
- initialization. This was omitted in 7b35efd734e (fsck_walk():
- optionally name objects on the go, 2016-07-17) when the field was
- added.
-
- I'm using a new FSCK_OPTIONS_COMMON and FSCK_OPTIONS_COMMON_ERROR_FUNC
- helper macros to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in
- common, and define the two in terms of those macro.
-
- The FSCK_OPTIONS_COMMON macro will be used in a subsequent commit to
- define other variants of common fsck initialization that wants to use
- a custom error function, but share the rest of the defaults.
+ designated initializers. This allows us to omit those fields that
+ aren't initialized to zero or NULL.
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
@@ fsck.h: struct fsck_options {
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
-+#define FSCK_OPTIONS_COMMON \
-+ .walk = NULL, \
-+ .msg_type = NULL, \
++#define FSCK_OPTIONS_DEFAULT { \
+ .skiplist = OIDSET_INIT, \
-+ .object_names = NULL,
-+#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
-+ FSCK_OPTIONS_COMMON \
-+ .error_func = fsck_error_function
-+
-+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
-+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
++ .error_func = fsck_error_function \
++}
++#define FSCK_OPTIONS_STRICT { \
++ .strict = 1, \
++ .error_func = fsck_error_function, \
++}
/* descend in all linked child objects
* the return value is:
3: 237a2806865 = 3: a721c396c50 fsck.h: use "enum object_type" instead of "int"
4: 13b76c73dd7 = 4: fcdba2f8fe8 fsck.c: rename variables in fsck_set_msg_type() for less confusion
5: 4ae83403b73 ! 5: b07e8e026ac fsck.c: move definition of msg_id into append_msg_id() @@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- fsck.c: move definition of msg_id into append_msg_id()
+ fsck.c: remove (mostly) redundant append_msg_id() function
- Refactor code added in 71ab8fa840f (fsck: report the ID of the
- error/warning, 2015-06-22) to resolve the msg_id to a string in the
- function that wants it, instead of doing it in report().
+ Remove the append_msg_id() function in favor of calling
+ prepare_msg_ids(). We already have code to compute the camel-cased
+ msg_id strings in msg_id_info, let's use it.
+
+ When the append_msg_id() function was added in 71ab8fa840f (fsck:
+ report the ID of the error/warning, 2015-06-22) the prepare_msg_ids()
+ function didn't exist. When prepare_msg_ids() was added in
+ a46baac61eb (fsck: factor out msg_id_info[] lazy initialization code,
+ 2018-05-26) this code wasn't moved over to lazy initialization.
+
+ This changes the behavior of the code to initialize all the messages
+ instead of just camel-casing the one we need on the fly. Since the
+ common case is that we're printing just one message this is mostly
+ redundant work.
+
+ But that's OK in this case, reporting this fsck issue to the user
+ isn't performance-sensitive. If we were somehow doing so in a tight
+ loop (in a hopelessly broken repository?) this would help, since we'd
+ save ourselves from re-doing this work for identical messages, we
+ could just grab the prepared string from msg_id_info after the first
+ invocation.
@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
-+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id) +-{
+- for (;;) {
+- char c = *(msg_id)++;
+-
+- if (!c)
+- break;
+- if (c != '_')
+- strbuf_addch(sb, tolower(c));
+- else {
+- assert(*msg_id);
+- strbuf_addch(sb, *(msg_id)++);
+- }
+- }
+-
+- strbuf_addstr(sb, ": ");
+-}
+-
+ static int object_on_skiplist(struct fsck_options *opts,
+ const struct object_id *oid)
{
-+ const char *msg_id = msg_id_info[id].id_string;
- for (;;) {
- char c = *(msg_id)++;
-
@@ fsck.c: static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
-+ append_msg_id(&sb, id);
++ prepare_msg_ids();
++ strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
6: 82107f1dac0 ! 6: 321b0c652de fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
@@ Commit message
## fsck.c ##
-@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values)
- free(to_free);
- }
-
--static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id) -+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id)
- {
-- const char *msg_id = msg_id_info[id].id_string;
-+ const char *msg_id_str = msg_id_info[msg_id].id_string;
- for (;;) {
-- char c = *(msg_id)++;
-+ char c = *(msg_id_str)++;
-
- if (!c)
- break;
- if (c != '_')
- strbuf_addch(sb, tolower(c));
- else {
-- assert(*msg_id);
-- strbuf_addch(sb, *(msg_id)++);
-+ assert(*msg_id_str);
-+ strbuf_addch(sb, *(msg_id_str)++);
- }
- }
-
@@ fsck.c: static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
@@ fsck.c: static int object_on_skiplist(struct fsck_options *opts,
if (msg_type == FSCK_IGNORE)
return 0;
@@ fsck.c: static int report(struct fsck_options *options,
- else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
-- append_msg_id(&sb, id);
-+ append_msg_id(&sb, msg_id);
+ prepare_msg_ids();
+- strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
++ strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
7: 796096bf73e = 7: 948689ad5c8 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
8: 3664abb23de = 8: 8ea468bf4d8 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
9: 81e6d7ab450 ! 9: 9316b35cd3b fsck.h: re-order and re-assign "enum fsck_msg_type" @@ Commit message
defined as "2".
I'm confident that nothing relies on these values, we always compare
- them explicitly. Let's not omit "0" so it won't be assumed that we're
- using these as a boolean somewhere.
+ them for equality. Let's not omit "0" so it won't be assumed that
+ we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for
10: 5c2e8e7b842 = 10: d7f1c5d37de fsck.c: call parse_msg_type() early in fsck_set_msg_type()
11: 7ffbf9af3fa = 11: ae5efd745cf fsck.c: undefine temporary STR macro after use
12: 12ff0f75ebf = 12: 96995244806 fsck.c: give "FOREACH_MSG_ID" a more specific name
13: 0c49dd5164f = 13: 1b42aea3a64 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
14: 900263f503a = 14: 563e6a0e5e6 fsck.c: pass along the fsck_msg_id in the fsck_error callback
15: 5f270e88a0a = 15: 5e504f25c51 fsck.c: add an fsck_set_msg_type() API that takes enums
16: 539d0197129 ! 16: 611631dd779 fsck.c: move gitmodules_{found,done} into fsck_options @@ Commit message
gitmodules_found attribute of "fsck_options" we need this intermediate step first.
+ An earlier version of this patch removed the small amount of
+ duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a
+ FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth
+ it for this amount of copy/pasting.
+
## fetch-pack.c ##
@@ fsck.h: struct fsck_options {
kh_oid_map_t *object_names;
};
-@@ fsck.h: struct fsck_options {
- .walk = NULL, \
- .msg_type = NULL, \
+ #define FSCK_OPTIONS_DEFAULT { \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
- .object_names = NULL,
- #define FSCK_OPTIONS_COMMON_ERROR_FUNC \
- FSCK_OPTIONS_COMMON \
+ .error_func = fsck_error_function \
+ }
+ #define FSCK_OPTIONS_STRICT { \
+ .strict = 1, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
+ .error_func = fsck_error_function, \
+ }
+
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
17: 1acf7442365 = 17: 03d512c8448 fetch-pack: don't needlessly copy fsck_options
18: b47c3d5ac6f = 18: 581c87c63c6 fetch-pack: use file-scope static struct for fsck_options
19: f05fa5c3ec9 ! 19: 6a38cade8c3 fetch-pack: use new fsck API to printing dangling submodules
@@ fetch-pack.c: static int server_supports_filtering;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
-@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+@@ fetch-pack.c: static int cmp_ref_by_name(const void *a_, const void *b_)
+ return strcmp(a->name, b->name);
+ }
- oidset_iter_init(gitmodules_oids, &iter);
- while ((oid = oidset_iter_next(&iter)))
+-static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+-{
+- struct oidset_iter iter;
+- const struct object_id *oid;
+-
+- if (!oidset_size(gitmodules_oids))
+- return;
+-
+- oidset_iter_init(gitmodules_oids, &iter);
+- while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
-+ oidset_insert(&fsck_options.gitmodules_found, oid);
- if (fsck_finish(&fsck_options))
- die("fsck failed");
- }
+- if (fsck_finish(&fsck_options))
+- die("fsck failed");
+-}
+-
+ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ int fd[2],
+ const struct ref *orig_ref,
+@@ fetch-pack.c: static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ int agent_len;
+ struct fetch_negotiator negotiator_alloc;
+ struct fetch_negotiator *negotiator;
+- struct oidset gitmodules_oids = OIDSET_INIT;
+
+ negotiator = &negotiator_alloc;
+ fetch_negotiator_init(r, negotiator);
+@@ fetch-pack.c: static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ else
+ alternate_shallow_file = NULL;
+ if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
+- &gitmodules_oids))
++ &fsck_options.gitmodules_found))
+ die(_("git fetch-pack: fetch failed."));
+- fsck_gitmodules_oids(&gitmodules_oids);
++ if (fsck_finish(&fsck_options))
++ die("fsck failed");
+
+ all_done:
+ if (negotiator)
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ struct string_list packfile_uris = STRING_LIST_INIT_DUP;
+ int i;
+ struct strvec index_pack_args = STRVEC_INIT;
+- struct oidset gitmodules_oids = OIDSET_INIT;
+
+ negotiator = &negotiator_alloc;
+ fetch_negotiator_init(r, negotiator);
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ process_section_header(&reader, "packfile", 0);
+ if (get_pack(args, fd, pack_lockfiles,
+ packfile_uris.nr ? &index_pack_args : NULL,
+- sought, nr_sought, &gitmodules_oids))
++ sought, nr_sought, &fsck_options.gitmodules_found))
+ die(_("git fetch-pack: fetch failed."));
+ do_check_stateless_delimiter(args, &reader);
+
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+
+ packname[the_hash_algo->hexsz] = '\0';
+
+- parse_gitmodules_oids(cmd.out, &gitmodules_oids);
++ parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found);
+
+ close(cmd.out);
+
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ string_list_clear(&packfile_uris, 0);
+ strvec_clear(&index_pack_args);
+
+- fsck_gitmodules_oids(&gitmodules_oids);
++ if (fsck_finish(&fsck_options))
++ die("fsck failed");
+
+ if (negotiator)
+ negotiator->release(negotiator);
## fsck.c ##
@@ fsck.c: int fsck_error_function(struct fsck_options *o,
@@ fsck.c: int git_fsck_config(const char *var, const char *value, void *cb)
+}
## fsck.h ##
+@@ fsck.h: int fsck_error_function(struct fsck_options *o,
+ const struct object_id *oid, enum object_type object_type,
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
++int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
++ const struct object_id *oid,
++ enum object_type object_type,
++ enum fsck_msg_type msg_type,
++ enum fsck_msg_id msg_id,
++ const char *message);
+
+ struct fsck_options {
+ fsck_walk_func walk;
+@@ fsck.h: struct fsck_options {
+ .gitmodules_done = OIDSET_INIT, \
+ .error_func = fsck_error_function, \
+ }
++#define FSCK_OPTIONS_MISSING_GITMODULES { \
++ .strict = 1, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
++ .error_func = fsck_error_cb_print_missing_gitmodules, \
++}
+
+ /* descend in all linked child objects
+ * the return value is:
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *optio
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
-@@ fsck.h: const char *fsck_describe_object(struct fsck_options *options,
- */
- int git_fsck_config(const char *var, const char *value, void *cb);
-
-+/*
-+ * Custom error callbacks that are used in more than one place.
-+ */
-+#define FSCK_OPTIONS_MISSING_GITMODULES { \
-+ .strict = 1, \
-+ .error_func = fsck_error_cb_print_missing_gitmodules, \
-+ FSCK_OPTIONS_COMMON \
-+}
-+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
-+ const struct object_id *oid,
-+ enum object_type object_type,
-+ enum fsck_msg_type msg_type,
-+ enum fsck_msg_id msg_id,
-+ const char *message);
-+
- #endifSignature · 1 line
2.31.1.445.g087790d4945
PATCH v6 1/19 fsck.c: refactor and rename common config callback
Refactor code I recently changed in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) so that I could use fsck's config callback in mktag in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05).
I don't know what I was thinking in structuring the code this way, but it clearly makes no sense to have an fsck_config_internal() at all just so it can get a fsck_options when git_config() already supports passing along some void* data.
Let's just make use of that instead, which gets us rid of the two wrapper functions, and brings fsck's common config callback in line with other such reusable config callbacks.
--- builtin/fsck.c | 7 +------ builtin/mktag.c | 7 +------ fsck.c | 4 ++-- fsck.h | 3 +-- 4 files changed, 5 insertions(+), 16 deletions(-)
builtin/fsck.c +1 -6
@@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid,return ret; } -static int fsck_config (const char *var,const char *value,void *cb) -{ -return fsck_config_internal (var, value, cb, &fsck_obj_options); -} -static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ;
@@ -803,7 +798,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (name_objects)fsck_enable_object_names (&fsck_walk_options); -git_config (fsck_config,NULL ); +git_config (git_fsck_config, &fsck_obj_options);if (connectivity_only) {for_each_loose_object (mark_loose_for_connectivity,NULL ,0 );
builtin/mktag.c +1 -6
@@ -14,11 +14,6 @@ static int option_strict = 1;static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; -static int mktag_config (const char *var,const char *value,void *cb) -{ -return fsck_config_internal (var, value, cb, &fsck_options); -} - static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type,
@@ -93,7 +88,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix) fsck_options.error_func = mktag_fsck_error_func;fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" );/* config might set fsck.extraHeaderEntry=* again */ -git_config (mktag_config,NULL ); +git_config (git_fsck_config, &fsck_options);if (fsck_tag_standalone (NULL , buf.buf, buf.len, &fsck_options, &tagged_oid, &tagged_type))die (_ ("tag on stdin did not pass our strict fsck check" ));
fsck.c +2 -2
@@ -1323,9 +1323,9 @@ int fsck_finish(struct fsck_options *options)return ret; } -int fsck_config_internal (const char *var,const char *value,void *cb, -struct fsck_options *options) +int git_fsck_config (const char *var,const char *value,void *cb) { +struct fsck_options *options = cb;if (strcmp (var,"fsck.skiplist" ) ==0 ) {const char *path;struct strbuf sb =STRBUF_INIT ;
fsck.h +1 -2
@@ -109,7 +109,6 @@ const char *fsck_describe_object(struct fsck_options *options,* git_config() callback for use by fsck-y tools that want to support * fsck.<msg> fsck.skipList etc. */ -int fsck_config_internal (const char *var,const char *value,void *cb, -struct fsck_options *options); +int git_fsck_config (const char *var,const char *value,void *cb);#endif
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 2/19 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð BjarmasonRefactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use designated initializers. This allows us to omit those fields that aren't initialized to zero or NULL.
--- fsck.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fsck.h +8 -2
@@ -43,8 +43,14 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { \ + .skiplist = OIDSET_INIT, \ + .error_func = fsck_error_function \ +} +#define FSCK_OPTIONS_STRICT { \ + .strict = 1, \ + .error_func = fsck_error_function, \ +}/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.1.445.g087790d4945
Re: [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use designated initializers. This allows us to omit those fields that aren't initialized to zero or NULL.
s/aren't/are/
[I apologize in advance - I am using mutt for the first time to reply to a ML post and I don't know if I should be using L-ist-reply or a g-roup-reply! :D ]
ATB,
Ramsay Jones
Re: [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
Quoted 6 lines · Ramsay Jones
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use designated initializers. This allows us to omit those fields that aren't initialized to zero or NULL.
s/aren't/are/
Thanks; tweak applied while queuing.
Quoted 3 lines
[I apologize in advance - I am using mutt for the first time to reply to a ML post and I don't know if I should be using L-ist-reply or a g-roup-reply! :D ]
FWIW, on lore (reading via nntp), the message I am responding to looks just fine.
PATCH v6 3/19 fsck.h: use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -192,7 +192,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 4/19 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
While I'm at it properly indent the fsck_set_msg_type() argument list.
--- fsck.c | 24 ++++++++++++------------ fsck.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 5/19 fsck.c: remove (mostly) redundant append_msg_id() function
In reply to Ævar Arnfjörð BjarmasonRemove the append_msg_id() function in favor of calling prepare_msg_ids(). We already have code to compute the camel-cased msg_id strings in msg_id_info, let's use it.
When the append_msg_id() function was added in 71ab8fa840f (fsck:
report the ID of the error/warning, 2015-06-22) the prepare_msg_ids() function didn't exist. When prepare_msg_ids() was added in a46baac61eb (fsck: factor out msg_id_info[] lazy initialization code, 2018-05-26) this code wasn't moved over to lazy initialization.
This changes the behavior of the code to initialize all the messages instead of just camel-casing the one we need on the fly. Since the common case is that we're printing just one message this is mostly redundant work.
But that's OK in this case, reporting this fsck issue to the user isn't performance-sensitive. If we were somehow doing so in a tight loop (in a hopelessly broken repository?) this would help, since we'd save ourselves from re-doing this work for identical messages, we could just grab the prepared string from msg_id_info after the first invocation.
--- fsck.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
fsck.c +2 -19
@@ -264,24 +264,6 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) -{ -for (;;) { -char c = *(msg_id)++; - -if (!c) -break ; -if (c !='_' ) -strbuf_addch (sb,tolower (c)); -else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); - } - } - -strbuf_addstr (sb,": " ); -} -static int object_on_skiplist (struct fsck_options *opts,const struct object_id *oid) {
@@ -308,7 +290,8 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +prepare_msg_ids (); +strbuf_addf (&sb,"%s: " , msg_id_info[id].camelcased);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 6/19 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -273,11 +273,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -291,7 +291,7 @@ static int report(struct fsck_options *options, msg_type =FSCK_WARN ;prepare_msg_ids (); -strbuf_addf (&sb,"%s: " , msg_id_info[id].camelcased); +strbuf_addf (&sb,"%s: " , msg_id_info[msg_id].camelcased);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 7/19 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
In reply to Ævar Arnfjörð BjarmasonRefactor "if options->msg_type" and other code added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit, only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type() function (also added in 0282f4dced0), which does a similar check for "!options->msg_type". Another minor benefit is getting rid of the style violation of not having braces for the body of the "if".
--- fsck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fsck.c +5 -7
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)static int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; -assert (msg_id >=0 && msg_id <FSCK_MSG_MAX ); -if (options->msg_type) - msg_type = options->msg_type[msg_id]; -else { - msg_type = msg_id_info[msg_id].msg_type; +if (!options->msg_type) { +int msg_type = msg_id_info[msg_id].msg_type; +if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ; +return msg_type; } -return msg_type; +return options->msg_type[msg_id]; }static int parse_msg_type (const char *str)
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 8/19 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks.
Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type.
--- builtin/fsck.c | 2 +- builtin/index-pack.c | 3 ++- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 16 ++++++++++------ 5 files changed, 25 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)static int print_dangling_gitmodules (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {/* * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
builtin/mktag.c +2 -1
@@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) {assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );if (!options->msg_type) { -int msg_type = msg_id_info[msg_id].msg_type; +enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return options->msg_type[msg_id]; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *severity; +enum fsck_msg_type *severity;ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) severity[i] =fsck_msg_type (i, options);
@@ -275,7 +273,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1247,7 +1246,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -6
@@ -3,9 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 9/19 fsck.h: re-order and re-assign "enum fsck_msg_type"
In reply to Ævar Arnfjörð BjarmasonChange the values in the "enum fsck_msg_type" from being manually assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously defined as "2".
I'm confident that nothing relies on these values, we always compare them for equality. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for not simply splitting these into two enums, namely that this is used for both the private and public fsck API.
--- fsck.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fsck.h +6 -4
@@ -4,11 +4,13 @@#include "oidset.h" enum fsck_msg_type { -FSCK_INFO =-2 , -FSCK_FATAL =-1 , -FSCK_ERROR =1 , +/* for internal use only */ +FSCK_IGNORE , +FSCK_INFO , +FSCK_FATAL , +/* "public", fed to e.g. error_func callbacks */ +FSCK_ERROR ,FSCK_WARN , -FSCK_IGNORE };struct fsck_options ;
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 10/19 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 11/19 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 12/19 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 13/19 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
In reply to Ævar Arnfjörð BjarmasonMove the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument.
--- fsck.c | 66 ---------------------------------------------------------- fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-)
fsck.c +0 -66
@@ -22,72 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_FSCK_MSG_ID (FUNC ) \ -/* fatal errors */ \ - FUNC(NUL_IN_HEADER, FATAL) \ - FUNC(UNTERMINATED_HEADER, FATAL) \ -/* errors */ \ - FUNC(BAD_DATE, ERROR) \ - FUNC(BAD_DATE_OVERFLOW, ERROR) \ - FUNC(BAD_EMAIL, ERROR) \ - FUNC(BAD_NAME, ERROR) \ - FUNC(BAD_OBJECT_SHA1, ERROR) \ - FUNC(BAD_PARENT_SHA1, ERROR) \ - FUNC(BAD_TAG_OBJECT, ERROR) \ - FUNC(BAD_TIMEZONE, ERROR) \ - FUNC(BAD_TREE, ERROR) \ - FUNC(BAD_TREE_SHA1, ERROR) \ - FUNC(BAD_TYPE, ERROR) \ - FUNC(DUPLICATE_ENTRIES, ERROR) \ - FUNC(MISSING_AUTHOR, ERROR) \ - FUNC(MISSING_COMMITTER, ERROR) \ - FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_TAG, ERROR) \ - FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TREE, ERROR) \ - FUNC(MISSING_TREE_OBJECT, ERROR) \ - FUNC(MISSING_TYPE, ERROR) \ - FUNC(MISSING_TYPE_ENTRY, ERROR) \ - FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TREE_NOT_SORTED, ERROR) \ - FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(ZERO_PADDED_DATE, ERROR) \ - FUNC(GITMODULES_MISSING, ERROR) \ - FUNC(GITMODULES_BLOB, ERROR) \ - FUNC(GITMODULES_LARGE, ERROR) \ - FUNC(GITMODULES_NAME, ERROR) \ - FUNC(GITMODULES_SYMLINK, ERROR) \ - FUNC(GITMODULES_URL, ERROR) \ - FUNC(GITMODULES_PATH, ERROR) \ -FUNC (GITMODULES_UPDATE ,ERROR ) \ - /* warnings */ \ - FUNC(BAD_FILEMODE, WARN) \ - FUNC(EMPTY_NAME, WARN) \ - FUNC(FULL_PATHNAME, WARN) \ - FUNC(HAS_DOT, WARN) \ - FUNC(HAS_DOTDOT, WARN) \ - FUNC(HAS_DOTGIT, WARN) \ - FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) \ -FUNC (NUL_IN_COMMIT ,WARN ) \ - /* infos (reported as warnings, but ignored by default) */ \ - FUNC(GITMODULES_PARSE, INFO) \ - FUNC(BAD_TAG_NAME, INFO) \ -FUNC (MISSING_TAGGER_ENTRY ,INFO ) \ - /* ignored (elevated when requested) */ \ - FUNC(EXTRA_HEADER_ENTRY, IGNORE) - -#define MSG_ID (id, msg_type) FSCK_MSG_##id, -enum fsck_msg_id { - FOREACH_FSCK_MSG_ID(MSG_ID) -FSCK_MSG_MAX -}; -#undef MSG_ID -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
fsck.h +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 14/19 fsck.c: pass along the fsck_msg_id in the fsck_error callback
In reply to Ævar Arnfjörð BjarmasonChange the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/[email protected]/
--- builtin/fsck.c | 4 +++- builtin/index-pack.c | 3 ++- builtin/mktag.c | 1 + fsck.c | 6 ++++-- fsck.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-)
builtin/fsck.c +3 -1
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) {/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,printf ("%s\n" ,oid_to_hex (oid));return 0 ; } -return fsck_error_function (o, oid, object_type, msg_type, message); +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); }int cmd_index_pack (int argc,const char **argv,const char *prefix)
builtin/mktag.c +1 -0
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { switch (msg_type) {
fsck.c +4 -2
@@ -227,7 +227,7 @@ static int report(struct fsck_options *options,va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (options, oid, object_type, - msg_type, sb.buf); + msg_type, msg_id, sb.buf);strbuf_release (&sb);va_end (ap);
@@ -1180,7 +1180,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +4 -2
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 15/19 fsck.c: add an fsck_set_msg_type() API that takes enums
In reply to Ævar Arnfjörð BjarmasonChange code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data.
For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler.
--- builtin/mktag.c | 3 ++- fsck.c | 27 +++++++++++++++++---------- fsck.h | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-)
builtin/mktag.c +2 -1
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)die_errno (_ ("could not read from stdin" )); fsck_options.error_func = mktag_fsck_error_func; -fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" ); +fsck_set_msg_type_from_ids (&fsck_options,FSCK_MSG_EXTRA_HEADER_ENTRY , +FSCK_WARN );/* config might set fsck.extraHeaderEntry=* again */ git_config (git_fsck_config, &fsck_options); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
fsck.c +17 -10
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)return 1 ; } +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type) +{ +if (!options->msg_type) { +int i; +enum fsck_msg_type *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; + } + + options->msg_type[msg_id] = msg_type; +} +void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) {
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str); -if (!options->msg_type) { -int i; -enum fsck_msg_type *severity; -ALLOC_ARRAY (severity,FSCK_MSG_MAX ); -for (i =0 ; i <FSCK_MSG_MAX ; i++) - severity[i] =fsck_msg_type (i, options); - options->msg_type = severity; - } - - options->msg_type[msg_id] = msg_type; +fsck_set_msg_type_from_ids (options, msg_id, msg_type); }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +3 -0
@@ -82,6 +82,9 @@ enum fsck_msg_id {struct fsck_options ;struct object ; +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type);void fsck_set_msg_type (struct fsck_options *options,const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 16/19 fsck.c: move gitmodules_{found,done} into fsck_options
In reply to Ævar Arnfjörð BjarmasonMove the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place.
This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first.
An earlier version of this patch removed the small amount of duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth it for this amount of copy/pasting.
--- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 9 ++++++++- 3 files changed, 19 insertions(+), 15 deletions(-)
fetch-pack.c +1 -1
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (oid); +register_found_gitmodules (&fo, oid);if (fsck_finish (&fo))die ("fsck failed" ); }
fsck.c +10 -13
@@ -19,9 +19,6 @@#include "credential.h" #include "help.h" -static struct oidset gitmodules_found =OIDSET_INIT ; -static struct oidset gitmodules_done =OIDSET_INIT ; -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
@@ -606,7 +603,7 @@ static int fsck_tree(const struct object_id *oid,if (is_hfs_dotgitmodules (name) ||is_ntfs_dotgitmodules (name)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE,
@@ -620,7 +617,7 @@ static int fsck_tree(const struct object_id *oid, has_dotgit |=is_ntfs_dotgit (backslash);if (is_ntfs_dotgitmodules (backslash)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK,
@@ -1132,9 +1129,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,struct fsck_gitmodules_data data;struct config_options config_opts = {0 }; -if (!oidset_contains (&gitmodules_found, oid)) +if (!oidset_contains (&options->gitmodules_found, oid))return 0 ; -oidset_insert (&gitmodules_done, oid); +oidset_insert (&options->gitmodules_done, oid);if (object_on_skiplist (options, oid))return 0 ;
@@ -1199,9 +1196,9 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (const struct object_id *oid) +void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) { -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid); }int fsck_finish (struct fsck_options *options)
@@ -1210,13 +1207,13 @@ int fsck_finish(struct fsck_options *options)struct oidset_iter iter;const struct object_id *oid; -oidset_iter_init (&gitmodules_found, &iter); +oidset_iter_init (&options->gitmodules_found, &iter);while ((oid =oidset_iter_next (&iter))) {enum object_type type;unsigned long size;char *buf; -if (oidset_contains (&gitmodules_done, oid)) +if (oidset_contains (&options->gitmodules_done, oid))continue ; buf =read_object_file (oid, &type, &size);
@@ -1241,8 +1238,8 @@ int fsck_finish(struct fsck_options *options) } -oidset_clear (&gitmodules_found); -oidset_clear (&gitmodules_done); +oidset_clear (&options->gitmodules_found); +oidset_clear (&options->gitmodules_done);return ret; }
fsck.h +8 -1
@@ -118,15 +118,21 @@ struct fsck_options { unsigned strict:1;enum fsck_msg_type *msg_type;struct oidset skiplist; +struct oidset gitmodules_found; +struct oidset gitmodules_done;kh_oid_map_t *object_names; };#define FSCK_OPTIONS_DEFAULT { \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function \ }#define FSCK_OPTIONS_STRICT { \ .strict = 1, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function, \ }
@@ -146,7 +152,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (const struct object_id *oid); +void register_found_gitmodules (struct fsck_options *options, +const struct object_id *oid);/* * fsck a tag, and pass info about it back to the caller. This is
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 17/19 fetch-pack: don't needlessly copy fsck_options
In reply to Ævar Arnfjörð BjarmasonChange the behavior of the .gitmodules validation added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting up the error_func earlier means that we're relying on the "error_func" not being set in some code in between the two hunks being modified here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is further setup by calling fsck_set_msg_types(), and assigning to do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the fsck_options struct before setting error_func. Let's just do this setup at the top of the function, along with the "walk" assignment.
--- builtin/index-pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
builtin/index-pack.c +3 -7
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; + fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)else close (input_fd); -if (do_fsck_object) { -struct fsck_options fo = fsck_options; - - fo.error_func = print_dangling_gitmodules; -if (fsck_finish (&fo)) -die (_ ("fsck error in pack objects" )); - } +if (do_fsck_object &&fsck_finish (&fsck_options)) +die (_ ("fsck error in pack objects" ));free (objects);strbuf_release (&index_name_buf);
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 18/19 fetch-pack: use file-scope static struct for fsck_options
In reply to Ævar Arnfjörð BjarmasonChange code added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so that we use a file-scoped "static struct fsck_options" instead of defining one in the "fsck_gitmodules_oids()" function.
We use this pattern in all of builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see fetch-pack be the odd one out. One might think that we're using other fsck_options structs in fetch-pack, or doing on fsck twice there, but we're not.
--- fetch-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fetch-pack.c +3 -3
@@ -38,6 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) {struct oidset_iter iter;const struct object_id *oid; -struct fsck_options fo =FSCK_OPTIONS_STRICT ;if (!oidset_size (gitmodules_oids))return ;oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fo, oid); -if (fsck_finish (&fo)) +register_found_gitmodules (&fsck_options, oid); +if (fsck_finish (&fsck_options))die ("fsck failed" ); }
Signature · 1 line
2.31.1.445.g087790d4945
PATCH v6 19/19 fetch-pack: use new fsck API to printing dangling submodules
In reply to Ævar Arnfjörð BjarmasonRefactor the check added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message.
Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
I'm sticking this callback in fsck.c. Perhaps in the future we'd like to accumulate such callbacks into another file (maybe fsck-cb.c, similar to parse-options-cb.c?), but while we've got just the one let's just put it into fsck.c.
A better alternative in this case would be some library some more obvious library shared by fetch-pack.c ad builtin/index-pack.c, but there isn't such a thing.
--- builtin/index-pack.c | 21 +-------------------- fetch-pack.c | 31 ++++++++----------------------- fsck.c | 23 ++++++++++++++++++----- fsck.h | 15 ++++++++++++--- 4 files changed, 39 insertions(+), 51 deletions(-)
builtin/index-pack.c +1 -20
@@ -120,7 +120,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static int verbose;static int show_resolving_progress;static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only) } } -static int print_dangling_gitmodules (struct fsck_options *o, -const struct object_id *oid, -enum object_type object_type, -enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, -const char *message) -{ -/* -* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it -* instead of relying on this string check. -*/ -if (starts_with (message,"gitmodulesMissing" )) { -printf ("%s\n" ,oid_to_hex (oid)); -return 0 ; - } -return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); -} -int cmd_index_pack (int argc,const char **argv,const char *prefix) {int i, fix_thin_pack =0 , verify =0 , stat_only =0 , rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
fetch-pack.c +8 -23
@@ -38,7 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -988,21 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)return strcmp (a->name, b->name); } -static void fsck_gitmodules_oids (struct oidset *gitmodules_oids) -{ -struct oidset_iter iter; -const struct object_id *oid; - -if (!oidset_size (gitmodules_oids)) -return ; - -oidset_iter_init (gitmodules_oids, &iter); -while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fsck_options, oid); -if (fsck_finish (&fsck_options)) -die ("fsck failed" ); -} - static struct ref *do_fetch_pack(struct fetch_pack_args *args, int fd[2], const struct ref *orig_ref,
@@ -1017,7 +1002,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,int agent_len;struct fetch_negotiator negotiator_alloc;struct fetch_negotiator *negotiator; -struct oidset gitmodules_oids =OIDSET_INIT ; negotiator = &negotiator_alloc;fetch_negotiator_init (r, negotiator);
@@ -1134,9 +1118,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,else alternate_shallow_file =NULL ;if (get_pack (args, fd, pack_lockfiles,NULL , sought, nr_sought, - &gitmodules_oids)) + &fsck_options.gitmodules_found))die (_ ("git fetch-pack: fetch failed." )); -fsck_gitmodules_oids (&gitmodules_oids); +if (fsck_finish (&fsck_options)) +die ("fsck failed" ); all_done:if (negotiator)
@@ -1587,7 +1572,6 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,struct string_list packfile_uris =STRING_LIST_INIT_DUP ;int i;struct strvec index_pack_args =STRVEC_INIT ; -struct oidset gitmodules_oids =OIDSET_INIT ; negotiator = &negotiator_alloc;fetch_negotiator_init (r, negotiator);
@@ -1678,7 +1662,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,process_section_header (&reader,"packfile" ,0 );if (get_pack (args, fd, pack_lockfiles, packfile_uris.nr ? &index_pack_args :NULL , - sought, nr_sought, &gitmodules_oids)) + sought, nr_sought, &fsck_options.gitmodules_found))die (_ ("git fetch-pack: fetch failed." ));do_check_stateless_delimiter (args, &reader);
@@ -1721,7 +1705,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, packname[the_hash_algo->hexsz] ='\0' ; -parse_gitmodules_oids (cmd.out, &gitmodules_oids); +parse_gitmodules_oids (cmd.out, &fsck_options.gitmodules_found);close (cmd.out);
@@ -1742,7 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,string_list_clear (&packfile_uris,0 );strvec_clear (&index_pack_args); -fsck_gitmodules_oids (&gitmodules_oids); +if (fsck_finish (&fsck_options)) +die ("fsck failed" );if (negotiator) negotiator->release (negotiator);
fsck.c +18 -5
@@ -1196,11 +1196,6 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) -{ -oidset_insert (&options->gitmodules_found, oid); -} -int fsck_finish (struct fsck_options *options) {int ret =0 ;
@@ -1266,3 +1261,21 @@ int git_fsck_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } + +/* +* Custom error callbacks that are used in more than one place. +*/ + +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +}
fsck.h +12 -3
@@ -111,6 +111,12 @@ int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message);struct fsck_options {fsck_walk_func walk;
@@ -135,6 +141,12 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function, \ } +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ +}/* descend in all linked child objects * the return value is:
@@ -152,9 +164,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (struct fsck_options *options, -const struct object_id *oid); -/* * fsck a tag, and pass info about it back to the caller. This is * exposed fsck_object() internals for git-mktag(1).
Signature · 1 line
2.31.1.445.g087790d4945
Re: [PATCH v6 00/19] fsck: API improvements
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
To recap on the goals in v1[1] this series gets rid of the need to have the rececently added "
print_dangling_gitmodules" function in favor of a better fsck API to get at that information.
Read the whole series afresh, as well as "git diff @{1}" after replacing to see what changed since the previous round. Didn't find anything iffy.
Unless somebody finds improvement opportunities in the coming couple of days, let's declare it is good enough and merge to 'next', polishing incrementally if needed.
Thanks.
PATCH v5 1/19 fsck.c: refactor and rename common config callback
In reply to Ævar Arnfjörð BjarmasonRefactor code I recently changed in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) so that I could use fsck's config callback in mktag in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05).
I don't know what I was thinking in structuring the code this way, but it clearly makes no sense to have an fsck_config_internal() at all just so it can get a fsck_options when git_config() already supports passing along some void* data.
Let's just make use of that instead, which gets us rid of the two wrapper functions, and brings fsck's common config callback in line with other such reusable config callbacks.
--- builtin/fsck.c | 7 +------ builtin/mktag.c | 7 +------ fsck.c | 4 ++-- fsck.h | 3 +-- 4 files changed, 5 insertions(+), 16 deletions(-)
builtin/fsck.c +1 -6
@@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid,return ret; } -static int fsck_config (const char *var,const char *value,void *cb) -{ -return fsck_config_internal (var, value, cb, &fsck_obj_options); -} -static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ;
@@ -803,7 +798,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (name_objects)fsck_enable_object_names (&fsck_walk_options); -git_config (fsck_config,NULL ); +git_config (git_fsck_config, &fsck_obj_options);if (connectivity_only) {for_each_loose_object (mark_loose_for_connectivity,NULL ,0 );
builtin/mktag.c +1 -6
@@ -14,11 +14,6 @@ static int option_strict = 1;static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; -static int mktag_config (const char *var,const char *value,void *cb) -{ -return fsck_config_internal (var, value, cb, &fsck_options); -} - static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type,
@@ -93,7 +88,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix) fsck_options.error_func = mktag_fsck_error_func;fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" );/* config might set fsck.extraHeaderEntry=* again */ -git_config (mktag_config,NULL ); +git_config (git_fsck_config, &fsck_options);if (fsck_tag_standalone (NULL , buf.buf, buf.len, &fsck_options, &tagged_oid, &tagged_type))die (_ ("tag on stdin did not pass our strict fsck check" ));
fsck.c +2 -2
@@ -1323,9 +1323,9 @@ int fsck_finish(struct fsck_options *options)return ret; } -int fsck_config_internal (const char *var,const char *value,void *cb, -struct fsck_options *options) +int git_fsck_config (const char *var,const char *value,void *cb) { +struct fsck_options *options = cb;if (strcmp (var,"fsck.skiplist" ) ==0 ) {const char *path;struct strbuf sb =STRBUF_INIT ;
fsck.h +1 -2
@@ -109,7 +109,6 @@ const char *fsck_describe_object(struct fsck_options *options,* git_config() callback for use by fsck-y tools that want to support * fsck.<msg> fsck.skipList etc. */ -int fsck_config_internal (const char *var,const char *value,void *cb, -struct fsck_options *options); +int git_fsck_config (const char *var,const char *value,void *cb);#endif
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 2/19 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð BjarmasonRefactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use designated initializers.
While I'm at it add the "object_names" member to the initialization. This was omitted in 7b35efd734e (fsck_walk():
optionally name objects on the go, 2016-07-17) when the field was added.
I'm using a new FSCK_OPTIONS_COMMON and FSCK_OPTIONS_COMMON_ERROR_FUNC helper macros to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in common, and define the two in terms of those macro.
The FSCK_OPTIONS_COMMON macro will be used in a subsequent commit to define other variants of common fsck initialization that wants to use a custom error function, but share the rest of the defaults.
--- fsck.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fsck.h +11 -2
@@ -43,8 +43,17 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_COMMON \ + .walk = NULL, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ + FSCK_OPTIONS_COMMON \ + .error_func = fsck_error_function + +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 3/19 fsck.h: use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -192,7 +192,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 4/19 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
While I'm at it properly indent the fsck_set_msg_type() argument list.
--- fsck.c | 24 ++++++++++++------------ fsck.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 5/19 fsck.c: move definition of msg_id into append_msg_id()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report().
--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fsck.c +3 -2
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 6/19 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fsck.c +8 -8
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 7/19 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
In reply to Ævar Arnfjörð BjarmasonRefactor "if options->msg_type" and other code added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit, only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type() function (also added in 0282f4dced0), which does a similar check for "!options->msg_type". Another minor benefit is getting rid of the style violation of not having braces for the body of the "if".
--- fsck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fsck.c +5 -7
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)static int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; -assert (msg_id >=0 && msg_id <FSCK_MSG_MAX ); -if (options->msg_type) - msg_type = options->msg_type[msg_id]; -else { - msg_type = msg_id_info[msg_id].msg_type; +if (!options->msg_type) { +int msg_type = msg_id_info[msg_id].msg_type; +if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ; +return msg_type; } -return msg_type; +return options->msg_type[msg_id]; }static int parse_msg_type (const char *str)
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 8/19 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks.
Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type.
--- builtin/fsck.c | 2 +- builtin/index-pack.c | 3 ++- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 16 ++++++++++------ 5 files changed, 25 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)static int print_dangling_gitmodules (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {/* * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
builtin/mktag.c +2 -1
@@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) {assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );if (!options->msg_type) { -int msg_type = msg_id_info[msg_id].msg_type; +enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return options->msg_type[msg_id]; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *severity; +enum fsck_msg_type *severity;ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) severity[i] =fsck_msg_type (i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -6
@@ -3,9 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 9/19 fsck.h: re-order and re-assign "enum fsck_msg_type"
In reply to Ævar Arnfjörð BjarmasonChange the values in the "enum fsck_msg_type" from being manually assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously defined as "2".
I'm confident that nothing relies on these values, we always compare them explicitly. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for not simply splitting these into two enums, namely that this is used for both the private and public fsck API.
--- fsck.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fsck.h +6 -4
@@ -4,11 +4,13 @@#include "oidset.h" enum fsck_msg_type { -FSCK_INFO =-2 , -FSCK_FATAL =-1 , -FSCK_ERROR =1 , +/* for internal use only */ +FSCK_IGNORE , +FSCK_INFO , +FSCK_FATAL , +/* "public", fed to e.g. error_func callbacks */ +FSCK_ERROR ,FSCK_WARN , -FSCK_IGNORE };struct fsck_options ;
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 10/19 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 11/19 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 12/19 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 13/19 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
In reply to Ævar Arnfjörð BjarmasonMove the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument.
--- fsck.c | 66 ---------------------------------------------------------- fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-)
fsck.c +0 -66
@@ -22,72 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_FSCK_MSG_ID (FUNC ) \ -/* fatal errors */ \ - FUNC(NUL_IN_HEADER, FATAL) \ - FUNC(UNTERMINATED_HEADER, FATAL) \ -/* errors */ \ - FUNC(BAD_DATE, ERROR) \ - FUNC(BAD_DATE_OVERFLOW, ERROR) \ - FUNC(BAD_EMAIL, ERROR) \ - FUNC(BAD_NAME, ERROR) \ - FUNC(BAD_OBJECT_SHA1, ERROR) \ - FUNC(BAD_PARENT_SHA1, ERROR) \ - FUNC(BAD_TAG_OBJECT, ERROR) \ - FUNC(BAD_TIMEZONE, ERROR) \ - FUNC(BAD_TREE, ERROR) \ - FUNC(BAD_TREE_SHA1, ERROR) \ - FUNC(BAD_TYPE, ERROR) \ - FUNC(DUPLICATE_ENTRIES, ERROR) \ - FUNC(MISSING_AUTHOR, ERROR) \ - FUNC(MISSING_COMMITTER, ERROR) \ - FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_TAG, ERROR) \ - FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TREE, ERROR) \ - FUNC(MISSING_TREE_OBJECT, ERROR) \ - FUNC(MISSING_TYPE, ERROR) \ - FUNC(MISSING_TYPE_ENTRY, ERROR) \ - FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TREE_NOT_SORTED, ERROR) \ - FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(ZERO_PADDED_DATE, ERROR) \ - FUNC(GITMODULES_MISSING, ERROR) \ - FUNC(GITMODULES_BLOB, ERROR) \ - FUNC(GITMODULES_LARGE, ERROR) \ - FUNC(GITMODULES_NAME, ERROR) \ - FUNC(GITMODULES_SYMLINK, ERROR) \ - FUNC(GITMODULES_URL, ERROR) \ - FUNC(GITMODULES_PATH, ERROR) \ -FUNC (GITMODULES_UPDATE ,ERROR ) \ - /* warnings */ \ - FUNC(BAD_FILEMODE, WARN) \ - FUNC(EMPTY_NAME, WARN) \ - FUNC(FULL_PATHNAME, WARN) \ - FUNC(HAS_DOT, WARN) \ - FUNC(HAS_DOTDOT, WARN) \ - FUNC(HAS_DOTGIT, WARN) \ - FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) \ -FUNC (NUL_IN_COMMIT ,WARN ) \ - /* infos (reported as warnings, but ignored by default) */ \ - FUNC(GITMODULES_PARSE, INFO) \ - FUNC(BAD_TAG_NAME, INFO) \ -FUNC (MISSING_TAGGER_ENTRY ,INFO ) \ - /* ignored (elevated when requested) */ \ - FUNC(EXTRA_HEADER_ENTRY, IGNORE) - -#define MSG_ID (id, msg_type) FSCK_MSG_##id, -enum fsck_msg_id { - FOREACH_FSCK_MSG_ID(MSG_ID) -FSCK_MSG_MAX -}; -#undef MSG_ID -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
fsck.h +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 14/19 fsck.c: pass along the fsck_msg_id in the fsck_error callback
In reply to Ævar Arnfjörð BjarmasonChange the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/[email protected]/
--- builtin/fsck.c | 4 +++- builtin/index-pack.c | 3 ++- builtin/mktag.c | 1 + fsck.c | 6 ++++-- fsck.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-)
builtin/fsck.c +3 -1
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) {/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,printf ("%s\n" ,oid_to_hex (oid));return 0 ; } -return fsck_error_function (o, oid, object_type, msg_type, message); +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); }int cmd_index_pack (int argc,const char **argv,const char *prefix)
builtin/mktag.c +1 -0
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { switch (msg_type) {
fsck.c +4 -2
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (options, oid, object_type, - msg_type, sb.buf); + msg_type, msg_id, sb.buf);strbuf_release (&sb);va_end (ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +4 -2
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 15/19 fsck.c: add an fsck_set_msg_type() API that takes enums
In reply to Ævar Arnfjörð BjarmasonChange code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data.
For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler.
--- builtin/mktag.c | 3 ++- fsck.c | 27 +++++++++++++++++---------- fsck.h | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-)
builtin/mktag.c +2 -1
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)die_errno (_ ("could not read from stdin" )); fsck_options.error_func = mktag_fsck_error_func; -fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" ); +fsck_set_msg_type_from_ids (&fsck_options,FSCK_MSG_EXTRA_HEADER_ENTRY , +FSCK_WARN );/* config might set fsck.extraHeaderEntry=* again */ git_config (git_fsck_config, &fsck_options); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
fsck.c +17 -10
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)return 1 ; } +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type) +{ +if (!options->msg_type) { +int i; +enum fsck_msg_type *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; + } + + options->msg_type[msg_id] = msg_type; +} +void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) {
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str); -if (!options->msg_type) { -int i; -enum fsck_msg_type *severity; -ALLOC_ARRAY (severity,FSCK_MSG_MAX ); -for (i =0 ; i <FSCK_MSG_MAX ; i++) - severity[i] =fsck_msg_type (i, options); - options->msg_type = severity; - } - - options->msg_type[msg_id] = msg_type; +fsck_set_msg_type_from_ids (options, msg_id, msg_type); }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +3 -0
@@ -82,6 +82,9 @@ enum fsck_msg_id {struct fsck_options ;struct object ; +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type);void fsck_set_msg_type (struct fsck_options *options,const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 16/19 fsck.c: move gitmodules_{found,done} into fsck_options
In reply to Ævar Arnfjörð BjarmasonMove the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place.
This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first.
--- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 7 ++++++- 3 files changed, 17 insertions(+), 15 deletions(-)
fetch-pack.c +1 -1
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (oid); +register_found_gitmodules (&fo, oid);if (fsck_finish (&fo))die ("fsck failed" ); }
fsck.c +10 -13
@@ -19,9 +19,6 @@#include "credential.h" #include "help.h" -static struct oidset gitmodules_found =OIDSET_INIT ; -static struct oidset gitmodules_done =OIDSET_INIT ; -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,if (is_hfs_dotgitmodules (name) ||is_ntfs_dotgitmodules (name)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid, has_dotgit |=is_ntfs_dotgit (backslash);if (is_ntfs_dotgitmodules (backslash)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,struct fsck_gitmodules_data data;struct config_options config_opts = {0 }; -if (!oidset_contains (&gitmodules_found, oid)) +if (!oidset_contains (&options->gitmodules_found, oid))return 0 ; -oidset_insert (&gitmodules_done, oid); +oidset_insert (&options->gitmodules_done, oid);if (object_on_skiplist (options, oid))return 0 ;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (const struct object_id *oid) +void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) { -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid); }int fsck_finish (struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)struct oidset_iter iter;const struct object_id *oid; -oidset_iter_init (&gitmodules_found, &iter); +oidset_iter_init (&options->gitmodules_found, &iter);while ((oid =oidset_iter_next (&iter))) {enum object_type type;unsigned long size;char *buf; -if (oidset_contains (&gitmodules_done, oid)) +if (oidset_contains (&options->gitmodules_done, oid))continue ; buf =read_object_file (oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options) } -oidset_clear (&gitmodules_found); -oidset_clear (&gitmodules_done); +oidset_clear (&options->gitmodules_found); +oidset_clear (&options->gitmodules_done);return ret; }
fsck.h +6 -1
@@ -118,6 +118,8 @@ struct fsck_options { unsigned strict:1;enum fsck_msg_type *msg_type;struct oidset skiplist; +struct oidset gitmodules_found; +struct oidset gitmodules_done;kh_oid_map_t *object_names; };
@@ -125,6 +127,8 @@ struct fsck_options { .walk = NULL, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .object_names = NULL,#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (const struct object_id *oid); +void register_found_gitmodules (struct fsck_options *options, +const struct object_id *oid);/* * fsck a tag, and pass info about it back to the caller. This is
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 17/19 fetch-pack: don't needlessly copy fsck_options
In reply to Ævar Arnfjörð BjarmasonChange the behavior of the .gitmodules validation added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting up the error_func earlier means that we're relying on the "error_func" not being set in some code in between the two hunks being modified here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is further setup by calling fsck_set_msg_types(), and assigning to do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the fsck_options struct before setting error_func. Let's just do this setup at the top of the function, along with the "walk" assignment.
--- builtin/index-pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
builtin/index-pack.c +3 -7
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; + fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)else close (input_fd); -if (do_fsck_object) { -struct fsck_options fo = fsck_options; - - fo.error_func = print_dangling_gitmodules; -if (fsck_finish (&fo)) -die (_ ("fsck error in pack objects" )); - } +if (do_fsck_object &&fsck_finish (&fsck_options)) +die (_ ("fsck error in pack objects" ));free (objects);strbuf_release (&index_name_buf);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 18/19 fetch-pack: use file-scope static struct for fsck_options
In reply to Ævar Arnfjörð BjarmasonChange code added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so that we use a file-scoped "static struct fsck_options" instead of defining one in the "fsck_gitmodules_oids()" function.
We use this pattern in all of builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see fetch-pack be the odd one out. One might think that we're using other fsck_options structs in fetch-pack, or doing on fsck twice there, but we're not.
--- fetch-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fetch-pack.c +3 -3
@@ -38,6 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) {struct oidset_iter iter;const struct object_id *oid; -struct fsck_options fo =FSCK_OPTIONS_STRICT ;if (!oidset_size (gitmodules_oids))return ;oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fo, oid); -if (fsck_finish (&fo)) +register_found_gitmodules (&fsck_options, oid); +if (fsck_finish (&fsck_options))die ("fsck failed" ); }
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v5 19/19 fetch-pack: use new fsck API to printing dangling submodules
In reply to Ævar Arnfjörð BjarmasonRefactor the check added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message.
Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
I'm sticking this callback in fsck.c. Perhaps in the future we'd like to accumulate such callbacks into another file (maybe fsck-cb.c, similar to parse-options-cb.c?), but while we've got just the one let's just put it into fsck.c.
A better alternative in this case would be some library some more obvious library shared by fetch-pack.c ad builtin/index-pack.c, but there isn't such a thing.
--- builtin/index-pack.c | 21 +-------------------- fetch-pack.c | 4 ++-- fsck.c | 23 ++++++++++++++++++----- fsck.h | 18 +++++++++++++++--- 4 files changed, 36 insertions(+), 30 deletions(-)
builtin/index-pack.c +1 -20
@@ -120,7 +120,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static int verbose;static int show_resolving_progress;static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only) } } -static int print_dangling_gitmodules (struct fsck_options *o, -const struct object_id *oid, -enum object_type object_type, -enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, -const char *message) -{ -/* -* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it -* instead of relying on this string check. -*/ -if (starts_with (message,"gitmodulesMissing" )) { -printf ("%s\n" ,oid_to_hex (oid)); -return 0 ; - } -return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); -} -int cmd_index_pack (int argc,const char **argv,const char *prefix) {int i, fix_thin_pack =0 , verify =0 , stat_only =0 , rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
fetch-pack.c +2 -2
@@ -38,7 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fsck_options, oid); +oidset_insert (&fsck_options.gitmodules_found, oid);if (fsck_finish (&fsck_options))die ("fsck failed" ); }
fsck.c +18 -5
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) -{ -oidset_insert (&options->gitmodules_found, oid); -} -int fsck_finish (struct fsck_options *options) {int ret =0 ;
@@ -1284,3 +1279,21 @@ int git_fsck_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } + +/* +* Custom error callbacks that are used in more than one place. +*/ + +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +}
fsck.h +15 -3
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (struct fsck_options *options, -const struct object_id *oid); -/* * fsck a tag, and pass info about it back to the caller. This is * exposed fsck_object() internals for git-mktag(1).
@@ -203,4 +200,19 @@ const char *fsck_describe_object(struct fsck_options *options,*/ int git_fsck_config (const char *var,const char *value,void *cb); +/* +* Custom error callbacks that are used in more than one place. +*/ +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ + FSCK_OPTIONS_COMMON \ +} +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message); +#endif
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 1/22 fsck.h: update FSCK_OPTIONS_* for object_name
In reply to Ævar Arnfjörð BjarmasonAdd the object_name member to the initialization macro. This was omitted in 7b35efd734e (fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fsck.h +2 -2
@@ -43,8 +43,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
While this does not hurt, as the missing one was and is at the end of the struct members, this has no effect. As you'll be rewriting everything into designated initializers anyway, does it matter, I have to wonder (it would affect your commit count karma, but you already have enough of them ;-)?
Quoted 21 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fsck.h +2
-2@@ -43,8 +43,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is:
Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
In reply to Ævar Arnfjörð BjarmasonHi Ævar,
just a general note: this patch, which is the first of v4, is marked as replying to the cover letter of v3. That feels quite odd. If you use threading, why not let it reply to the cover letter of the same patch series iteration?
In other words, would you mind using the --thread=shallow option in the future, for better structuring on the mailing list?
Thanks,
Johannes
Quoted 28 lines · Ævar Arnfjörð Bjarmason
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fsck.h +2
-3@@ -43,8 +43,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is: -- 2.31.0.260.g719c683c1d
Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
Quoted 9 lines · Johannes Schindelin
Hi Ævar,
just a general note: this patch, which is the first of v4, is marked as replying to the cover letter of v3. That feels quite odd. If you use threading, why not let it reply to the cover letter of the same patch series iteration?
In other words, would you mind using the
--thread=shallowoption in the future, for better structuring on the mailing list?
Not at all, I've set it in my config now.
I've just been using the default configuration of format-patch --in-reply-to --cover-letter && send-email *.patch all this time.
Looking around at other patch submissions (aside from GGG) this seems to be the norm though, but isn't documented in SubmittingPatches etc. AFAICT.
So I wonder if I'm using some different process from the norm, or if most everyone else is just looking carefully at Message-ID/In-Reply-To norms before sending...
Quoted 30 lines · Ævar Arnfjörð Bjarmason
Quoted 29 lines
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fsck.h +2
-3@@ -43,8 +43,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is: -- 2.31.0.260.g719c683c1d
Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
Quoted 11 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines
In other words, would you mind using the
--thread=shallowoption in the future, for better structuring on the mailing list?Not at all, I've set it in my config now.
I've just been using the default configuration of format-patch --in-reply-to --cover-letter && send-email *.patch all this time.
...
So I wonder if I'm using some different process from the norm, or if most everyone else is just looking carefully at Message-ID/In-Reply-To norms before sending...
Interesting. I always let send-email assign the message IDs and haven't used --thread=<any> option at all. In other words, my format-patch output files have no message IDs in them or In-reply-to header fields. That in turn means that in-reply-to is decided not when format-patch is run, but when send-email sends things out, it gives them the ids and structures the in-reply-to chains.
I guess we have too much flexibility in our tooling X-<.
PATCH v4 2/22 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fsck.h +16 -2
@@ -43,8 +43,22 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_DEFAULT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 0, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +} +#define FSCK_OPTIONS_STRICT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 1, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +}/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
Quoted 10 lines · Ævar Arnfjörð Bjarmason
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)fsck.h +0
-0
fsck.h struct fsck_options { · line 47
Quoted 5 lines
fsck.h +0
-2@@ -43,8 +43,22 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
You just edited these lines in the previous patch. Seems unnecesary to split them. You can point out that the object_names portion was previously excluded in the message here.
Quoted 6 lines
fsck.h +6
-0+#define FSCK_OPTIONS_DEFAULT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 0, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \
fsck.h struct fsck_options { · line 61
Quoted 10 lines
fsck.h +10
-0+ .object_names = NULL, \ +} +#define FSCK_OPTIONS_STRICT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 1, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +}
This explicit definition is better.
Thanks,
-Stolee
Re: [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð BjarmasonQuoted 21 lines · Ævar Arnfjörð Bjarmason
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)fsck.h +6
-2@@ -43,8 +43,22 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_DEFAULT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 0, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \
fsck.h struct fsck_options { · line 61
Quoted 10 lines
fsck.h +10
-0+ .object_names = NULL, \ +} +#define FSCK_OPTIONS_STRICT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 1, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +}
Being explicit is good, but spelling out zero initialization sounds more like cluttering than clarifying. I do not mind .strict = 0 in the DEFAULT one only because it contrasts well with .strict = 1 on the STRICT side, but it would be easier to read to omit these zero initilization of the .walk, .msg_type and .object_names members.
Quoted 2 lines
fsck.h +0
-0/* descend in all linked child objects * the return value is:
PATCH v4 3/22 fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð BjarmasonUse a temporary macro to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in common, and define the two in terms of that macro.
--- fsck.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
fsck.h +4 -12
@@ -43,22 +43,14 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { \ +#define FSCK_OPTIONS_COMMON \ .walk = NULL, \ .error_func = fsck_error_function, \ - .strict = 0, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ - .object_names = NULL, \ -} -#define FSCK_OPTIONS_STRICT { \ - .walk = NULL, \ - .error_func = fsck_error_function, \ - .strict = 1, \ - .msg_type = NULL, \ - .skiplist = OIDSET_INIT, \ - .object_names = NULL, \ -} + .object_names = NULL, +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 4/22 fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
In reply to Ævar Arnfjörð BjarmasonAdd a FSCK_OPTIONS_COMMON_ERROR_FUNC macro for those that would like to use FSCK_OPTIONS_COMMON in their own initialization, but supply their own error functions.
Nothing is being changed to use this yet, but in some subsequent commits we'll make use of this macro.
--- fsck.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fsck.h +6 -3
@@ -45,12 +45,15 @@ struct fsck_options {#define FSCK_OPTIONS_COMMON \ .walk = NULL, \ - .error_func = fsck_error_function, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ .object_names = NULL, -#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON } -#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON } +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ + FSCK_OPTIONS_COMMON \ + .error_func = fsck_error_function + +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
Quoted 22 lines · Ævar Arnfjörð Bjarmason
Add a
FSCK_OPTIONS_COMMON_ERROR_FUNCmacro for those that would like to useFSCK_OPTIONS_COMMONin their own initialization, but supply their own error functions.Nothing is being changed to use this yet, but in some subsequent commits we'll make use of this macro.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fsck.h +0
-1@@ -45,12 +45,15 @@ struct fsck_options {#define FSCK_OPTIONS_COMMON \ .walk = NULL, \ - .error_func = fsck_error_function, \ .msg_type = NULL, \
fsck.h struct fsck_options { · line 56
Quoted 10 lines
fsck.h +6
-2.skiplist = OIDSET_INIT, \ .object_names = NULL, -#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON } -#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON } +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ + FSCK_OPTIONS_COMMON \ + .error_func = fsck_error_function + +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
OK. It seems like you are converging on your final definitions for these macros. At first glance, this seems like unnecessary split to demonstrate the tiny changes between, but it could just be done with one change and a description of why you want the four different entry points as macros.
Thanks,
-Stolee
PATCH v4 5/22 fsck.h: indent arguments to of fsck_set_msg_type
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 6/22 fsck.h: use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -197,7 +197,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 7/22 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
--- fsck.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 8/22 fsck.c: move definition of msg_id into append_msg_id()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report().
--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fsck.c +3 -2
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id()
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Refactor code added in
71ab8fa840f(fsck: report the ID of the error/warning, 2015-06-22) to resolve themsg_idto a string in the function that wants it, instead of doing it inreport().
This reintroduces the same confusion 07/22 tried to get rid of, unless msg_id variable is renamed to msg_id_str in this step, instead of being left to the next step, no?
Quoted 29 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fsck.c +3
-2@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
PATCH v4 9/22 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fsck.c +8 -8
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 10/22 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
In reply to Ævar Arnfjörð BjarmasonRefactor "if options->msg_type" and other code added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit, only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type() function (also added in 0282f4dced0), which does a similar check for "!options->msg_type". Another minor benefit is getting rid of the style violation of not having braces for the body of the "if".
--- fsck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fsck.c +5 -7
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)static int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; -assert (msg_id >=0 && msg_id <FSCK_MSG_MAX ); -if (options->msg_type) - msg_type = options->msg_type[msg_id]; -else { - msg_type = msg_id_info[msg_id].msg_type; +if (!options->msg_type) { +int msg_type = msg_id_info[msg_id].msg_type; +if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ; +return msg_type; } -return msg_type; +return options->msg_type[msg_id]; }static int parse_msg_type (const char *str)
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 11/22 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks.
Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type.
--- builtin/fsck.c | 2 +- builtin/index-pack.c | 3 ++- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 16 ++++++++++------ 5 files changed, 25 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)static int print_dangling_gitmodules (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {/* * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
builtin/mktag.c +2 -1
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) {assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );if (!options->msg_type) { -int msg_type = msg_id_info[msg_id].msg_type; +enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return options->msg_type[msg_id]; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *severity; +enum fsck_msg_type *severity;ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) severity[i] =fsck_msg_type (i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -6
@@ -3,9 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
Quoted 2 lines · Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_typeenum.
Nice.
Quoted 4 lines
Untangling that would take some more work, since we expose the new "enum
fsck_msg_type" to both. Similar to "enumobject_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type.
PATCH v4 12/22 fsck.h: re-order and re-assign "enum fsck_msg_type"
In reply to Ævar Arnfjörð BjarmasonChange the values in the "enum fsck_msg_type" from being manually assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously defined as "2".
I'm confident that nothing relies on these values, we always compare them explicitly. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for not simply splitting these into two enums, namely that this is used for both the private and public fsck API.
--- fsck.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fsck.h +6 -4
@@ -4,11 +4,13 @@#include "oidset.h" enum fsck_msg_type { -FSCK_INFO =-2 , -FSCK_FATAL =-1 , -FSCK_ERROR =1 , +/* for internal use only */ +FSCK_IGNORE , +FSCK_INFO , +FSCK_FATAL , +/* "public", fed to e.g. error_func callbacks */ +FSCK_ERROR ,FSCK_WARN , -FSCK_IGNORE };struct fsck_options ;
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type"
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Change the values in the "enum
fsck_msg_type" from being manually assigned to using default C enum values.This means we end up with a FSCK_IGNORE=0, which was previously defined as "2".
I'm confident that nothing relies on these values, we always compare them explicitly. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere.
Do you mean by "compare them explicitly", we always compare for equality?
If the code had depended on constructs like "if (msg < FSCK_ERROR)", this change would break badly.
Quoted 22 lines
fsck.h +6
-4@@ -4,11 +4,13 @@#include "oidset.h" enum fsck_msg_type { -FSCK_INFO =-2 , -FSCK_FATAL =-1 , -FSCK_ERROR =1 , +/* for internal use only */ +FSCK_IGNORE , +FSCK_INFO , +FSCK_FATAL , +/* "public", fed to e.g. error_func callbacks */ +FSCK_ERROR ,FSCK_WARN , -FSCK_IGNORE };struct fsck_options ;
PATCH v4 13/22 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 14/22 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use
Quoted 5 lines · Ævar Arnfjörð Bjarmason
In
f417eed8cde(fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for theMSG_IDmacro inc99ba492f1c(fsck: introduce identifiers for fsck messages, 2015-06-22).
Makes sense. Thanks.
Quoted 18 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.c | 1 + 1 file changed, 1 insertion(+)fsck.c +1
-0@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
PATCH v4 15/22 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 16/22 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
In reply to Ævar Arnfjörð BjarmasonMove the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument.
--- fsck.c | 66 ---------------------------------------------------------- fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-)
fsck.c +0 -66
@@ -22,72 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_FSCK_MSG_ID (FUNC ) \ -/* fatal errors */ \ - FUNC(NUL_IN_HEADER, FATAL) \ - FUNC(UNTERMINATED_HEADER, FATAL) \ -/* errors */ \ - FUNC(BAD_DATE, ERROR) \ - FUNC(BAD_DATE_OVERFLOW, ERROR) \ - FUNC(BAD_EMAIL, ERROR) \ - FUNC(BAD_NAME, ERROR) \ - FUNC(BAD_OBJECT_SHA1, ERROR) \ - FUNC(BAD_PARENT_SHA1, ERROR) \ - FUNC(BAD_TAG_OBJECT, ERROR) \ - FUNC(BAD_TIMEZONE, ERROR) \ - FUNC(BAD_TREE, ERROR) \ - FUNC(BAD_TREE_SHA1, ERROR) \ - FUNC(BAD_TYPE, ERROR) \ - FUNC(DUPLICATE_ENTRIES, ERROR) \ - FUNC(MISSING_AUTHOR, ERROR) \ - FUNC(MISSING_COMMITTER, ERROR) \ - FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_TAG, ERROR) \ - FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TREE, ERROR) \ - FUNC(MISSING_TREE_OBJECT, ERROR) \ - FUNC(MISSING_TYPE, ERROR) \ - FUNC(MISSING_TYPE_ENTRY, ERROR) \ - FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TREE_NOT_SORTED, ERROR) \ - FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(ZERO_PADDED_DATE, ERROR) \ - FUNC(GITMODULES_MISSING, ERROR) \ - FUNC(GITMODULES_BLOB, ERROR) \ - FUNC(GITMODULES_LARGE, ERROR) \ - FUNC(GITMODULES_NAME, ERROR) \ - FUNC(GITMODULES_SYMLINK, ERROR) \ - FUNC(GITMODULES_URL, ERROR) \ - FUNC(GITMODULES_PATH, ERROR) \ -FUNC (GITMODULES_UPDATE ,ERROR ) \ - /* warnings */ \ - FUNC(BAD_FILEMODE, WARN) \ - FUNC(EMPTY_NAME, WARN) \ - FUNC(FULL_PATHNAME, WARN) \ - FUNC(HAS_DOT, WARN) \ - FUNC(HAS_DOTDOT, WARN) \ - FUNC(HAS_DOTGIT, WARN) \ - FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) \ -FUNC (NUL_IN_COMMIT ,WARN ) \ - /* infos (reported as warnings, but ignored by default) */ \ - FUNC(GITMODULES_PARSE, INFO) \ - FUNC(BAD_TAG_NAME, INFO) \ -FUNC (MISSING_TAGGER_ENTRY ,INFO ) \ - /* ignored (elevated when requested) */ \ - FUNC(EXTRA_HEADER_ENTRY, IGNORE) - -#define MSG_ID (id, msg_type) FSCK_MSG_##id, -enum fsck_msg_id { - FOREACH_FSCK_MSG_ID(MSG_ID) -FSCK_MSG_MAX -}; -#undef MSG_ID -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
fsck.h +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 17/22 fsck.c: pass along the fsck_msg_id in the fsck_error callback
In reply to Ævar Arnfjörð BjarmasonChange the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/[email protected]/
--- builtin/fsck.c | 4 +++- builtin/index-pack.c | 3 ++- builtin/mktag.c | 1 + fsck.c | 6 ++++-- fsck.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-)
builtin/fsck.c +3 -1
@@ -89,7 +89,9 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) {/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,printf ("%s\n" ,oid_to_hex (oid));return 0 ; } -return fsck_error_function (o, oid, object_type, msg_type, message); +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); }int cmd_index_pack (int argc,const char **argv,const char *prefix)
builtin/mktag.c +1 -0
@@ -23,6 +23,7 @@ static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { switch (msg_type) {
fsck.c +4 -2
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (options, oid, object_type, - msg_type, sb.buf); + msg_type, msg_id, sb.buf);strbuf_release (&sb);va_end (ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +4 -2
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Change the
fsck_errorcallback to also pass along thefsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".
Nice.
Quoted 8 lines
Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].
Passing the
msg_typeis now redundant, as you can always get it back from themsg_id, but I'm not changing that convention. It's really common to need themsg_type, and thereport()function itself (which calls "fsck_error") needs to callfsck_msg_type()to discover it. Let's not needlessly re-do that work in the user callback.
PATCH v4 18/22 fsck.c: add an fsck_set_msg_type() API that takes enums
In reply to Ævar Arnfjörð BjarmasonChange code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data.
For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler.
--- builtin/mktag.c | 3 ++- fsck.c | 27 +++++++++++++++++---------- fsck.h | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-)
builtin/mktag.c +2 -1
@@ -93,7 +93,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)die_errno (_ ("could not read from stdin" )); fsck_options.error_func = mktag_fsck_error_func; -fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" ); +fsck_set_msg_type_from_ids (&fsck_options,FSCK_MSG_EXTRA_HEADER_ENTRY , +FSCK_WARN );/* config might set fsck.extraHeaderEntry=* again */ git_config (mktag_config,NULL ); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
fsck.c +17 -10
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)return 1 ; } +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type) +{ +if (!options->msg_type) { +int i; +enum fsck_msg_type *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; + } + + options->msg_type[msg_id] = msg_type; +} +void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) {
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str); -if (!options->msg_type) { -int i; -enum fsck_msg_type *severity; -ALLOC_ARRAY (severity,FSCK_MSG_MAX ); -for (i =0 ; i <FSCK_MSG_MAX ; i++) - severity[i] =fsck_msg_type (i, options); - options->msg_type = severity; - } - - options->msg_type[msg_id] = msg_type; +fsck_set_msg_type_from_ids (options, msg_id, msg_type); }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +3 -0
@@ -82,6 +82,9 @@ enum fsck_msg_id {struct fsck_options ;struct object ; +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type);void fsck_set_msg_type (struct fsck_options *options,const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 19/22 fsck.c: move gitmodules_{found,done} into fsck_options
In reply to Ævar Arnfjörð BjarmasonMove the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place.
This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first.
--- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 7 ++++++- 3 files changed, 17 insertions(+), 15 deletions(-)
fetch-pack.c +1 -1
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (oid); +register_found_gitmodules (&fo, oid);if (fsck_finish (&fo))die ("fsck failed" ); }
fsck.c +10 -13
@@ -19,9 +19,6 @@#include "credential.h" #include "help.h" -static struct oidset gitmodules_found =OIDSET_INIT ; -static struct oidset gitmodules_done =OIDSET_INIT ; -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,if (is_hfs_dotgitmodules (name) ||is_ntfs_dotgitmodules (name)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid, has_dotgit |=is_ntfs_dotgit (backslash);if (is_ntfs_dotgitmodules (backslash)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,struct fsck_gitmodules_data data;struct config_options config_opts = {0 }; -if (!oidset_contains (&gitmodules_found, oid)) +if (!oidset_contains (&options->gitmodules_found, oid))return 0 ; -oidset_insert (&gitmodules_done, oid); +oidset_insert (&options->gitmodules_done, oid);if (object_on_skiplist (options, oid))return 0 ;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (const struct object_id *oid) +void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) { -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid); }int fsck_finish (struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)struct oidset_iter iter;const struct object_id *oid; -oidset_iter_init (&gitmodules_found, &iter); +oidset_iter_init (&options->gitmodules_found, &iter);while ((oid =oidset_iter_next (&iter))) {enum object_type type;unsigned long size;char *buf; -if (oidset_contains (&gitmodules_done, oid)) +if (oidset_contains (&options->gitmodules_done, oid))continue ; buf =read_object_file (oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options) } -oidset_clear (&gitmodules_found); -oidset_clear (&gitmodules_done); +oidset_clear (&options->gitmodules_found); +oidset_clear (&options->gitmodules_done);return ret; }
fsck.h +6 -1
@@ -118,6 +118,8 @@ struct fsck_options { unsigned strict:1;enum fsck_msg_type *msg_type;struct oidset skiplist; +struct oidset gitmodules_found; +struct oidset gitmodules_done;kh_oid_map_t *object_names; };
@@ -125,6 +127,8 @@ struct fsck_options { .walk = NULL, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .object_names = NULL,#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (const struct object_id *oid); +void register_found_gitmodules (struct fsck_options *options, +const struct object_id *oid);/* * fsck a tag, and pass info about it back to the caller. This is
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 20/22 fetch-pack: don't needlessly copy fsck_options
In reply to Ævar Arnfjörð BjarmasonChange the behavior of the .gitmodules validation added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting up the error_func earlier means that we're relying on the "error_func" not being set in some code in between the two hunks being modified here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is further setup by calling fsck_set_msg_types(), and assigning to do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the fsck_options struct before setting error_func. Let's just do this setup at the top of the function, along with the "walk" assignment.
--- builtin/index-pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
builtin/index-pack.c +3 -7
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; + fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)else close (input_fd); -if (do_fsck_object) { -struct fsck_options fo = fsck_options; - - fo.error_func = print_dangling_gitmodules; -if (fsck_finish (&fo)) -die (_ ("fsck error in pack objects" )); - } +if (do_fsck_object &&fsck_finish (&fsck_options)) +die (_ ("fsck error in pack objects" ));free (objects);strbuf_release (&index_name_buf);
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 21/22 fetch-pack: use file-scope static struct for fsck_options
In reply to Ævar Arnfjörð BjarmasonChange code added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so that we use a file-scoped "static struct fsck_options" instead of defining one in the "fsck_gitmodules_oids()" function.
We use this pattern in all of builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see fetch-pack be the odd one out. One might think that we're using other fsck_options structs in fetch-pack, or doing on fsck twice there, but we're not.
--- fetch-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fetch-pack.c +3 -3
@@ -38,6 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) {struct oidset_iter iter;const struct object_id *oid; -struct fsck_options fo =FSCK_OPTIONS_STRICT ;if (!oidset_size (gitmodules_oids))return ;oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fo, oid); -if (fsck_finish (&fo)) +register_found_gitmodules (&fsck_options, oid); +if (fsck_finish (&fsck_options))die ("fsck failed" ); }
Signature · 1 line
2.31.0.260.g719c683c1d
PATCH v4 22/22 fetch-pack: use new fsck API to printing dangling submodules
In reply to Ævar Arnfjörð BjarmasonRefactor the check added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message.
Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
Add a fsck-cb.c file similar to parse-options-cb.c, the alternative would be to either define this directly in fsck.c as a public API, or to create some library shared by fetch-pack.c ad builtin/index-pack.
I expect that there won't be many of these fsck utility functions in the future, so just having a single fsck-cb.c makes sense.
--- Makefile | 1 + builtin/index-pack.c | 21 +-------------------- fetch-pack.c | 4 ++-- fsck-cb.c | 16 ++++++++++++++++ fsck.c | 5 ----- fsck.h | 22 +++++++++++++++++++--- 6 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 fsck-cb.c
Makefile +1 -0
@@ -882,6 +882,7 @@ LIB_OBJS += fetch-negotiator.o LIB_OBJS += fetch-pack.o LIB_OBJS += fmt-merge-msg.o LIB_OBJS += fsck.o +LIB_OBJS += fsck-cb.o LIB_OBJS += fsmonitor.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o
builtin/index-pack.c +1 -20
@@ -120,7 +120,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static int verbose;static int show_resolving_progress;static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only) } } -static int print_dangling_gitmodules (struct fsck_options *o, -const struct object_id *oid, -enum object_type object_type, -enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, -const char *message) -{ -/* -* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it -* instead of relying on this string check. -*/ -if (starts_with (message,"gitmodulesMissing" )) { -printf ("%s\n" ,oid_to_hex (oid)); -return 0 ; - } -return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); -} -int cmd_index_pack (int argc,const char **argv,const char *prefix) {int i, fix_thin_pack =0 , verify =0 , stat_only =0 , rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
fetch-pack.c +2 -2
@@ -38,7 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fsck_options, oid); +oidset_insert (&fsck_options.gitmodules_found, oid);if (fsck_finish (&fsck_options))die ("fsck failed" ); }
fsck-cb.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "git-compat-util.h" +#include "fsck.h" + +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +}
fsck.c +0 -5
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) -{ -oidset_insert (&options->gitmodules_found, oid); -} -int fsck_finish (struct fsck_options *options) {int ret =0 ;
fsck.h +19 -3
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (struct fsck_options *options, -const struct object_id *oid); -/* * fsck a tag, and pass info about it back to the caller. This is * exposed fsck_object() internals for git-mktag(1).
@@ -204,4 +201,23 @@ const char *fsck_describe_object(struct fsck_options *options,int fsck_config_internal (const char *var,const char *value,void *cb,struct fsck_options *options); +/* +* Initializations for callbacks in fsck-cb.c +*/ +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ + FSCK_OPTIONS_COMMON \ +} + +/* +* Error callbacks in fsck-cb.c +*/ +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message); +#endif
Signature · 1 line
2.31.0.260.g719c683c1d
Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
Quoted 10 lines · Ævar Arnfjörð Bjarmason
Refactor the check added in
5476e1efde(fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against theFSCK_MSG_GITMODULES_MISSINGinstead of parsing the generated message.Let's also replace
register_found_gitmodules()with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
Quoted 6 lines
Add a
fsck-cb.cfile similar toparse-options-cb.c, the alternative would be to either define this directly infsck.cas a public API, or to create some library shared byfetch-pack.cad builtin/index-pack.I expect that there won't be many of these fsck utility functions in the future, so just having a single
fsck-cb.cmakes sense.
I'm not convinced that having a single cb function merits its own file. But, if you expect this pattern to be expanded a couple more times, then I would say it is worth it. Do you have such plans?
Thanks,
-Stolee
Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
Quoted 15 lines · Derrick Stolee
Quoted 14 lines · Ævar Arnfjörð Bjarmason
Refactor the check added in
5476e1efde(fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against theFSCK_MSG_GITMODULES_MISSINGinstead of parsing the generated message.Let's also replace
register_found_gitmodules()with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.Add a
fsck-cb.cfile similar toparse-options-cb.c, the alternative would be to either define this directly infsck.cas a public API, or to create some library shared byfetch-pack.cad builtin/index-pack.
Quoted 7 lines
Quoted 2 lines
I expect that there won't be many of these fsck utility functions in the future, so just having a single
fsck-cb.cmakes sense.I'm not convinced that having a single cb function merits its own file. But, if you expect this pattern to be expanded a couple more times, then I would say it is worth it. Do you have such plans?
Not really, well. Vague ones, but nothing I have even local patches for.
It just seemed odd to stick random callback functions shared by related programs into fsck.h's interface, but I guess with FSCK_OPTIONS_MISSING_GITMODULES I already did that.
Do you suggest just putting it into fsck.c?
Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
Quoted 12 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Derrick Stolee
Quoted 2 lines · Ævar Arnfjörð Bjarmason
I expect that there won't be many of these fsck utility functions in the future, so just having a single
fsck-cb.cmakes sense.I'm not convinced that having a single cb function merits its own file. But, if you expect this pattern to be expanded a couple more times, then I would say it is worth it. Do you have such plans?
Quoted 7 lines
Not really, well. Vague ones, but nothing I have even local patches for.
It just seemed odd to stick random callback functions shared by related programs into fsck.h's interface, but I guess with
FSCK_OPTIONS_MISSING_GITMODULESI already did that.Do you suggest just putting it into
fsck.c?
Yeah, if it is frequently paired with fsck operations, I think it makes the most sense there.
And looking at it again, I'm not sure parse-options-cb.c has a good excuse for being separate from parse-options.c, but that's the current state so I wouldn't change it now.
Thanks,
-Stolee
Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
In reply to Ævar Arnfjörð Bjarmasonbuiltin/index-pack.c static int nr_threads; · line 123
Quoted 10 lines · Ævar Arnfjörð Bjarmason
builtin/index-pack.c +1
-1@@ -120,7 +120,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;
Hmph, I do not think this is a good way to go. Specifically, fsck-cb.c with the definition of what this thing is, and in fsck.h file the normal "options" initializers being defined quite far away from where this is defined, it is hard to see what is different between the normal strict one and MISSING_GITMODULES one.
Rather, it may be far simpler to keep only DEFAULT and STRICT, and override .error_func at runtime in the codepath(s) that needs to, which would make it more clear what is going on. That way, we do not need the split initializers with _ERROR_FUNC, which is another reason why the approach taken by this series is not a good idea (it does not scale---error-func may seem so special to deserve having two sets of macros that use the default one and leave the member unspecified, but it won't stay to be special forever).
IOW,
builtin/index-pack.c int cmd_index_pack(int argc, const char **argv, const char *prefix) · line 1764
Quoted 5 lines
builtin/index-pack.c +0
-1@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules;
I doubt this hunk is an improvement.
Quoted 12 lines
fsck-cb.c new file +6
-0@@ -0,0 +1,16 @@ +#include "git-compat-util.h" +#include "fsck.h" + +int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type,
fsck-cb.c line 16
Quoted 10 lines
fsck-cb.c new file +10
-0+enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) +{ + if (msg_id == FSCK_MSG_GITMODULES_MISSING) { +puts (oid_to_hex (oid )); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +}
As Derrick noticed, I do not know if we want to have a separate file for this single function. Shouldn't it be part of builtin/index-pack.c, or do we want other places to do the same kind of checks?
Thanks.
PATCH v3 1/22 fsck.h: update FSCK_OPTIONS_* for object_name
In reply to Ævar Arnfjörð BjarmasonAdd the object_name member to the initialization macro. This was omitted in 7b35efd734e (fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fsck.h +2 -2
@@ -43,8 +43,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 2/22 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fsck.h +16 -2
@@ -43,8 +43,22 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_DEFAULT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 0, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +} +#define FSCK_OPTIONS_STRICT { \ + .walk = NULL, \ + .error_func = fsck_error_function, \ + .strict = 1, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, \ +}/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 3/22 fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
In reply to Ævar Arnfjörð BjarmasonUse a temporary macro to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in common, and define the two in terms of that macro.
--- fsck.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
fsck.h +4 -12
@@ -43,22 +43,14 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { \ +#define FSCK_OPTIONS_COMMON \ .walk = NULL, \ .error_func = fsck_error_function, \ - .strict = 0, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ - .object_names = NULL, \ -} -#define FSCK_OPTIONS_STRICT { \ - .walk = NULL, \ - .error_func = fsck_error_function, \ - .strict = 1, \ - .msg_type = NULL, \ - .skiplist = OIDSET_INIT, \ - .object_names = NULL, \ -} + .object_names = NULL, +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 4/22 fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
In reply to Ævar Arnfjörð BjarmasonAdd a FSCK_OPTIONS_COMMON_ERROR_FUNC macro for those that would like to use FSCK_OPTIONS_COMMON in their own initialization, but supply their own error functions.
Nothing is being changed to use this yet, but in some subsequent commits we'll make use of this macro.
--- fsck.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fsck.h +6 -3
@@ -45,12 +45,15 @@ struct fsck_options {#define FSCK_OPTIONS_COMMON \ .walk = NULL, \ - .error_func = fsck_error_function, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ .object_names = NULL, -#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON } -#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON } +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ + FSCK_OPTIONS_COMMON \ + .error_func = fsck_error_function + +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 5/22 fsck.h: indent arguments to of fsck_set_msg_type
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 6/22 fsck.h: use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -197,7 +197,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 7/22 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
--- fsck.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 8/22 fsck.c: move definition of msg_id into append_msg_id()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report().
--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fsck.c +3 -2
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 9/22 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fsck.c +8 -8
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 10/22 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
In reply to Ævar Arnfjörð BjarmasonRefactor "if options->msg_type" and other code added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit, only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type() function (also added in 0282f4dced0), which does a similar check for "!options->msg_type". Another minor benefit is getting rid of the style violation of not having braces for the body of the "if".
--- fsck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fsck.c +5 -7
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)static int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; -assert (msg_id >=0 && msg_id <FSCK_MSG_MAX ); -if (options->msg_type) - msg_type = options->msg_type[msg_id]; -else { - msg_type = msg_id_info[msg_id].msg_type; +if (!options->msg_type) { +int msg_type = msg_id_info[msg_id].msg_type; +if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ; +return msg_type; } -return msg_type; +return options->msg_type[msg_id]; }static int parse_msg_type (const char *str)
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 11/22 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks.
Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type.
--- builtin/fsck.c | 2 +- builtin/index-pack.c | 3 ++- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 16 ++++++++++------ 5 files changed, 25 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)static int print_dangling_gitmodules (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {/* * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
builtin/mktag.c +2 -1
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) {assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );if (!options->msg_type) { -int msg_type = msg_id_info[msg_id].msg_type; +enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;if (options->strict && msg_type ==FSCK_WARN ) msg_type =FSCK_ERROR ;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return options->msg_type[msg_id]; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *severity; +enum fsck_msg_type *severity;ALLOC_ARRAY (severity,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) severity[i] =fsck_msg_type (i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -6
@@ -3,9 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 12/22 fsck.h: re-order and re-assign "enum fsck_msg_type"
In reply to Ævar Arnfjörð BjarmasonChange the values in the "enum fsck_msg_type" from being manually assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously defined as "2".
I'm confident that nothing relies on these values, we always compare them explicitly. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for not simply splitting these into two enums, namely that this is used for both the private and public fsck API.
--- fsck.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fsck.h +6 -4
@@ -4,11 +4,13 @@#include "oidset.h" enum fsck_msg_type { -FSCK_INFO =-2 , -FSCK_FATAL =-1 , -FSCK_ERROR =1 , +/* for internal use only */ +FSCK_IGNORE , +FSCK_INFO , +FSCK_FATAL , +/* "public", fed to e.g. error_func callbacks */ +FSCK_ERROR ,FSCK_WARN , -FSCK_IGNORE };struct fsck_options ;
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 13/22 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 14/22 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 15/22 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 16/22 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
In reply to Ævar Arnfjörð BjarmasonMove the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument.
--- fsck.c | 66 ---------------------------------------------------------- fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-)
fsck.c +0 -66
@@ -22,72 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_FSCK_MSG_ID (FUNC ) \ -/* fatal errors */ \ - FUNC(NUL_IN_HEADER, FATAL) \ - FUNC(UNTERMINATED_HEADER, FATAL) \ -/* errors */ \ - FUNC(BAD_DATE, ERROR) \ - FUNC(BAD_DATE_OVERFLOW, ERROR) \ - FUNC(BAD_EMAIL, ERROR) \ - FUNC(BAD_NAME, ERROR) \ - FUNC(BAD_OBJECT_SHA1, ERROR) \ - FUNC(BAD_PARENT_SHA1, ERROR) \ - FUNC(BAD_TAG_OBJECT, ERROR) \ - FUNC(BAD_TIMEZONE, ERROR) \ - FUNC(BAD_TREE, ERROR) \ - FUNC(BAD_TREE_SHA1, ERROR) \ - FUNC(BAD_TYPE, ERROR) \ - FUNC(DUPLICATE_ENTRIES, ERROR) \ - FUNC(MISSING_AUTHOR, ERROR) \ - FUNC(MISSING_COMMITTER, ERROR) \ - FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_TAG, ERROR) \ - FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TREE, ERROR) \ - FUNC(MISSING_TREE_OBJECT, ERROR) \ - FUNC(MISSING_TYPE, ERROR) \ - FUNC(MISSING_TYPE_ENTRY, ERROR) \ - FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TREE_NOT_SORTED, ERROR) \ - FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(ZERO_PADDED_DATE, ERROR) \ - FUNC(GITMODULES_MISSING, ERROR) \ - FUNC(GITMODULES_BLOB, ERROR) \ - FUNC(GITMODULES_LARGE, ERROR) \ - FUNC(GITMODULES_NAME, ERROR) \ - FUNC(GITMODULES_SYMLINK, ERROR) \ - FUNC(GITMODULES_URL, ERROR) \ - FUNC(GITMODULES_PATH, ERROR) \ -FUNC (GITMODULES_UPDATE ,ERROR ) \ - /* warnings */ \ - FUNC(BAD_FILEMODE, WARN) \ - FUNC(EMPTY_NAME, WARN) \ - FUNC(FULL_PATHNAME, WARN) \ - FUNC(HAS_DOT, WARN) \ - FUNC(HAS_DOTDOT, WARN) \ - FUNC(HAS_DOTGIT, WARN) \ - FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) \ -FUNC (NUL_IN_COMMIT ,WARN ) \ - /* infos (reported as warnings, but ignored by default) */ \ - FUNC(GITMODULES_PARSE, INFO) \ - FUNC(BAD_TAG_NAME, INFO) \ -FUNC (MISSING_TAGGER_ENTRY ,INFO ) \ - /* ignored (elevated when requested) */ \ - FUNC(EXTRA_HEADER_ENTRY, IGNORE) - -#define MSG_ID (id, msg_type) FSCK_MSG_##id, -enum fsck_msg_id { - FOREACH_FSCK_MSG_ID(MSG_ID) -FSCK_MSG_MAX -}; -#undef MSG_ID -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
fsck.h +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 17/22 fsck.c: pass along the fsck_msg_id in the fsck_error callback
In reply to Ævar Arnfjörð BjarmasonChange the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/[email protected]/
--- builtin/fsck.c | 4 +++- builtin/index-pack.c | 3 ++- builtin/mktag.c | 1 + fsck.c | 6 ++++-- fsck.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-)
builtin/fsck.c +3 -1
@@ -89,7 +89,9 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/index-pack.c +2 -1
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) {/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,printf ("%s\n" ,oid_to_hex (oid));return 0 ; } -return fsck_error_function (o, oid, object_type, msg_type, message); +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); }int cmd_index_pack (int argc,const char **argv,const char *prefix)
builtin/mktag.c +1 -0
@@ -23,6 +23,7 @@ static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { switch (msg_type) {
fsck.c +4 -2
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (options, oid, object_type, - msg_type, sb.buf); + msg_type, msg_id, sb.buf);strbuf_release (&sb);va_end (ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message) +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +4 -2
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_type msg_type,const char *message); +enum fsck_msg_type msg_type,enum fsck_msg_id msg_id, +const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 18/22 fsck.c: add an fsck_set_msg_type() API that takes enums
In reply to Ævar Arnfjörð BjarmasonChange code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data.
For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler.
--- builtin/mktag.c | 3 ++- fsck.c | 27 +++++++++++++++++---------- fsck.h | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-)
builtin/mktag.c +2 -1
@@ -93,7 +93,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)die_errno (_ ("could not read from stdin" )); fsck_options.error_func = mktag_fsck_error_func; -fsck_set_msg_type (&fsck_options,"extraheaderentry" ,"warn" ); +fsck_set_msg_type_from_ids (&fsck_options,FSCK_MSG_EXTRA_HEADER_ENTRY , +FSCK_WARN );/* config might set fsck.extraHeaderEntry=* again */ git_config (mktag_config,NULL ); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
fsck.c +17 -10
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)return 1 ; } +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type) +{ +if (!options->msg_type) { +int i; +enum fsck_msg_type *severity; +ALLOC_ARRAY (severity,FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + severity[i] =fsck_msg_type (i, options); + options->msg_type = severity; + } + + options->msg_type[msg_id] = msg_type; +} +void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) {
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str); -if (!options->msg_type) { -int i; -enum fsck_msg_type *severity; -ALLOC_ARRAY (severity,FSCK_MSG_MAX ); -for (i =0 ; i <FSCK_MSG_MAX ; i++) - severity[i] =fsck_msg_type (i, options); - options->msg_type = severity; - } - - options->msg_type[msg_id] = msg_type; +fsck_set_msg_type_from_ids (options, msg_id, msg_type); }void fsck_set_msg_types (struct fsck_options *options,const char *values)
fsck.h +3 -0
@@ -82,6 +82,9 @@ enum fsck_msg_id {struct fsck_options ;struct object ; +void fsck_set_msg_type_from_ids (struct fsck_options *options, +enum fsck_msg_id msg_id, +enum fsck_msg_type msg_type);void fsck_set_msg_type (struct fsck_options *options,const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 19/22 fsck.c: move gitmodules_{found,done} into fsck_options
In reply to Ævar Arnfjörð BjarmasonMove the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place.
This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first.
--- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 7 ++++++- 3 files changed, 17 insertions(+), 15 deletions(-)
fetch-pack.c +1 -1
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (oid); +register_found_gitmodules (&fo, oid);if (fsck_finish (&fo))die ("fsck failed" ); }
fsck.c +10 -13
@@ -19,9 +19,6 @@#include "credential.h" #include "help.h" -static struct oidset gitmodules_found =OIDSET_INIT ; -static struct oidset gitmodules_done =OIDSET_INIT ; -#define STR (x) #x#define MSG_ID (id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,if (is_hfs_dotgitmodules (name) ||is_ntfs_dotgitmodules (name)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid, has_dotgit |=is_ntfs_dotgit (backslash);if (is_ntfs_dotgitmodules (backslash)) {if (!S_ISLNK (mode)) -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid);else retval += report(options, oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,struct fsck_gitmodules_data data;struct config_options config_opts = {0 }; -if (!oidset_contains (&gitmodules_found, oid)) +if (!oidset_contains (&options->gitmodules_found, oid))return 0 ; -oidset_insert (&gitmodules_done, oid); +oidset_insert (&options->gitmodules_done, oid);if (object_on_skiplist (options, oid))return 0 ;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (const struct object_id *oid) +void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) { -oidset_insert (&gitmodules_found, oid); +oidset_insert (&options->gitmodules_found, oid); }int fsck_finish (struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)struct oidset_iter iter;const struct object_id *oid; -oidset_iter_init (&gitmodules_found, &iter); +oidset_iter_init (&options->gitmodules_found, &iter);while ((oid =oidset_iter_next (&iter))) {enum object_type type;unsigned long size;char *buf; -if (oidset_contains (&gitmodules_done, oid)) +if (oidset_contains (&options->gitmodules_done, oid))continue ; buf =read_object_file (oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options) } -oidset_clear (&gitmodules_found); -oidset_clear (&gitmodules_done); +oidset_clear (&options->gitmodules_found); +oidset_clear (&options->gitmodules_done);return ret; }
fsck.h +6 -1
@@ -118,6 +118,8 @@ struct fsck_options { unsigned strict:1;enum fsck_msg_type *msg_type;struct oidset skiplist; +struct oidset gitmodules_found; +struct oidset gitmodules_done;kh_oid_map_t *object_names; };
@@ -125,6 +127,8 @@ struct fsck_options { .walk = NULL, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .object_names = NULL,#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (const struct object_id *oid); +void register_found_gitmodules (struct fsck_options *options, +const struct object_id *oid);/* * fsck a tag, and pass info about it back to the caller. This is
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 20/22 fetch-pack: don't needlessly copy fsck_options
In reply to Ævar Arnfjörð BjarmasonChange the behavior of the .gitmodules validation added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting up the error_func earlier means that we're relying on the "error_func" not being set in some code in between the two hunks being modified here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is further setup by calling fsck_set_msg_types(), and assigning to do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the fsck_options struct before setting error_func. Let's just do this setup at the top of the function, along with the "walk" assignment.
--- builtin/index-pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
builtin/index-pack.c +3 -7
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; + fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)else close (input_fd); -if (do_fsck_object) { -struct fsck_options fo = fsck_options; - - fo.error_func = print_dangling_gitmodules; -if (fsck_finish (&fo)) -die (_ ("fsck error in pack objects" )); - } +if (do_fsck_object &&fsck_finish (&fsck_options)) +die (_ ("fsck error in pack objects" ));free (objects);strbuf_release (&index_name_buf);
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 21/22 fetch-pack: use file-scope static struct for fsck_options
In reply to Ævar Arnfjörð BjarmasonChange code added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so that we use a file-scoped "static struct fsck_options" instead of defining one in the "fsck_gitmodules_oids()" function.
We use this pattern in all of builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see fetch-pack be the odd one out. One might think that we're using other fsck_options structs in fetch-pack, or doing on fsck twice there, but we're not.
--- fetch-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fetch-pack.c +3 -3
@@ -38,6 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) {struct oidset_iter iter;const struct object_id *oid; -struct fsck_options fo =FSCK_OPTIONS_STRICT ;if (!oidset_size (gitmodules_oids))return ;oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fo, oid); -if (fsck_finish (&fo)) +register_found_gitmodules (&fsck_options, oid); +if (fsck_finish (&fsck_options))die ("fsck failed" ); }
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v3 22/22 fetch-pack: use new fsck API to printing dangling submodules
In reply to Ævar Arnfjörð BjarmasonRefactor the check added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message.
Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here.
Add a fsck-cb.c file similar to parse-options-cb.c, the alternative would be to either define this directly in fsck.c as a public API, or to create some library shared by fetch-pack.c ad builtin/index-pack.
I expect that there won't be many of these fsck utility functions in the future, so just having a single fsck-cb.c makes sense.
--- Makefile | 1 + builtin/index-pack.c | 21 +-------------------- fetch-pack.c | 4 ++-- fsck-cb.c | 16 ++++++++++++++++ fsck.c | 5 ----- fsck.h | 22 +++++++++++++++++++--- 6 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 fsck-cb.c
Makefile +1 -0
@@ -879,6 +879,7 @@ LIB_OBJS += fetch-negotiator.o LIB_OBJS += fetch-pack.o LIB_OBJS += fmt-merge-msg.o LIB_OBJS += fsck.o +LIB_OBJS += fsck-cb.o LIB_OBJS += fsmonitor.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o
builtin/index-pack.c +1 -20
@@ -120,7 +120,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static int verbose;static int show_resolving_progress;static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only) } } -static int print_dangling_gitmodules (struct fsck_options *o, -const struct object_id *oid, -enum object_type object_type, -enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, -const char *message) -{ -/* -* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it -* instead of relying on this string check. -*/ -if (starts_with (message,"gitmodulesMissing" )) { -printf ("%s\n" ,oid_to_hex (oid)); -return 0 ; - } -return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); -} -int cmd_index_pack (int argc,const char **argv,const char *prefix) {int i, fix_thin_pack =0 , verify =0 , stat_only =0 , rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs =0 ; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules;reset_pack_idx_option (&opts);git_config (git_index_pack_config, &opts);
fetch-pack.c +2 -2
@@ -38,7 +38,7 @@ static int server_supports_filtering;static int advertise_sid;static struct shallow_lock shallow_lock;static const char *alternate_shallow_file; -static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; +static struct fsck_options fsck_options =FSCK_OPTIONS_MISSING_GITMODULES ;static struct strbuf fsck_msg_types =STRBUF_INIT ;static struct string_list uri_protocols =STRING_LIST_INIT_DUP ;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)oidset_iter_init (gitmodules_oids, &iter);while ((oid =oidset_iter_next (&iter))) -register_found_gitmodules (&fsck_options, oid); +oidset_insert (&fsck_options.gitmodules_found, oid);if (fsck_finish (&fsck_options))die ("fsck failed" ); }
fsck-cb.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "git-compat-util.h" +#include "fsck.h" + +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message) +{ +if (msg_id ==FSCK_MSG_GITMODULES_MISSING ) { +puts (oid_to_hex (oid)); +return 0 ; + } +return fsck_error_function (o, oid, object_type, msg_type, msg_id, message); +}
fsck.c +0 -5
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,return 1 ; } -void register_found_gitmodules (struct fsck_options *options,const struct object_id *oid) -{ -oidset_insert (&options->gitmodules_found, oid); -} -int fsck_finish (struct fsck_options *options) {int ret =0 ;
fsck.h +19 -3
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);int fsck_object (struct object *obj,void *data,unsigned long size,struct fsck_options *options); -void register_found_gitmodules (struct fsck_options *options, -const struct object_id *oid); -/* * fsck a tag, and pass info about it back to the caller. This is * exposed fsck_object() internals for git-mktag(1).
@@ -204,4 +201,23 @@ const char *fsck_describe_object(struct fsck_options *options,int fsck_config_internal (const char *var,const char *value,void *cb,struct fsck_options *options); +/* +* Initializations for callbacks in fsck-cb.c +*/ +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ + FSCK_OPTIONS_COMMON \ +} + +/* +* Error callbacks in fsck-cb.c +*/ +int fsck_error_cb_print_missing_gitmodules (struct fsck_options *o, +const struct object_id *oid, +enum object_type object_type, +enum fsck_msg_type msg_type, +enum fsck_msg_id msg_id, +const char *message); +#endif
Signature · 1 line
2.31.0.rc0.126.g04f22c5b82
PATCH v2 9/10 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 09/10] fsck.c: give "FOREACH_MSG_ID" a more specific name
Quoted 4 lines · Ævar Arnfjörð Bjarmason
Rename the
FOREACH_MSG_IDmacro toFOREACH_FSCK_MSG_IDin preparation for moving it over tofsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
The patch to move it is not in this v2 of the series, so arguably this is less interesting. However, I think the resulting code is equally or more readable, so I don't mind it standing on its own.
-Peff
PATCH v2 10/10 fsck.h: update FSCK_OPTIONS_* for object_name
In reply to Ævar Arnfjörð BjarmasonAdd the object_name member to the initialization macro. This was omitted in 7b35efd734e (fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fsck.h +2 -2
@@ -47,8 +47,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH v2 10/10] fsck.h: update FSCK_OPTIONS_* for object_name
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
We're correct either way here, because trailing fields that are not initialized will get the usual zero-initialization. But I don't mind trying to be more complete.
That said, we have embraced designated initializers these days, in which case we usually omit the NULL ones. So perhaps:
#define FSCK_OPTIONS_DEFAULT { \
.walk = fsck_error_function, \
.skiplist = OIDSET_INIT, \
}
#define FSCK_OPTIONS_STRICT { \
.walk = fsck_error_function, \
.skiplist = OIDSET_INIT, \
.strict = 1, \}
would be more readable still?
-Peff
Re: [PATCH v2 10/10] fsck.h: update FSCK_OPTIONS_* for object_name
Quoted 21 lines · Jeff King
Quoted 3 lines · Ævar Arnfjörð Bjarmason
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.We're correct either way here, because trailing fields that are not initialized will get the usual zero-initialization. But I don't mind trying to be more complete.
That said, we have embraced designated initializers these days, in which case we usually omit the NULL ones. So perhaps:
#define FSCK_OPTIONS_DEFAULT { \ .walk = fsck_error_function, \ .skiplist = OIDSET_INIT, \ } #define FSCK_OPTIONS_STRICT { \ .walk = fsck_error_function, \ .skiplist = OIDSET_INIT, \ .strict = 1, \
Quoted 3 lines
}
would be more readable still?
Ahh, I should probably have read your reviews first before reading patches myself ;-)
Thanks.
Re: [PATCH v2 10/10] fsck.h: update FSCK_OPTIONS_* for object_name
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
Add the
object_namemember to the initialization macro. This was omitted in7b35efd734e(fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.
This is more of a Meh to me. If this were to change us to designated initializers and omit NULL and 0 initialization, it would be more interesting.
Thanks.
Quoted 21 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- fsck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fsck.h +2
-2@@ -47,8 +47,8 @@ struct fsck_options {kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }/* descend in all linked child objects * the return value is:
PATCH 1/14 fsck.h: indent arguments to of fsck_set_msg_type
In reply to Ævar Arnfjörð Bjarmason--- fsck.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.h +1 -1
@@ -11,7 +11,7 @@ struct fsck_options;struct object ;void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type); +const char *msg_id,const char *msg_type);void fsck_set_msg_types (struct fsck_options *options,const char *values);int is_valid_msg_type (const char *msg_id,const char *msg_type);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 2/14 fsck.h: use use "enum object_type" instead of "int"
In reply to Ævar Arnfjörð BjarmasonChange the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
builtin/fsck.c +2 -1
@@ -197,7 +197,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;
builtin/unpack-objects.c +2 -1
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
fsck.h +2 -1
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
Re: [PATCH 02/14] fsck.h: use use "enum object_type" instead of "int"
Quoted 1 line · Ævar Arnfjörð Bjarmason
Subject: Re: [PATCH 02/14]
fsck.h: use use "enumobject_type" instead of "int"
use use.
Quoted 8 lines
Change the
fsck_walk_functo use an "enumobject_type" instead of an "int" type. The types are compatible, and ever since this was added in355885d5315(add generic, type aware object chain walker, 2008-02-25) we've used entries fromobject_type(OBJ_BLOBetc.).So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read.
Yup, as long as we won't trick the compiler into complaining "ah, but you are not covering OBJ_OFS_DELTA or OBJ_BAD values in your switch statement", I think a change like this is a good thing.
Quoted 64 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)builtin/fsck.c +2
-1@@ -197,7 +197,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_used (struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options) {if (!obj)return 1 ;builtin/index-pack.c +2
-1@@ -212,7 +212,8 @@ static void cleanup_thread(void)free (thread_data); } -static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) +static int mark_link (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {if (!obj)return -1 ;builtin/unpack-objects.c +2
-1@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) +static int check_object (struct object *obj,enum object_type type, +void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;fsck.h +2
-1@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options); +typedef int (*fsck_walk_func )(struct object *obj,enum object_type object_type, +void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o,
PATCH 3/14 fsck.c: rename variables in fsck_set_msg_type() for less confusion
In reply to Ævar Arnfjörð BjarmasonRename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type.
Let's rename that to "tmp", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller.
--- fsck.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fsck.c +12 -12
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) }void fsck_set_msg_type (struct fsck_options *options, -const char *msg_id,const char *msg_type) +const char *msg_id_str,const char *msg_type_str) { -int id =parse_msg_id (msg_id), type; +int msg_id =parse_msg_id (msg_id_str), msg_type; -if (id <0 ) -die ("Unhandled message id: %s" , msg_id); - type =parse_msg_type (msg_type); +if (msg_id <0 ) +die ("Unhandled message id: %s" , msg_id_str); + msg_type =parse_msg_type (msg_type_str); -if (type !=FSCK_ERROR && msg_id_info[id].msg_type ==FSCK_FATAL ) -die ("Cannot demote %s to %s" , msg_id, msg_type); +if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL ) +die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);if (!options->msg_type) {int i; -int *msg_type; -ALLOC_ARRAY (msg_type,FSCK_MSG_MAX ); +int *tmp; +ALLOC_ARRAY (tmp,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) - msg_type[i] =fsck_msg_type (i, options); - options->msg_type = msg_type; + tmp[i] =fsck_msg_type (i, options); + options->msg_type = tmp; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; }void fsck_set_msg_types (struct fsck_options *options,const char *values)
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 4/14 fsck.c: move definition of msg_id into append_msg_id()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report().
--- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fsck.c +3 -2
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,const char *msg_id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) { +const char *msg_id = msg_id_info[id].id_string;for (;;) {char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, msg_id_info[id].id_string); +append_msg_id (&sb, id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 5/14 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
In reply to Ævar Arnfjörð BjarmasonRename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function.
--- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fsck.c +8 -8
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)free (to_free); } -static void append_msg_id (struct strbuf *sb,enum fsck_msg_id id) +static void append_msg_id (struct strbuf *sb,enum fsck_msg_id msg_id) { -const char *msg_id = msg_id_info[id].id_string; +const char *msg_id_str = msg_id_info[msg_id].id_string;for (;;) { -char c = *(msg_id)++; +char c = *(msg_id_str)++;if (!c)break ;if (c !='_' )strbuf_addch (sb,tolower (c));else { -assert (*msg_id); -strbuf_addch (sb, *(msg_id)++); +assert (*msg_id_str); +strbuf_addch (sb, *(msg_id_str)++); } }
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __attribute__((format (printf,5 ,6 )))static int report (struct fsck_options *options,const struct object_id *oid,enum object_type object_type, -enum fsck_msg_id id,const char *fmt, ...) +enum fsck_msg_id msg_id,const char *fmt, ...) {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (id, options), result; +int msg_type =fsck_msg_type (msg_id, options), result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,else if (msg_type ==FSCK_INFO ) msg_type =FSCK_WARN ; -append_msg_id (&sb, id); +append_msg_id (&sb, msg_id);va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 6/14 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
In reply to Ævar Arnfjörð BjarmasonMove the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22)
--- builtin/fsck.c | 2 +- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 17 ++++++++++------- 4 files changed, 23 insertions(+), 20 deletions(-)
builtin/fsck.c +1 -1
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)static int fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {switch (msg_type) {case FSCK_WARN :
builtin/mktag.c +2 -1
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)static int mktag_fsck_error_func (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type, +const char *message) {switch (msg_type) {case FSCK_WARN :
fsck.c +10 -11
@@ -22,9 +22,6 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 -#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {const char *id_string;const char *downcased;const char *camelcased; -int msg_type; +enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = {FOREACH_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 }
@@ -164,10 +161,10 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)list_config_item (list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type (enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { -int msg_type; +enum fsck_msg_type msg_type;assert (msg_id >=0 && msg_id <FSCK_MSG_MAX );
@@ -182,7 +179,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,return msg_type; } -static int parse_msg_type (const char *str) +static enum fsck_msg_type parse_msg_type (const char *str) {if (!strcmp (str,"error" ))return FSCK_ERROR ;
@@ -205,7 +202,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)void fsck_set_msg_type (struct fsck_options *options,const char *msg_id_str,const char *msg_type_str) { -int msg_id =parse_msg_id (msg_id_str), msg_type; +int msg_id =parse_msg_id (msg_id_str); +enum fsck_msg_type msg_type;if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str);
@@ -216,7 +214,7 @@ void fsck_set_msg_type(struct fsck_options *options,if (!options->msg_type) {int i; -int *tmp; +enum fsck_msg_type *tmp;ALLOC_ARRAY (tmp,FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) tmp[i] =fsck_msg_type (i, options);
@@ -296,7 +294,8 @@ static int report(struct fsck_options *options, {va_list ap;struct strbuf sb =STRBUF_INIT ; -int msg_type =fsck_msg_type (msg_id, options), result; +enum fsck_msg_type msg_type =fsck_msg_type (msg_id, options); +int result;if (msg_type ==FSCK_IGNORE )return 0 ;
@@ -1262,7 +1261,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message) +enum fsck_msg_type msg_type,const char *message) {if (msg_type ==FSCK_WARN ) {warning ("object %s: %s" ,fsck_describe_object (o, oid), message);
fsck.h +10 -7
@@ -3,10 +3,13 @@#include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 - +enum fsck_msg_type { +FSCK_INFO =-2 , +FSCK_FATAL =-1 , +FSCK_ERROR =1 , +FSCK_WARN , +FSCK_IGNORE +};struct fsck_options ;struct object ;
@@ -29,17 +32,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);int fsck_error_function (struct fsck_options *o,const struct object_id *oid,enum object_type object_type, -int msg_type,const char *message); +enum fsck_msg_type msg_type,const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func;unsigned strict:1 ; -int *msg_type; +enum fsck_msg_type *msg_type;struct oidset skiplist;kh_oid_map_t *object_names; };
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 7/14 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
In reply to Ævar Arnfjörð BjarmasonThere's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input.
--- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck.c +1 -2
@@ -203,11 +203,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); -enum fsck_msg_type msg_type; +enum fsck_msg_type msg_type =parse_msg_type (msg_type_str);if (msg_id <0 )die ("Unhandled message id: %s" , msg_id_str); - msg_type =parse_msg_type (msg_type_str);if (msg_type !=FSCK_ERROR && msg_id_info[msg_id].msg_type ==FSCK_FATAL )die ("Cannot demote %s to %s" , msg_id_str, msg_type_str);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 8/14 fsck.c: undefine temporary STR macro after use
In reply to Ævar Arnfjörð BjarmasonIn f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22).
--- fsck.c | 1 + 1 file changed, 1 insertion(+)
fsck.c +1 -0
@@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } };#undef MSG_ID +#undef STRstatic void prepare_msg_ids (void ) {
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
PATCH 9/14 fsck.c: give "FOREACH_MSG_ID" a more specific name
In reply to Ævar Arnfjörð BjarmasonRename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files.
--- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fsck.c +3 -3
@@ -22,7 +22,7 @@static struct oidset gitmodules_found =OIDSET_INIT ;static struct oidset gitmodules_done =OIDSET_INIT ; -#define FOREACH_MSG_ID (FUNC ) \ +#define FOREACH_FSCK_MSG_ID (FUNC ) \/* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;#define MSG_ID (id, msg_type) FSCK_MSG_##id,enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID)FSCK_MSG_MAX };#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {const char *camelcased;enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { -FOREACH_MSG_ID (MSG_ID ) +FOREACH_FSCK_MSG_ID (MSG_ID ) { NULL, NULL, NULL, -1 } };#undef MSG_ID
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7