* Re: [git-for-windows] Re: Continuous Testing of Git on Windows
From: Philip Oakley @ 2017-02-18 11:49 UTC (permalink / raw)
To: Junio C Hamano
Cc: Johannes Schindelin, Christian Couder, git-for-windows, git
In-Reply-To: <xmqq60kb0ywi.fsf@gitster.mtv.corp.google.com>
From: "Junio C Hamano" <gitster@pobox.com>
Sent: Thursday, February 16, 2017 12:20 AM
> "Philip Oakley" <philipoakley@iee.org> writes:
>
>> It may even be worth 'splitting' the pu branch sequence into the
>> existing pu (with merges from series that are selected as reasonable),
>> and then a pr branch (public review?) on top of that holding the rest
>> of the series that have been submitted, so that the CI can do a full
>> test on the tips of them to support those devs with limited test
>> capability.
>
> I won't stop you from publishing such a pr branch yourself.
But would others see it?... (rhetorical, better thoughts below))
>
> For patches whose merit is not clear because the problem they try to
> solve is under-explained, whose solution is ill-designed, etc., IOW,
> with issues that makes me judge that they are not interesting enough
> for 'pu',
It is reasonble that that a project's integrator is able to make these
decisions. For some projects they may have a layered approach of descisions
which does allow the gradations for the submitted feature series.
Some of this does fall into dscho's differentiation between those patch
series that should pass the CI (continuous integration) testing, and those
that are there for CT (continuous testing) feedback. This could either be an
extra branch marking the transition, or a named commit similar to the
"pu^{/^### match next}", etc. In some ways it is similar to my 'pr'
suggestion, without the inclusion of the 'all and sundry' series.
For for integrators who are willing/want to recieve any/all contributions
for public view (usually those for projects of a more lenient and less
critical variety), then even the CT grouping could then have those
additional pr submissions. For Git, you provide that that 'voice of reason'
for gatekeeping the pu branch.
> it is not worth my time to deal with whitespace brekages
> in them to make them not even apply, to figure out what base the
> patches are meant to apply to, or to resolve conflicts caused by
> them with topics already in flight, etc.
>
If a centralised CT service was available to the project, maybe via the
GitHub PR process (which isn't curently used by the project) then is may be
a way of allowing the 'all and sundry' contributors to get their ideas upto
a basic level before even bothering yourself (because PRs do not trouble
you).
It may need an extra gatekeeper between the passing patches (PRs) and auto
submission (the Heroku script thingy) which could flood the list with with
inane changes - one only has to look at the
http://stackoverflow.com/questions/tagged/git stream to see that.
At least if there was a break point within pu that allowed differentiation
between the series that should fit a CI view, and those that are still at
the CT stage, then that may help.
Thanks
Philip.
^ permalink raw reply
* Re: Git bisect does not find commit introducing the bug
From: Alex Hoffman @ 2017-02-18 11:15 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Stephan Beyer, git
In-Reply-To: <3ff5ce3c-285f-cb9a-d1d4-46323524dab7@kdbg.org>
>> First of all this is confusing, as this commit cannot be reached
>> starting from "v.good".
> Hm, IMHO it shows that your example is pretty artificial (although you
> might have come across it in a real-world scenario): you introduced a
> new feature in f4154e9 (and it worked) and you broke that feature by
> making the merge 671cec2. However, the feature (that broke in 671cec2)
> did not even exist in 04c6f4b; so a test on the feature would not fail
> (leading to "bisect bad" as in the example), it would not exist (leading
> to "bisect skip").
No one commented the fact, that I find this very confusing. Don't you
find this confusing? I will underline, that 'git bisect good v.good'
will fail if the commit 'v.good' is not a parent of the bad commit,
meaning there MUST be at least a path between 'v.good' and 'v.bad',
thus I would expect it looks on this path ONLY. Beside that, this is
what I understand by 'binary search' (to search on this commit path).
You might find this example artificial, but I doubt git is/was
intentionally designed to work with 'natural' examples only (no
matter how you define 'natural' and 'artificial').
>> In other words: bisect assumes that your repo is usually in a good state
>> and you have a commit that changes it to a bad state. In your case you
>> have a repo that is in a bad state and you have a commit that switches
>> it to a good state and later you merge a bad-state branch and you have a
>> bad state again. It is not made for that use-case, I think.
> Correct. The assumption of bisection is that there is only one transition between GOOD and BAD. By violating that assumption, anything can happen.
I did not find that in the manpage or did I miss it? Why would someone
assume that the commit graph looks in a certain way? I assume, that
'git bisect' was not thought through and that it considers the first
directed path between v.good and v.bad, instead of all paths (in my
example graph there are two such paths). I will also underline that
git bisect was designed to work with multiple good commits and one bad
commit (also multiple paths), but probably NOT with multiple paths
between the same pair of good and bad commits.
VG
2017-02-18 10:12 GMT+01:00 Johannes Sixt <j6t@kdbg.org>:
> Am 18.02.2017 um 00:21 schrieb Stephan Beyer:
>>
>> On 02/17/2017 11:29 PM, Alex Hoffman wrote:
>> * 7a9e952 (bisect bad) <BAD>
>> |\
>> | * 671cec2 <BAD> <--- expected
>> | |\
>> | * | 04c6f4b <BAD> <--- found
>> * | | 3915157 <GOOD>
>> |\ \ \
>> | | |/
>> | |/|
>> | * | f4154e9 (bisect good) <GOOD>
>> | * | 85855bf <BAD>
>> | |/
>> * | f1a36f5 <BAD>
>> |/
>> * 1b7fb88 <BAD>
>>
>> The <BAD> and <GOOD> markers are set by your definition of what good and
>> what bad commits are.
>>
>> [...]
>> In other words: bisect assumes that your repo is usually in a good state
>> and you have a commit that changes it to a bad state. In your case you
>> have a repo that is in a bad state and you have a commit that switches
>> it to a good state and later you merge a bad-state branch and you have a
>> bad state again. It is not made for that use-case, I think.
>
>
> Correct. The assumption of bisection is that there is only one transition
> between GOOD and BAD. By violating that assumption, anything can happen.
>
> -- Hannes
>
^ permalink raw reply
* Re: Git bisect does not find commit introducing the bug
From: Johannes Sixt @ 2017-02-18 9:12 UTC (permalink / raw)
To: Alex Hoffman; +Cc: Stephan Beyer, git
In-Reply-To: <d4991e4b-cbc4-da14-381a-88704e457a19@gmx.net>
Am 18.02.2017 um 00:21 schrieb Stephan Beyer:
> On 02/17/2017 11:29 PM, Alex Hoffman wrote:
> * 7a9e952 (bisect bad) <BAD>
> |\
> | * 671cec2 <BAD> <--- expected
> | |\
> | * | 04c6f4b <BAD> <--- found
> * | | 3915157 <GOOD>
> |\ \ \
> | | |/
> | |/|
> | * | f4154e9 (bisect good) <GOOD>
> | * | 85855bf <BAD>
> | |/
> * | f1a36f5 <BAD>
> |/
> * 1b7fb88 <BAD>
>
> The <BAD> and <GOOD> markers are set by your definition of what good and
> what bad commits are.
>
> [...]
> In other words: bisect assumes that your repo is usually in a good state
> and you have a commit that changes it to a bad state. In your case you
> have a repo that is in a bad state and you have a commit that switches
> it to a good state and later you merge a bad-state branch and you have a
> bad state again. It is not made for that use-case, I think.
Correct. The assumption of bisection is that there is only one
transition between GOOD and BAD. By violating that assumption, anything
can happen.
-- Hannes
^ permalink raw reply
* Re: git alias for options
From: Jeff King @ 2017-02-18 6:33 UTC (permalink / raw)
To: hIpPy
Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason,
Git Mailing List
In-Reply-To: <CAM_JFCzoouREM5-6aq9wb0ouT34GKCoJ_pcsww5TYKAdztR9sA@mail.gmail.com>
On Fri, Feb 17, 2017 at 02:34:15PM -0800, hIpPy wrote:
> I think the conversation has drifted away from what I am asking / hoping for.
Yeah, the usual answer to "can we have custom options" is "use a custom
alias". But I agree they are not quite the same thing.
> Say I want an alias for option --name-status as -s, so I can type:
> $ git log -s
>
> But there is already a -s option and that wins so the built-in option
> alias wins.
>
> However, I think I should be able alias it as --ns.
> $ git log --ns
To be honest, I am not that enthused about the idea, but I don't have an
real objection beyond "meh, that looks like an unnecessary
complication".
If anybody wants to pursue it, the simplest way would probably be to
teach parse-options to take a callback for an unknown option, which
could then do a config lookup to transmute the argument into another
option-name.
Though many of the options (notably the revision-walker and diff ones)
are not handled by parse-options. So that might present a challenge.
-Peff
^ permalink raw reply
* Re: [PATCH 0/5] A series of performance enhancements in the memihash and name-cache area
From: Jeff King @ 2017-02-18 6:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff Hostetler, Johannes Schindelin, git, Jeff Hostetler
In-Reply-To: <xmqqo9y0m45e.fsf@gitster.mtv.corp.google.com>
On Fri, Feb 17, 2017 at 09:58:21PM -0800, Junio C Hamano wrote:
> Jeff Hostetler <git@jeffhostetler.com> writes:
>
> > I'll try to put together a before/after perf-test to better
> > demonstrate this.
>
> I didn't pick up the series while watching these exchanges, as I
> didn't know how quick your turnaround would be, but now a few days
> have passed. Just to make sure we won't forget this topic, I'll
> pick up these 5 patches in the meantime.
Yeah, to be clear my question was not an objection, but mostly
curiosity and interest.
-Peff
^ permalink raw reply
* Re: [PATCH 0/5] A series of performance enhancements in the memihash and name-cache area
From: Junio C Hamano @ 2017-02-18 5:58 UTC (permalink / raw)
To: Jeff Hostetler; +Cc: Jeff King, Johannes Schindelin, git, Jeff Hostetler
In-Reply-To: <16b1259c-4cdc-8f4d-db47-d724386a3d2b@jeffhostetler.com>
Jeff Hostetler <git@jeffhostetler.com> writes:
> I'll try to put together a before/after perf-test to better
> demonstrate this.
I didn't pick up the series while watching these exchanges, as I
didn't know how quick your turnaround would be, but now a few days
have passed. Just to make sure we won't forget this topic, I'll
pick up these 5 patches in the meantime.
Thanks.
^ permalink raw reply
* Re: [PATCH 0/5] A series of performance enhancements in the memihash and name-cache area
From: Junio C Hamano @ 2017-02-18 5:56 UTC (permalink / raw)
To: Jeff King; +Cc: Jeff Hostetler, Johannes Schindelin, git, Jeff Hostetler
In-Reply-To: <20170215164416.tekykkzhm6qlj2h2@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> On Wed, Feb 15, 2017 at 09:27:53AM -0500, Jeff Hostetler wrote:
>
>> I have some informal numbers in a spreadsheet. I was seeing
>> a 8-9% speed up on a status on my gigantic repo.
>>
>> I'll try to put together a before/after perf-test to better
>> demonstrate this.
>
> Thanks. What I'm mostly curious about is how much each individual step
> buys. Sometimes when doing a long optimization series, I find that some
> of the optimizations make other ones somewhat redundant (e.g., if patch
> 2 causes us to call the optimized code from patch 3 less often).
I am curious too.
To me 1/5 (reduction of redundant calls), 4/5 (correctly size the
hash that would grow to a known size anyway) and 5/5 (take advantage
of the fact that adjacent cache entries are often in the same
directory) look like no brainers to take, regardless of the others
(including themselves).
It is not clear to me if 3/5 (preload-index uses available cores to
compute hashes) is an unconditional win (an operation that is
pathspec limited may need hashes for only a small fraction of the
index---would it still be a win to compute the hash for all entries
upon loading the index, even if we are using otherwise-idel cores?).
Of course 2/5 is a prerequisite step for 3/5 and 5/5, so if we want
either of the latter two, we cannot avoid it.
^ permalink raw reply
* Re: [PATCH 3/5] name-hash: precompute hash values during preload-index
From: Junio C Hamano @ 2017-02-18 5:47 UTC (permalink / raw)
To: Jeff Hostetler; +Cc: git, Johannes Schindelin
In-Reply-To: <8621305c69898e012720d4fe66d42b096f053073.1487071883.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> +void precompute_istate_hashes(struct cache_entry *ce)
> +{
> + int namelen = ce_namelen(ce);
> +
> + while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
> + namelen--;
> +
> + if (namelen <= 0) {
> + ce->precomputed_hash.name = memihash(ce->name, ce_namelen(ce));
> + ce->precomputed_hash.root_entry = 1;
> + } else {
> + namelen--;
> + ce->precomputed_hash.dir = memihash(ce->name, namelen);
> + ce->precomputed_hash.name = memihash_continue(
> + ce->precomputed_hash.dir, ce->name + namelen,
> + ce_namelen(ce) - namelen);
> + ce->precomputed_hash.root_entry = 0;
> + }
> + ce->precomputed_hash.initialized = 1;
> +}
> diff --git a/preload-index.c b/preload-index.c
> index c1fe3a3ef9c..602737f9d0f 100644
> --- a/preload-index.c
> +++ b/preload-index.c
> @@ -47,6 +47,8 @@ static void *preload_thread(void *_data)
> struct cache_entry *ce = *cep++;
> struct stat st;
>
> + precompute_istate_hashes(ce);
> +
The fact that each preload_thread() still walks the index in-order
makes me wonder if it may allow us to further optimize the "dir"
part of the hash by passing the previous ce for which we already
precomputed hash values. While the loop is iterating over the paths
in the same directory, .dir component from the previous ce can be
reused and .name component can "continue", no?
It's possible that you already tried such an optimization and
rejected it after finding that the cost of comparison of pathnames
to tell if ce and previous ce are still in the same directory is
more than unconditionally memihash() the directory part, and I am in
no way saying that I found a missed optimization opportunity you
must pursue. I am just being curious.
^ permalink raw reply
* Re: [PATCH 2/5] hashmap: allow memihash computation to be continued
From: Junio C Hamano @ 2017-02-18 5:35 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Jeff Hostetler
In-Reply-To: <bd4893f86c4484fc36480848bf2d0905d961e022.1487071883.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> diff --git a/hashmap.c b/hashmap.c
> index b10b642229c..061b7d61da6 100644
> --- a/hashmap.c
> +++ b/hashmap.c
> @@ -50,6 +50,20 @@ unsigned int memihash(const void *buf, size_t len)
> return hash;
> }
>
> +/* Incoporate another chunk of data into a memihash computation. */
> +unsigned int memihash_continue(unsigned int hash,
> + const void *buf, size_t len)
> +{
> + const unsigned char *p = buf;
> + while (len--) {
> + unsigned int c = *p++;
> + if (c >= 'a' && c <= 'z')
> + c -= 'a' - 'A';
> + hash = (hash * FNV32_PRIME) ^ c;
> + }
> + return hash;
> +}
This makes me wonder if we want to reduce the duplication (primarily
to avoid risking the loop body to go out of sync) by doing:
unsigned int memihash(const void *buf, size_t len)
{
return memihash_continue(buf, len, FNV32_BASE);
}
If an extra call level really matters, its "inline" equivalent in
the header would probably be good.
^ permalink raw reply
* Re: [RFC PATCH] show decorations at the end of the line
From: Junio C Hamano @ 2017-02-18 5:27 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Git Mailing List, Jeff King
In-Reply-To: <20170215002901.gtzegvhyy7d6cvrb@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
>> The updates to the expectation look like this (already squashed).
>> The --source decorations in 4202 are also shown at the end, which
>> probably is in line with the way --show-decorations adds them at the
>> end of the line, but was somewhat surprising from reading only the
>> log message.
>
> Hrm, that does surprise me. I'm not sure if that's desirable or not. I
> do think some of the "nobody could possibly be parsing these" arguments
> about decorations do not apply to --source (and also, they're harder for
> humans to pick out from the end of the line as they lack punctuation and
> color).
I just got bitten by a fallout. I have
$ git recent --help
`git recent' is aliased to `log --oneline --branches --no-merges \
--source --since=3.weeks'
and often do
$ git recent name-hash.c
primarily to see if I already queued a patch series to a topic (and
forgot about it), and/or what other recent topics in flight touch
the same thing.
I'd need that the topic name to be shown rather prominently for this
use case, i.e.
eb2263adb1 jh/memihash-opt name-hash: remember previous dir_...
0c04267dc8 jh/memihash-opt name-hash: specify initial size f...
57463ce445 jh/memihash-opt name-hash: precompute hash values...
dd3170e2cf jh/memihash-opt name-hash: eliminate duplicate me...
but now the branch names are shown at the end, which defeats the
whole point of the alias.
If nobody gets around to fixing it, I may take a look at it when
able, but for now let me just vent^Wreport a regression first.
^ permalink raw reply
* Re: [PATCH v3 02/19] builtin/diff-tree: convert to struct object_id
From: Jeff King @ 2017-02-18 3:15 UTC (permalink / raw)
To: brian m. carlson, Ramsay Jones, git, Michael Haggerty,
Junio C Hamano
In-Reply-To: <20170218014217.sil4jyukkbqguxfz@sigill.intra.peff.net>
On Fri, Feb 17, 2017 at 08:42:17PM -0500, Jeff King wrote:
> > I'm wondering if parse_oid_hex could be useful here as well.
>
> I know I haven't looked at this chunk nearly as carefully as you have,
> but it seems somewhat crazy to me that these functions get the original
> "line" in the first place. Shouldn't they get line+40 from the caller
> (who in turn should be using parse_oid_hex to compute that)?
>
> And then each function should subsequently parse left-to-right with
> a mix of isspace() and parse_oid_hex(), and probably doesn't even need
> to care about the original "len" at all (yes, you can quit early if you
> know your len isn't long enough, but that's the unusual error case
> anyway; it's not a big deal to find that out while parsing).
>
> In general, I think this sort of left-to-right incremental pointer
> movement is safe and simple. There may be a few cases where it doesn't
> apply (i.e., where you need to look at the end of the string to know how
> to parse the beginning), but that should be relatively rare.
So for this case, something like the patch below.
Incidentally, there's an off-by-one in the original loop of
stdin_diff_commit that reads past the end of the trailing NUL for the
final sha1 on the line. The problem is the:
pos += GIT_SHA1_HEXSZ + 1;
which assumes we're slurping up the trailing space. This works in
practice because the caller will only permit a string which had a
newline (which it converted into a NUL).
I suspect that function could be more aggressive about complaining about
nonsense on the line, rather than silently ignoring it.
builtin/diff-tree.c | 43 ++++++++++++++++-------------------
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 1f1573bb2..222c671f2 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -16,37 +16,33 @@ static int diff_tree_commit_sha1(const struct object_id *oid)
}
/* Diff one or more commits. */
-static int stdin_diff_commit(struct commit *commit, char *line, int len)
+static int stdin_diff_commit(struct commit *commit, const char *p)
{
struct object_id oid;
- if (isspace(line[GIT_SHA1_HEXSZ]) && !get_oid_hex(line+GIT_SHA1_HEXSZ+1, &oid)) {
- /* Graft the fake parents locally to the commit */
- int pos = GIT_SHA1_HEXSZ + 1;
- struct commit_list **pptr;
-
- /* Free the real parent list */
- free_commit_list(commit->parents);
- commit->parents = NULL;
- pptr = &(commit->parents);
- while (line[pos] && !get_oid_hex(line + pos, &oid)) {
- struct commit *parent = lookup_commit(oid.hash);
- if (parent) {
- pptr = &commit_list_insert(parent, pptr)->next;
- }
- pos += GIT_SHA1_HEXSZ + 1;
+ struct commit_list **pptr = NULL;
+
+ /* Graft the fake parents locally to the commit */
+ while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
+ struct commit *parent = lookup_commit(oid.hash);
+ if (!pptr) {
+ /* Free the real parent list */
+ free_commit_list(commit->parents);
+ commit->parents = NULL;
+ pptr = &(commit->parents);
+ }
+ if (parent) {
+ pptr = &commit_list_insert(parent, pptr)->next;
}
}
return log_tree_commit(&log_tree_opt, commit);
}
/* Diff two trees. */
-static int stdin_diff_trees(struct tree *tree1, char *line, int len)
+static int stdin_diff_trees(struct tree *tree1, const char *p)
{
struct object_id oid;
struct tree *tree2;
- const int chunksz = GIT_SHA1_HEXSZ + 1;
- if (len != 2 * chunksz || !isspace(line[chunksz-1]) ||
- get_sha1_hex(line + chunksz, oid.hash))
+ if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
return error("Need exactly two trees, separated by a space");
tree2 = lookup_tree(oid.hash);
if (!tree2 || parse_tree(tree2))
@@ -64,19 +60,20 @@ static int diff_tree_stdin(char *line)
int len = strlen(line);
struct object_id oid;
struct object *obj;
+ const char *rest;
if (!len || line[len-1] != '\n')
return -1;
line[len-1] = 0;
- if (get_oid_hex(line, &oid))
+ if (parse_oid_hex(line, &oid, &rest))
return -1;
obj = parse_object(oid.hash);
if (!obj)
return -1;
if (obj->type == OBJ_COMMIT)
- return stdin_diff_commit((struct commit *)obj, line, len);
+ return stdin_diff_commit((struct commit *)obj, rest);
if (obj->type == OBJ_TREE)
- return stdin_diff_trees((struct tree *)obj, line, len);
+ return stdin_diff_trees((struct tree *)obj, rest);
error("Object %s is a %s, not a commit or tree",
oid_to_hex(&oid), typename(obj->type));
return -1;
^ permalink raw reply related
* Re: [PATCH v3 02/19] builtin/diff-tree: convert to struct object_id
From: Jeff King @ 2017-02-18 1:42 UTC (permalink / raw)
To: brian m. carlson, Ramsay Jones, git, Michael Haggerty,
Junio C Hamano
In-Reply-To: <20170218012607.kdisudmmponvts35@genre.crustytoothpaste.net>
On Sat, Feb 18, 2017 at 01:26:07AM +0000, brian m. carlson wrote:
> > > + struct object_id oid;
> > > struct tree *tree2;
> > > - if (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))
> > > + const int chunksz = GIT_SHA1_HEXSZ + 1;
> > > + if (len != 2 * chunksz || !isspace(line[chunksz-1]) ||
> > > + get_sha1_hex(line + chunksz, oid.hash))
> >
> > I'm not sure that this is an improvement. The input expected in 'line'
> > is supposed to look like: '<sha1> + <space> + <sha1> + <\n>'. So your
> > 'chunk' would be a <sha1> plus one 'char' of some sort. Except that the
> > caller of this function has already replaced the newline character with
> > a '\0' char (so strlen(line) would return 81), but still passes the
> > original line length! Also, note that this (and other functions in this
> > file) actually test for 'isspace(char)' rather than for a ' ' char!
> >
> > Hmm, maybe just:
> >
> > if (len < (2 * GIT_SHA1_HEXSZ + 1) || line[GIT_SHA1_HEXSZ] != ' ' ||
> > get_sha1_hex(line + GIT_SHA1_HEXSZ + 1, oid.hash))
> >
> > (or, perhaps, still call isspace() in this patch ...)
>
> Well, I think it's strictly an improvement in that we have avoided
> writing hardcoded constants[0]. I did intend it as a "hash plus one"
> chunk, which is actually quite common throughout the code.
>
> I'm wondering if parse_oid_hex could be useful here as well.
I know I haven't looked at this chunk nearly as carefully as you have,
but it seems somewhat crazy to me that these functions get the original
"line" in the first place. Shouldn't they get line+40 from the caller
(who in turn should be using parse_oid_hex to compute that)?
And then each function should subsequently parse left-to-right with
a mix of isspace() and parse_oid_hex(), and probably doesn't even need
to care about the original "len" at all (yes, you can quit early if you
know your len isn't long enough, but that's the unusual error case
anyway; it's not a big deal to find that out while parsing).
In general, I think this sort of left-to-right incremental pointer
movement is safe and simple. There may be a few cases where it doesn't
apply (i.e., where you need to look at the end of the string to know how
to parse the beginning), but that should be relatively rare.
> [0] If we change the hash size, all of the GIT_SHA1_HEXSZ constants can
> be replaced with a variable that varies based on hash size, and the code
> still works.
I am happy to see fewer magic numbers. But I think with incremental
pointer-movements, we don't even need to use the numeric constants,
either. If one day we can parse "sha256:1234abcd..." as an oid, then the
existing code would "just work".
-Peff
^ permalink raw reply
* Re: [PATCH v3 16/19] sha1_file: introduce an nth_packed_object_oid function
From: brian m. carlson @ 2017-02-18 1:29 UTC (permalink / raw)
To: Ramsay Jones; +Cc: git, Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <fc5aff14-a047-1a51-c40c-8918098f1f59@ramsayjones.plus.com>
[-- Attachment #1: Type: text/plain, Size: 2122 bytes --]
On Sat, Feb 18, 2017 at 01:24:34AM +0000, Ramsay Jones wrote:
>
>
> On 18/02/17 00:06, brian m. carlson wrote:
> > There are places in the code where we would like to provide a struct
> > object_id *, yet read the hash directly from the pack. Provide an
> > nth_packed_object_oid function that is similar to the
> > nth_packed_object_sha1 function.
> >
> > In order to avoid a potentially invalid cast, nth_packed_object_oid
> > provides a variable into which to store the value, which it returns on
> > success; on error, it returns NULL, as nth_packed_object_sha1 does.
> >
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> > ---
> > cache.h | 6 ++++++
> > sha1_file.c | 17 ++++++++++++++---
> > 2 files changed, 20 insertions(+), 3 deletions(-)
> >
> > diff --git a/cache.h b/cache.h
> > index e03a672d15..4f3bfc5ee7 100644
> > --- a/cache.h
> > +++ b/cache.h
> > @@ -1608,6 +1608,12 @@ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
> > * error.
> > */
> > extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
> > +/*
> > + * Like nth_packed_object_oid, but write the data into the object specified by
> ^^^
> ... Like nth_packed_object_sha1, but ...
Good catch.
> Having said that, if the intent is to eventually replace that function with
> the new nth_packed_object_oid(), then it is probably not a good idea to
> describe this function in terms of the function it will obsolete. ;-)
I've chosen to define them that way for now, in the hopes that it will
make them easier to use (as people are already familiar with the _sha1
version). When I remove nth_packed_object_sha1 eventually, I'll update
the docstring so that the oid version is standalone. I think I've
already done that somewhere else before (although it may be in a patch
that I haven't sent yet).
--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply
* Re: [PATCH v3 02/19] builtin/diff-tree: convert to struct object_id
From: brian m. carlson @ 2017-02-18 1:26 UTC (permalink / raw)
To: Ramsay Jones; +Cc: git, Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <3630da01-5af3-bc02-3a8c-1e3495512279@ramsayjones.plus.com>
[-- Attachment #1: Type: text/plain, Size: 4181 bytes --]
On Sat, Feb 18, 2017 at 01:18:11AM +0000, Ramsay Jones wrote:
>
>
> On 18/02/17 00:06, brian m. carlson wrote:
> > Convert most leaf functions to struct object_id. Rewrite several
> > hardcoded numbers in terms of GIT_SHA1_HEXSZ, using an intermediate
> > variable where that makes sense.
> >
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> > ---
> > builtin/diff-tree.c | 38 ++++++++++++++++++++------------------
> > 1 file changed, 20 insertions(+), 18 deletions(-)
> >
> > diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> > index 8ce00480cd..1f1573bb2a 100644
> > --- a/builtin/diff-tree.c
> > +++ b/builtin/diff-tree.c
> > @@ -7,9 +7,9 @@
> >
> > static struct rev_info log_tree_opt;
> >
> > -static int diff_tree_commit_sha1(const unsigned char *sha1)
> > +static int diff_tree_commit_sha1(const struct object_id *oid)
> > {
> > - struct commit *commit = lookup_commit_reference(sha1);
> > + struct commit *commit = lookup_commit_reference(oid->hash);
> > if (!commit)
> > return -1;
> > return log_tree_commit(&log_tree_opt, commit);
> > @@ -18,22 +18,22 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)
> > /* Diff one or more commits. */
> > static int stdin_diff_commit(struct commit *commit, char *line, int len)
> > {
> > - unsigned char sha1[20];
> > - if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
> > + struct object_id oid;
> > + if (isspace(line[GIT_SHA1_HEXSZ]) && !get_oid_hex(line+GIT_SHA1_HEXSZ+1, &oid)) {
> > /* Graft the fake parents locally to the commit */
> > - int pos = 41;
> > + int pos = GIT_SHA1_HEXSZ + 1;
> > struct commit_list **pptr;
> >
> > /* Free the real parent list */
> > free_commit_list(commit->parents);
> > commit->parents = NULL;
> > pptr = &(commit->parents);
> > - while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
> > - struct commit *parent = lookup_commit(sha1);
> > + while (line[pos] && !get_oid_hex(line + pos, &oid)) {
> > + struct commit *parent = lookup_commit(oid.hash);
> > if (parent) {
> > pptr = &commit_list_insert(parent, pptr)->next;
> > }
> > - pos += 41;
> > + pos += GIT_SHA1_HEXSZ + 1;
> > }
> > }
> > return log_tree_commit(&log_tree_opt, commit);
> > @@ -42,11 +42,13 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)
> > /* Diff two trees. */
> > static int stdin_diff_trees(struct tree *tree1, char *line, int len)
> > {
> > - unsigned char sha1[20];
> > + struct object_id oid;
> > struct tree *tree2;
> > - if (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))
> > + const int chunksz = GIT_SHA1_HEXSZ + 1;
> > + if (len != 2 * chunksz || !isspace(line[chunksz-1]) ||
> > + get_sha1_hex(line + chunksz, oid.hash))
>
> I'm not sure that this is an improvement. The input expected in 'line'
> is supposed to look like: '<sha1> + <space> + <sha1> + <\n>'. So your
> 'chunk' would be a <sha1> plus one 'char' of some sort. Except that the
> caller of this function has already replaced the newline character with
> a '\0' char (so strlen(line) would return 81), but still passes the
> original line length! Also, note that this (and other functions in this
> file) actually test for 'isspace(char)' rather than for a ' ' char!
>
> Hmm, maybe just:
>
> if (len < (2 * GIT_SHA1_HEXSZ + 1) || line[GIT_SHA1_HEXSZ] != ' ' ||
> get_sha1_hex(line + GIT_SHA1_HEXSZ + 1, oid.hash))
>
> (or, perhaps, still call isspace() in this patch ...)
Well, I think it's strictly an improvement in that we have avoided
writing hardcoded constants[0]. I did intend it as a "hash plus one"
chunk, which is actually quite common throughout the code.
I'm wondering if parse_oid_hex could be useful here as well.
[0] If we change the hash size, all of the GIT_SHA1_HEXSZ constants can
be replaced with a variable that varies based on hash size, and the code
still works.
--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply
* Re: [PATCH v3 16/19] sha1_file: introduce an nth_packed_object_oid function
From: Ramsay Jones @ 2017-02-18 1:24 UTC (permalink / raw)
To: brian m. carlson, git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-17-sandals@crustytoothpaste.net>
On 18/02/17 00:06, brian m. carlson wrote:
> There are places in the code where we would like to provide a struct
> object_id *, yet read the hash directly from the pack. Provide an
> nth_packed_object_oid function that is similar to the
> nth_packed_object_sha1 function.
>
> In order to avoid a potentially invalid cast, nth_packed_object_oid
> provides a variable into which to store the value, which it returns on
> success; on error, it returns NULL, as nth_packed_object_sha1 does.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> cache.h | 6 ++++++
> sha1_file.c | 17 ++++++++++++++---
> 2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index e03a672d15..4f3bfc5ee7 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -1608,6 +1608,12 @@ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
> * error.
> */
> extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
> +/*
> + * Like nth_packed_object_oid, but write the data into the object specified by
^^^
... Like nth_packed_object_sha1, but ...
Having said that, if the intent is to eventually replace that function with
the new nth_packed_object_oid(), then it is probably not a good idea to
describe this function in terms of the function it will obsolete. ;-)
ATB,
Ramsay Jones
> + * the the first argument. Returns the first argument on success, and NULL on
> + * error.
> + */
> +extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
>
> /*
> * Return the offset of the nth object within the specified packfile.
> diff --git a/sha1_file.c b/sha1_file.c
> index ec957db5e1..777b8e8eae 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -2628,6 +2628,17 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,
> }
> }
>
> +const struct object_id *nth_packed_object_oid(struct object_id *oid,
> + struct packed_git *p,
> + uint32_t n)
> +{
> + const unsigned char *hash = nth_packed_object_sha1(p, n);
> + if (!hash)
> + return NULL;
> + hashcpy(oid->hash, hash);
> + return oid;
> +}
> +
> void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
> {
> const unsigned char *ptr = vptr;
> @@ -3788,13 +3799,13 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
> int r = 0;
>
> for (i = 0; i < p->num_objects; i++) {
> - const unsigned char *sha1 = nth_packed_object_sha1(p, i);
> + struct object_id oid;
>
> - if (!sha1)
> + if (!nth_packed_object_oid(&oid, p, i))
> return error("unable to get sha1 of object %u in %s",
> i, p->pack_name);
>
> - r = cb(sha1, p, i, data);
> + r = cb(oid.hash, p, i, data);
> if (r)
> break;
> }
>
^ permalink raw reply
* Re: [PATCH v3 02/19] builtin/diff-tree: convert to struct object_id
From: Ramsay Jones @ 2017-02-18 1:18 UTC (permalink / raw)
To: brian m. carlson, git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-3-sandals@crustytoothpaste.net>
On 18/02/17 00:06, brian m. carlson wrote:
> Convert most leaf functions to struct object_id. Rewrite several
> hardcoded numbers in terms of GIT_SHA1_HEXSZ, using an intermediate
> variable where that makes sense.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> builtin/diff-tree.c | 38 ++++++++++++++++++++------------------
> 1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> index 8ce00480cd..1f1573bb2a 100644
> --- a/builtin/diff-tree.c
> +++ b/builtin/diff-tree.c
> @@ -7,9 +7,9 @@
>
> static struct rev_info log_tree_opt;
>
> -static int diff_tree_commit_sha1(const unsigned char *sha1)
> +static int diff_tree_commit_sha1(const struct object_id *oid)
> {
> - struct commit *commit = lookup_commit_reference(sha1);
> + struct commit *commit = lookup_commit_reference(oid->hash);
> if (!commit)
> return -1;
> return log_tree_commit(&log_tree_opt, commit);
> @@ -18,22 +18,22 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)
> /* Diff one or more commits. */
> static int stdin_diff_commit(struct commit *commit, char *line, int len)
> {
> - unsigned char sha1[20];
> - if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
> + struct object_id oid;
> + if (isspace(line[GIT_SHA1_HEXSZ]) && !get_oid_hex(line+GIT_SHA1_HEXSZ+1, &oid)) {
> /* Graft the fake parents locally to the commit */
> - int pos = 41;
> + int pos = GIT_SHA1_HEXSZ + 1;
> struct commit_list **pptr;
>
> /* Free the real parent list */
> free_commit_list(commit->parents);
> commit->parents = NULL;
> pptr = &(commit->parents);
> - while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
> - struct commit *parent = lookup_commit(sha1);
> + while (line[pos] && !get_oid_hex(line + pos, &oid)) {
> + struct commit *parent = lookup_commit(oid.hash);
> if (parent) {
> pptr = &commit_list_insert(parent, pptr)->next;
> }
> - pos += 41;
> + pos += GIT_SHA1_HEXSZ + 1;
> }
> }
> return log_tree_commit(&log_tree_opt, commit);
> @@ -42,11 +42,13 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)
> /* Diff two trees. */
> static int stdin_diff_trees(struct tree *tree1, char *line, int len)
> {
> - unsigned char sha1[20];
> + struct object_id oid;
> struct tree *tree2;
> - if (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))
> + const int chunksz = GIT_SHA1_HEXSZ + 1;
> + if (len != 2 * chunksz || !isspace(line[chunksz-1]) ||
> + get_sha1_hex(line + chunksz, oid.hash))
I'm not sure that this is an improvement. The input expected in 'line'
is supposed to look like: '<sha1> + <space> + <sha1> + <\n>'. So your
'chunk' would be a <sha1> plus one 'char' of some sort. Except that the
caller of this function has already replaced the newline character with
a '\0' char (so strlen(line) would return 81), but still passes the
original line length! Also, note that this (and other functions in this
file) actually test for 'isspace(char)' rather than for a ' ' char!
Hmm, maybe just:
if (len < (2 * GIT_SHA1_HEXSZ + 1) || line[GIT_SHA1_HEXSZ] != ' ' ||
get_sha1_hex(line + GIT_SHA1_HEXSZ + 1, oid.hash))
(or, perhaps, still call isspace() in this patch ...)
ATB,
Ramsay Jones
> return error("Need exactly two trees, separated by a space");
> - tree2 = lookup_tree(sha1);
> + tree2 = lookup_tree(oid.hash);
> if (!tree2 || parse_tree(tree2))
> return -1;
> printf("%s %s\n", oid_to_hex(&tree1->object.oid),
> @@ -60,15 +62,15 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)
> static int diff_tree_stdin(char *line)
> {
> int len = strlen(line);
> - unsigned char sha1[20];
> + struct object_id oid;
> struct object *obj;
>
> if (!len || line[len-1] != '\n')
> return -1;
> line[len-1] = 0;
> - if (get_sha1_hex(line, sha1))
> + if (get_oid_hex(line, &oid))
> return -1;
> - obj = parse_object(sha1);
> + obj = parse_object(oid.hash);
> if (!obj)
> return -1;
> if (obj->type == OBJ_COMMIT)
> @@ -76,7 +78,7 @@ static int diff_tree_stdin(char *line)
> if (obj->type == OBJ_TREE)
> return stdin_diff_trees((struct tree *)obj, line, len);
> error("Object %s is a %s, not a commit or tree",
> - sha1_to_hex(sha1), typename(obj->type));
> + oid_to_hex(&oid), typename(obj->type));
> return -1;
> }
>
> @@ -141,7 +143,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
> break;
> case 1:
> tree1 = opt->pending.objects[0].item;
> - diff_tree_commit_sha1(tree1->oid.hash);
> + diff_tree_commit_sha1(&tree1->oid);
> break;
> case 2:
> tree1 = opt->pending.objects[0].item;
> @@ -164,9 +166,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
> opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
> DIFF_SETUP_USE_CACHE);
> while (fgets(line, sizeof(line), stdin)) {
> - unsigned char sha1[20];
> + struct object_id oid;
>
> - if (get_sha1_hex(line, sha1)) {
> + if (get_oid_hex(line, &oid)) {
> fputs(line, stdout);
> fflush(stdout);
> }
>
^ permalink raw reply
* [PATCH] remote: Ignore failure to remove missing branch.<name>.merge
From: Ross Lagerwall @ 2017-02-18 0:23 UTC (permalink / raw)
To: git; +Cc: Ross Lagerwall
If a branch is configured with a default remote but no
branch.<name>.merge and then the remote is removed, git fails to remove
the remote with:
"fatal: could not unset 'branch.<name>.merge'"
Instead, ignore this since it is not an error and shouldn't prevent the
remote from being removed.
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
---
builtin/remote.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index e52cf3925..5dd22c2eb 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -769,7 +769,9 @@ static int rm(int argc, const char **argv)
strbuf_reset(&buf);
strbuf_addf(&buf, "branch.%s.%s",
item->string, *k);
- git_config_set(buf.buf, NULL);
+ result = git_config_set_gently(buf.buf, NULL);
+ if (result && result != CONFIG_NOTHING_SET)
+ die(_("COULd not unset '%s'"), buf.buf);
}
}
}
--
2.11.0
^ permalink raw reply related
* [PATCH v3 09/19] builtin/merge: convert to struct object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
Additionally convert several uses of the constant 40 into
GIT_SHA1_HEXSZ.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
builtin/merge.c | 134 ++++++++++++++++++++++++++++----------------------------
1 file changed, 66 insertions(+), 68 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index a96d4fb501..099cfab447 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -244,7 +244,7 @@ static void drop_save(void)
unlink(git_path_merge_mode());
}
-static int save_state(unsigned char *stash)
+static int save_state(struct object_id *stash)
{
int len;
struct child_process cp = CHILD_PROCESS_INIT;
@@ -265,7 +265,7 @@ static int save_state(unsigned char *stash)
else if (!len) /* no changes */
return -1;
strbuf_setlen(&buffer, buffer.len-1);
- if (get_sha1(buffer.buf, stash))
+ if (get_oid(buffer.buf, stash))
die(_("not a valid object: %s"), buffer.buf);
return 0;
}
@@ -305,18 +305,18 @@ static void reset_hard(unsigned const char *sha1, int verbose)
die(_("read-tree failed"));
}
-static void restore_state(const unsigned char *head,
- const unsigned char *stash)
+static void restore_state(const struct object_id *head,
+ const struct object_id *stash)
{
struct strbuf sb = STRBUF_INIT;
const char *args[] = { "stash", "apply", NULL, NULL };
- if (is_null_sha1(stash))
+ if (is_null_oid(stash))
return;
- reset_hard(head, 1);
+ reset_hard(head->hash, 1);
- args[2] = sha1_to_hex(stash);
+ args[2] = oid_to_hex(stash);
/*
* It is OK to ignore error here, for example when there was
@@ -376,10 +376,10 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
static void finish(struct commit *head_commit,
struct commit_list *remoteheads,
- const unsigned char *new_head, const char *msg)
+ const struct object_id *new_head, const char *msg)
{
struct strbuf reflog_message = STRBUF_INIT;
- const unsigned char *head = head_commit->object.oid.hash;
+ const struct object_id *head = &head_commit->object.oid;
if (!msg)
strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
@@ -397,7 +397,7 @@ static void finish(struct commit *head_commit,
else {
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
update_ref(reflog_message.buf, "HEAD",
- new_head, head, 0,
+ new_head->hash, head->hash, 0,
UPDATE_REFS_DIE_ON_ERR);
/*
* We ignore errors in 'gc --auto', since the
@@ -416,7 +416,7 @@ static void finish(struct commit *head_commit,
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
opts.detect_rename = DIFF_DETECT_RENAME;
diff_setup_done(&opts);
- diff_tree_sha1(head, new_head, "", &opts);
+ diff_tree_sha1(head->hash, new_head->hash, "", &opts);
diffcore_std(&opts);
diff_flush(&opts);
}
@@ -431,7 +431,7 @@ static void finish(struct commit *head_commit,
static void merge_name(const char *remote, struct strbuf *msg)
{
struct commit *remote_head;
- unsigned char branch_head[20];
+ struct object_id branch_head;
struct strbuf buf = STRBUF_INIT;
struct strbuf bname = STRBUF_INIT;
const char *ptr;
@@ -441,25 +441,25 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote);
remote = bname.buf;
- memset(branch_head, 0, sizeof(branch_head));
+ oidclr(&branch_head);
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
- if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {
+ if (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {
if (starts_with(found_ref, "refs/heads/")) {
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
- sha1_to_hex(branch_head), remote);
+ oid_to_hex(&branch_head), remote);
goto cleanup;
}
if (starts_with(found_ref, "refs/tags/")) {
strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
- sha1_to_hex(branch_head), remote);
+ oid_to_hex(&branch_head), remote);
goto cleanup;
}
if (starts_with(found_ref, "refs/remotes/")) {
strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n",
- sha1_to_hex(branch_head), remote);
+ oid_to_hex(&branch_head), remote);
goto cleanup;
}
}
@@ -590,8 +590,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return git_diff_ui_config(k, v, cb);
}
-static int read_tree_trivial(unsigned char *common, unsigned char *head,
- unsigned char *one)
+static int read_tree_trivial(struct object_id *common, struct object_id *head,
+ struct object_id *one)
{
int i, nr_trees = 0;
struct tree *trees[MAX_UNPACK_TREES];
@@ -606,13 +606,13 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,
opts.verbose_update = 1;
opts.trivial_merges_only = 1;
opts.merge = 1;
- trees[nr_trees] = parse_tree_indirect(common);
+ trees[nr_trees] = parse_tree_indirect(common->hash);
if (!trees[nr_trees++])
return -1;
- trees[nr_trees] = parse_tree_indirect(head);
+ trees[nr_trees] = parse_tree_indirect(head->hash);
if (!trees[nr_trees++])
return -1;
- trees[nr_trees] = parse_tree_indirect(one);
+ trees[nr_trees] = parse_tree_indirect(one->hash);
if (!trees[nr_trees++])
return -1;
opts.fn = threeway_merge;
@@ -626,9 +626,9 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,
return 0;
}
-static void write_tree_trivial(unsigned char *sha1)
+static void write_tree_trivial(struct object_id *oid)
{
- if (write_cache_as_tree(sha1, 0, NULL))
+ if (write_cache_as_tree(oid->hash, 0, NULL))
die(_("git write-tree failed to write a tree"));
}
@@ -781,7 +781,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
{
- unsigned char result_tree[20], result_commit[20];
+ struct object_id result_tree, result_commit;
struct commit_list *parents, **pptr = &parents;
static struct lock_file lock;
@@ -792,15 +792,15 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
return error(_("Unable to write index."));
rollback_lock_file(&lock);
- write_tree_trivial(result_tree);
+ write_tree_trivial(&result_tree);
printf(_("Wonderful.\n"));
pptr = commit_list_append(head, pptr);
pptr = commit_list_append(remoteheads->item, pptr);
prepare_to_commit(remoteheads);
- if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
- result_commit, NULL, sign_commit))
+ if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,
+ result_commit.hash, NULL, sign_commit))
die(_("failed to write commit object"));
- finish(head, remoteheads, result_commit, "In-index merge");
+ finish(head, remoteheads, &result_commit, "In-index merge");
drop_save();
return 0;
}
@@ -809,12 +809,12 @@ static int finish_automerge(struct commit *head,
int head_subsumed,
struct commit_list *common,
struct commit_list *remoteheads,
- unsigned char *result_tree,
+ struct object_id *result_tree,
const char *wt_strategy)
{
struct commit_list *parents = NULL;
struct strbuf buf = STRBUF_INIT;
- unsigned char result_commit[20];
+ struct object_id result_commit;
free_commit_list(common);
parents = remoteheads;
@@ -822,11 +822,11 @@ static int finish_automerge(struct commit *head,
commit_list_insert(head, &parents);
strbuf_addch(&merge_msg, '\n');
prepare_to_commit(remoteheads);
- if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
- result_commit, NULL, sign_commit))
+ if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,
+ result_commit.hash, NULL, sign_commit))
die(_("failed to write commit object"));
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
- finish(head, remoteheads, result_commit, buf.buf);
+ finish(head, remoteheads, &result_commit, buf.buf);
strbuf_release(&buf);
drop_save();
return 0;
@@ -854,18 +854,18 @@ static int suggest_conflicts(void)
}
static struct commit *is_old_style_invocation(int argc, const char **argv,
- const unsigned char *head)
+ const struct object_id *head)
{
struct commit *second_token = NULL;
if (argc > 2) {
- unsigned char second_sha1[20];
+ struct object_id second_oid;
- if (get_sha1(argv[1], second_sha1))
+ if (get_oid(argv[1], &second_oid))
return NULL;
- second_token = lookup_commit_reference_gently(second_sha1, 0);
+ second_token = lookup_commit_reference_gently(second_oid.hash, 0);
if (!second_token)
die(_("'%s' is not a commit"), argv[1]);
- if (hashcmp(second_token->object.oid.hash, head))
+ if (oidcmp(&second_token->object.oid, head))
return NULL;
}
return second_token;
@@ -1038,7 +1038,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
die_errno(_("could not close '%s'"), filename);
for (pos = 0; pos < merge_names->len; pos = npos) {
- unsigned char sha1[20];
+ struct object_id oid;
char *ptr;
struct commit *commit;
@@ -1048,16 +1048,16 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
else
npos = merge_names->len;
- if (npos - pos < 40 + 2 ||
- get_sha1_hex(merge_names->buf + pos, sha1))
+ if (npos - pos < GIT_SHA1_HEXSZ + 2 ||
+ get_oid_hex(merge_names->buf + pos, &oid))
commit = NULL; /* bad */
- else if (memcmp(merge_names->buf + pos + 40, "\t\t", 2))
+ else if (memcmp(merge_names->buf + pos + GIT_SHA1_HEXSZ, "\t\t", 2))
continue; /* not-for-merge */
else {
- char saved = merge_names->buf[pos + 40];
- merge_names->buf[pos + 40] = '\0';
+ char saved = merge_names->buf[pos + GIT_SHA1_HEXSZ];
+ merge_names->buf[pos + GIT_SHA1_HEXSZ] = '\0';
commit = get_merge_parent(merge_names->buf + pos);
- merge_names->buf[pos + 40] = saved;
+ merge_names->buf[pos + GIT_SHA1_HEXSZ] = saved;
}
if (!commit) {
if (ptr)
@@ -1117,9 +1117,7 @@ static struct commit_list *collect_parents(struct commit *head_commit,
int cmd_merge(int argc, const char **argv, const char *prefix)
{
- unsigned char result_tree[20];
- unsigned char stash[20];
- unsigned char head_sha1[20];
+ struct object_id result_tree, stash, head_oid;
struct commit *head_commit;
struct strbuf buf = STRBUF_INIT;
const char *head_arg;
@@ -1138,13 +1136,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* Check if we are _not_ on a detached HEAD, i.e. if there is a
* current branch.
*/
- branch = branch_to_free = resolve_refdup("HEAD", 0, head_sha1, NULL);
+ branch = branch_to_free = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
if (branch && starts_with(branch, "refs/heads/"))
branch += 11;
- if (!branch || is_null_sha1(head_sha1))
+ if (!branch || is_null_oid(&head_oid))
head_commit = NULL;
else
- head_commit = lookup_commit_or_die(head_sha1, "HEAD");
+ head_commit = lookup_commit_or_die(head_oid.hash, "HEAD");
init_diff_ui_defaults();
git_config(git_merge_config, NULL);
@@ -1242,7 +1240,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* to forbid "git merge" into a branch yet to be born.
* We do the same for "git pull".
*/
- unsigned char *remote_head_sha1;
+ struct object_id *remote_head_oid;
if (squash)
die(_("Squash commit into empty head not supported yet"));
if (fast_forward == FF_NO)
@@ -1254,9 +1252,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
die(_("%s - not something we can merge"), argv[0]);
if (remoteheads->next)
die(_("Can merge only exactly one commit into empty head"));
- remote_head_sha1 = remoteheads->item->object.oid.hash;
- read_empty(remote_head_sha1, 0);
- update_ref("initial pull", "HEAD", remote_head_sha1,
+ remote_head_oid = &remoteheads->item->object.oid;
+ read_empty(remote_head_oid->hash, 0);
+ update_ref("initial pull", "HEAD", remote_head_oid->hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
goto done;
}
@@ -1270,7 +1268,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* additional safety measure to check for it.
*/
if (!have_message &&
- is_old_style_invocation(argc, argv, head_commit->object.oid.hash)) {
+ is_old_style_invocation(argc, argv, &head_commit->object.oid)) {
warning("old-style 'git merge <msg> HEAD <commit>' is deprecated.");
strbuf_addstr(&merge_msg, argv[0]);
head_arg = argv[1];
@@ -1422,7 +1420,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done;
}
- finish(head_commit, remoteheads, commit->object.oid.hash, msg.buf);
+ finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
drop_save();
goto done;
} else if (!remoteheads->next && common->next)
@@ -1441,9 +1439,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
/* See if it is really trivial. */
git_committer_info(IDENT_STRICT);
printf(_("Trying really trivial in-index merge...\n"));
- if (!read_tree_trivial(common->item->object.oid.hash,
- head_commit->object.oid.hash,
- remoteheads->item->object.oid.hash)) {
+ if (!read_tree_trivial(&common->item->object.oid,
+ &head_commit->object.oid,
+ &remoteheads->item->object.oid)) {
ret = merge_trivial(head_commit, remoteheads);
goto done;
}
@@ -1495,14 +1493,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
/*
* Stash away the local changes so that we can try more than one.
*/
- save_state(stash))
- hashclr(stash);
+ save_state(&stash))
+ oidclr(&stash);
for (i = 0; i < use_strategies_nr; i++) {
int ret;
if (i) {
printf(_("Rewinding the tree to pristine...\n"));
- restore_state(head_commit->object.oid.hash, stash);
+ restore_state(&head_commit->object.oid, &stash);
}
if (use_strategies_nr != 1)
printf(_("Trying merge strategy %s...\n"),
@@ -1547,7 +1545,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
/* Automerge succeeded. */
- write_tree_trivial(result_tree);
+ write_tree_trivial(&result_tree);
automerge_was_ok = 1;
break;
}
@@ -1559,7 +1557,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (automerge_was_ok) {
ret = finish_automerge(head_commit, head_subsumed,
common, remoteheads,
- result_tree, wt_strategy);
+ &result_tree, wt_strategy);
goto done;
}
@@ -1568,7 +1566,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* it up.
*/
if (!best_strategy) {
- restore_state(head_commit->object.oid.hash, stash);
+ restore_state(&head_commit->object.oid, &stash);
if (use_strategies_nr > 1)
fprintf(stderr,
_("No merge strategy handled the merge.\n"));
@@ -1581,7 +1579,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
; /* We already have its result in the working tree. */
else {
printf(_("Rewinding the tree to pristine...\n"));
- restore_state(head_commit->object.oid.hash, stash);
+ restore_state(&head_commit->object.oid, &stash);
printf(_("Using the %s to prepare resolving by hand.\n"),
best_strategy);
try_merge_strategy(best_strategy, common, remoteheads,
--
2.11.0
^ permalink raw reply related
* [PATCH v3 10/19] Convert remaining callers of resolve_refdup to object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
There are a few leaf functions in various files that call
resolve_refdup. Convert these functions to use struct object_id
internally to prepare for transitioning resolve_refdup itself.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
builtin/notes.c | 18 +++++++++---------
builtin/receive-pack.c | 4 ++--
ref-filter.c | 4 ++--
reflog-walk.c | 12 ++++++------
transport.c | 4 ++--
wt-status.c | 4 ++--
6 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 5248a9bad8..8c569a49a0 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -693,7 +693,7 @@ static int merge_abort(struct notes_merge_options *o)
static int merge_commit(struct notes_merge_options *o)
{
struct strbuf msg = STRBUF_INIT;
- unsigned char sha1[20], parent_sha1[20];
+ struct object_id oid, parent_oid;
struct notes_tree *t;
struct commit *partial;
struct pretty_print_context pretty_ctx;
@@ -705,27 +705,27 @@ static int merge_commit(struct notes_merge_options *o)
* and target notes ref from .git/NOTES_MERGE_REF.
*/
- if (get_sha1("NOTES_MERGE_PARTIAL", sha1))
+ if (get_oid("NOTES_MERGE_PARTIAL", &oid))
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
- else if (!(partial = lookup_commit_reference(sha1)))
+ else if (!(partial = lookup_commit_reference(oid.hash)))
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
if (partial->parents)
- hashcpy(parent_sha1, partial->parents->item->object.oid.hash);
+ oidcpy(&parent_oid, &partial->parents->item->object.oid);
else
- hashclr(parent_sha1);
+ oidclr(&parent_oid);
t = xcalloc(1, sizeof(struct notes_tree));
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
o->local_ref = local_ref_to_free =
- resolve_refdup("NOTES_MERGE_REF", 0, sha1, NULL);
+ resolve_refdup("NOTES_MERGE_REF", 0, oid.hash, NULL);
if (!o->local_ref)
die(_("failed to resolve NOTES_MERGE_REF"));
- if (notes_merge_commit(o, t, partial, sha1))
+ if (notes_merge_commit(o, t, partial, oid.hash))
die(_("failed to finalize notes merge"));
/* Reuse existing commit message in reflog message */
@@ -733,8 +733,8 @@ static int merge_commit(struct notes_merge_options *o)
format_commit_message(partial, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg);
strbuf_insert(&msg, 0, "notes: ", 7);
- update_ref(msg.buf, o->local_ref, sha1,
- is_null_sha1(parent_sha1) ? NULL : parent_sha1,
+ update_ref(msg.buf, o->local_ref, oid.hash,
+ is_null_oid(&parent_oid) ? NULL : parent_oid.hash,
0, UPDATE_REFS_DIE_ON_ERR);
free_notes(t);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1dbb8a0692..7966f4f4df 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1414,7 +1414,7 @@ static void execute_commands(struct command *commands,
{
struct check_connected_options opt = CHECK_CONNECTED_INIT;
struct command *cmd;
- unsigned char sha1[20];
+ struct object_id oid;
struct iterate_data data;
struct async muxer;
int err_fd = 0;
@@ -1471,7 +1471,7 @@ static void execute_commands(struct command *commands,
check_aliased_updates(commands);
free(head_name_to_free);
- head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL);
+ head_name = head_name_to_free = resolve_refdup("HEAD", 0, oid.hash, NULL);
if (use_atomic)
execute_commands_atomic(commands, si);
diff --git a/ref-filter.c b/ref-filter.c
index 3820b21cc7..f0de30e2ef 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -961,9 +961,9 @@ static void populate_value(struct ref_array_item *ref)
ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
- unsigned char unused1[20];
+ struct object_id unused1;
ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
- unused1, NULL);
+ unused1.hash, NULL);
if (!ref->symref)
ref->symref = "";
}
diff --git a/reflog-walk.c b/reflog-walk.c
index a246af2767..f98748e2ae 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -45,11 +45,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
reflogs->ref = xstrdup(ref);
for_each_reflog_ent(ref, read_one_reflog, reflogs);
if (reflogs->nr == 0) {
- unsigned char sha1[20];
+ struct object_id oid;
const char *name;
void *name_to_free;
name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
- sha1, NULL);
+ oid.hash, NULL);
if (name) {
for_each_reflog_ent(name, read_one_reflog, reflogs);
free(name_to_free);
@@ -172,18 +172,18 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
reflogs = item->util;
else {
if (*branch == '\0') {
- unsigned char sha1[20];
+ struct object_id oid;
free(branch);
- branch = resolve_refdup("HEAD", 0, sha1, NULL);
+ branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
if (!branch)
die ("No current branch");
}
reflogs = read_complete_reflog(branch);
if (!reflogs || reflogs->nr == 0) {
- unsigned char sha1[20];
+ struct object_id oid;
char *b;
- if (dwim_log(branch, strlen(branch), sha1, &b) == 1) {
+ if (dwim_log(branch, strlen(branch), oid.hash, &b) == 1) {
if (reflogs) {
free(reflogs->ref);
free(reflogs);
diff --git a/transport.c b/transport.c
index d72e089484..141af31e8e 100644
--- a/transport.c
+++ b/transport.c
@@ -467,11 +467,11 @@ void transport_print_push_status(const char *dest, struct ref *refs,
{
struct ref *ref;
int n = 0;
- unsigned char head_sha1[20];
+ struct object_id head_oid;
char *head;
int summary_width = transport_summary_width(refs);
- head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
+ head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
if (verbose) {
for (ref = refs; ref; ref = ref->next)
diff --git a/wt-status.c b/wt-status.c
index d47012048f..0ec090a338 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -121,7 +121,7 @@ static void status_printf_more(struct wt_status *s, const char *color,
void wt_status_prepare(struct wt_status *s)
{
- unsigned char sha1[20];
+ struct object_id oid;
memset(s, 0, sizeof(*s));
memcpy(s->color_palette, default_wt_status_colors,
@@ -129,7 +129,7 @@ void wt_status_prepare(struct wt_status *s)
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
s->use_color = -1;
s->relative_paths = 1;
- s->branch = resolve_refdup("HEAD", 0, sha1, NULL);
+ s->branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
s->reference = "HEAD";
s->fp = stdout;
s->index_file = get_index_file();
--
2.11.0
^ permalink raw reply related
* [PATCH v3 03/19] builtin/describe: convert to struct object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
Convert the functions in this file and struct commit_name to struct
object_id.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
builtin/describe.c | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/builtin/describe.c b/builtin/describe.c
index 01490a157e..738e68f95b 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -39,11 +39,11 @@ static const char *diff_index_args[] = {
struct commit_name {
struct hashmap_entry entry;
- unsigned char peeled[20];
+ struct object_id peeled;
struct tag *tag;
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
unsigned name_checked:1;
- unsigned char sha1[20];
+ struct object_id oid;
char *path;
};
@@ -54,17 +54,17 @@ static const char *prio_names[] = {
static int commit_name_cmp(const struct commit_name *cn1,
const struct commit_name *cn2, const void *peeled)
{
- return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
+ return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
}
-static inline struct commit_name *find_commit_name(const unsigned char *peeled)
+static inline struct commit_name *find_commit_name(const struct object_id *peeled)
{
- return hashmap_get_from_hash(&names, sha1hash(peeled), peeled);
+ return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
}
static int replace_name(struct commit_name *e,
int prio,
- const unsigned char *sha1,
+ const struct object_id *oid,
struct tag **tag)
{
if (!e || e->prio < prio)
@@ -77,13 +77,13 @@ static int replace_name(struct commit_name *e,
struct tag *t;
if (!e->tag) {
- t = lookup_tag(e->sha1);
+ t = lookup_tag(e->oid.hash);
if (!t || parse_tag(t))
return 1;
e->tag = t;
}
- t = lookup_tag(sha1);
+ t = lookup_tag(oid->hash);
if (!t || parse_tag(t))
return 0;
*tag = t;
@@ -96,24 +96,24 @@ static int replace_name(struct commit_name *e,
}
static void add_to_known_names(const char *path,
- const unsigned char *peeled,
+ const struct object_id *peeled,
int prio,
- const unsigned char *sha1)
+ const struct object_id *oid)
{
struct commit_name *e = find_commit_name(peeled);
struct tag *tag = NULL;
- if (replace_name(e, prio, sha1, &tag)) {
+ if (replace_name(e, prio, oid, &tag)) {
if (!e) {
e = xmalloc(sizeof(struct commit_name));
- hashcpy(e->peeled, peeled);
- hashmap_entry_init(e, sha1hash(peeled));
+ oidcpy(&e->peeled, peeled);
+ hashmap_entry_init(e, sha1hash(peeled->hash));
hashmap_add(&names, e);
e->path = NULL;
}
e->tag = tag;
e->prio = prio;
e->name_checked = 0;
- hashcpy(e->sha1, sha1);
+ oidcpy(&e->oid, oid);
free(e->path);
e->path = xstrdup(path);
}
@@ -154,7 +154,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
else
prio = 0;
- add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
+ add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
return 0;
}
@@ -212,7 +212,7 @@ static unsigned long finish_depth_computation(
static void display_name(struct commit_name *n)
{
if (n->prio == 2 && !n->tag) {
- n->tag = lookup_tag(n->sha1);
+ n->tag = lookup_tag(n->oid.hash);
if (!n->tag || parse_tag(n->tag))
die(_("annotated tag %s not available"), n->path);
}
@@ -230,14 +230,14 @@ static void display_name(struct commit_name *n)
printf("%s", n->path);
}
-static void show_suffix(int depth, const unsigned char *sha1)
+static void show_suffix(int depth, const struct object_id *oid)
{
- printf("-%d-g%s", depth, find_unique_abbrev(sha1, abbrev));
+ printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
}
static void describe(const char *arg, int last_one)
{
- unsigned char sha1[20];
+ struct object_id oid;
struct commit *cmit, *gave_up_on = NULL;
struct commit_list *list;
struct commit_name *n;
@@ -246,20 +246,20 @@ static void describe(const char *arg, int last_one)
unsigned long seen_commits = 0;
unsigned int unannotated_cnt = 0;
- if (get_sha1(arg, sha1))
+ if (get_oid(arg, &oid))
die(_("Not a valid object name %s"), arg);
- cmit = lookup_commit_reference(sha1);
+ cmit = lookup_commit_reference(oid.hash);
if (!cmit)
die(_("%s is not a valid '%s' object"), arg, commit_type);
- n = find_commit_name(cmit->object.oid.hash);
+ n = find_commit_name(&cmit->object.oid);
if (n && (tags || all || n->prio == 2)) {
/*
* Exact match to an existing ref.
*/
display_name(n);
if (longformat)
- show_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1);
+ show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
if (dirty)
printf("%s", dirty);
printf("\n");
@@ -276,7 +276,7 @@ static void describe(const char *arg, int last_one)
struct commit *c;
struct commit_name *n = hashmap_iter_first(&names, &iter);
for (; n; n = hashmap_iter_next(&iter)) {
- c = lookup_commit_reference_gently(n->peeled, 1);
+ c = lookup_commit_reference_gently(n->peeled.hash, 1);
if (c)
c->util = n;
}
@@ -380,7 +380,7 @@ static void describe(const char *arg, int last_one)
display_name(all_matches[0].name);
if (abbrev)
- show_suffix(all_matches[0].depth, cmit->object.oid.hash);
+ show_suffix(all_matches[0].depth, &cmit->object.oid);
if (dirty)
printf("%s", dirty);
printf("\n");
--
2.11.0
^ permalink raw reply related
* [PATCH v3 04/19] builtin/fast-export: convert to struct object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
In addition to converting to struct object_id, write some hardcoded
buffer sizes in terms of GIT_SHA1_RAWSZ.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
builtin/fast-export.c | 58 +++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 1e815b5577..e0220630d0 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -212,7 +212,7 @@ static char *anonymize_blob(unsigned long *size)
return strbuf_detach(&out, NULL);
}
-static void export_blob(const unsigned char *sha1)
+static void export_blob(const struct object_id *oid)
{
unsigned long size;
enum object_type type;
@@ -223,34 +223,34 @@ static void export_blob(const unsigned char *sha1)
if (no_data)
return;
- if (is_null_sha1(sha1))
+ if (is_null_oid(oid))
return;
- object = lookup_object(sha1);
+ object = lookup_object(oid->hash);
if (object && object->flags & SHOWN)
return;
if (anonymize) {
buf = anonymize_blob(&size);
- object = (struct object *)lookup_blob(sha1);
+ object = (struct object *)lookup_blob(oid->hash);
eaten = 0;
} else {
- buf = read_sha1_file(sha1, &type, &size);
+ buf = read_sha1_file(oid->hash, &type, &size);
if (!buf)
- die ("Could not read blob %s", sha1_to_hex(sha1));
- if (check_sha1_signature(sha1, buf, size, typename(type)) < 0)
- die("sha1 mismatch in blob %s", sha1_to_hex(sha1));
- object = parse_object_buffer(sha1, type, size, buf, &eaten);
+ die ("Could not read blob %s", oid_to_hex(oid));
+ if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
+ die("sha1 mismatch in blob %s", oid_to_hex(oid));
+ object = parse_object_buffer(oid->hash, type, size, buf, &eaten);
}
if (!object)
- die("Could not read blob %s", sha1_to_hex(sha1));
+ die("Could not read blob %s", oid_to_hex(oid));
mark_next_object(object);
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
if (size && fwrite(buf, size, 1, stdout) != 1)
- die_errno ("Could not write blob '%s'", sha1_to_hex(sha1));
+ die_errno ("Could not write blob '%s'", oid_to_hex(oid));
printf("\n");
show_progress();
@@ -323,19 +323,19 @@ static void print_path(const char *path)
}
}
-static void *generate_fake_sha1(const void *old, size_t *len)
+static void *generate_fake_oid(const void *old, size_t *len)
{
static uint32_t counter = 1; /* avoid null sha1 */
- unsigned char *out = xcalloc(20, 1);
- put_be32(out + 16, counter++);
+ unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);
+ put_be32(out + GIT_SHA1_RAWSZ - 4, counter++);
return out;
}
-static const unsigned char *anonymize_sha1(const unsigned char *sha1)
+static const unsigned char *anonymize_sha1(const struct object_id *oid)
{
static struct hashmap sha1s;
- size_t len = 20;
- return anonymize_mem(&sha1s, generate_fake_sha1, sha1, &len);
+ size_t len = GIT_SHA1_RAWSZ;
+ return anonymize_mem(&sha1s, generate_fake_oid, oid, &len);
}
static void show_filemodify(struct diff_queue_struct *q,
@@ -383,7 +383,7 @@ static void show_filemodify(struct diff_queue_struct *q,
if (no_data || S_ISGITLINK(spec->mode))
printf("M %06o %s ", spec->mode,
sha1_to_hex(anonymize ?
- anonymize_sha1(spec->oid.hash) :
+ anonymize_sha1(&spec->oid) :
spec->oid.hash));
else {
struct object *object = lookup_object(spec->oid.hash);
@@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
/* Export the referenced blobs, and remember the marks. */
for (i = 0; i < diff_queued_diff.nr; i++)
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
- export_blob(diff_queued_diff.queue[i]->two->oid.hash);
+ export_blob(&diff_queued_diff.queue[i]->two->oid);
refname = commit->util;
if (anonymize) {
@@ -797,14 +797,14 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
for (i = 0; i < info->nr; i++) {
struct rev_cmdline_entry *e = info->rev + i;
- unsigned char sha1[20];
+ struct object_id oid;
struct commit *commit;
char *full_name;
if (e->flags & UNINTERESTING)
continue;
- if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
+ if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
continue;
if (refspecs) {
@@ -828,7 +828,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
case OBJ_COMMIT:
break;
case OBJ_BLOB:
- export_blob(commit->object.oid.hash);
+ export_blob(&commit->object.oid);
continue;
default: /* OBJ_TAG (nested tags) is already handled */
warning("Tag points to object of unexpected type %s, skipping.",
@@ -912,7 +912,7 @@ static void import_marks(char *input_file)
while (fgets(line, sizeof(line), f)) {
uint32_t mark;
char *line_end, *mark_end;
- unsigned char sha1[20];
+ struct object_id oid;
struct object *object;
struct commit *commit;
enum object_type type;
@@ -924,28 +924,28 @@ static void import_marks(char *input_file)
mark = strtoumax(line + 1, &mark_end, 10);
if (!mark || mark_end == line + 1
- || *mark_end != ' ' || get_sha1_hex(mark_end + 1, sha1))
+ || *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid))
die("corrupt mark line: %s", line);
if (last_idnum < mark)
last_idnum = mark;
- type = sha1_object_info(sha1, NULL);
+ type = sha1_object_info(oid.hash, NULL);
if (type < 0)
- die("object not found: %s", sha1_to_hex(sha1));
+ die("object not found: %s", oid_to_hex(&oid));
if (type != OBJ_COMMIT)
/* only commits */
continue;
- commit = lookup_commit(sha1);
+ commit = lookup_commit(oid.hash);
if (!commit)
- die("not a commit? can't happen: %s", sha1_to_hex(sha1));
+ die("not a commit? can't happen: %s", oid_to_hex(&oid));
object = &commit->object;
if (object->flags & SHOWN)
- error("Object %s already has a mark", sha1_to_hex(sha1));
+ error("Object %s already has a mark", oid_to_hex(&oid));
mark_object(object, mark);
--
2.11.0
^ permalink raw reply related
* [PATCH v3 01/19] builtin/commit: convert to struct object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
Convert most leaf functions to use struct object_id.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
builtin/commit.c | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 2de5f6cc64..4e288bc513 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -496,7 +496,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
struct wt_status *s)
{
- unsigned char sha1[20];
+ struct object_id oid;
if (s->relative_paths)
s->prefix = prefix;
@@ -509,9 +509,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
s->index_file = index_file;
s->fp = fp;
s->nowarn = nowarn;
- s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
+ s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
if (!s->is_initial)
- hashcpy(s->sha1_commit, sha1);
+ hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format;
s->ignore_submodule_arg = ignore_submodule_arg;
@@ -885,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
commitable = run_status(s->fp, index_file, prefix, 1, s);
s->use_color = saved_color_setting;
} else {
- unsigned char sha1[20];
+ struct object_id oid;
const char *parent = "HEAD";
if (!active_nr && read_cache() < 0)
@@ -894,7 +894,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (amend)
parent = "HEAD^1";
- if (get_sha1(parent, sha1)) {
+ if (get_sha1(parent, oid.hash)) {
int i, ita_nr = 0;
for (i = 0; i < active_nr; i++)
@@ -1332,7 +1332,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
{
static struct wt_status s;
int fd;
- unsigned char sha1[20];
+ struct object_id oid;
static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose, N_("be verbose")),
OPT_SET_INT('s', "short", &status_format,
@@ -1382,9 +1382,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0);
- s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
+ s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
if (!s.is_initial)
- hashcpy(s.sha1_commit, sha1);
+ hashcpy(s.sha1_commit, oid.hash);
s.ignore_submodule_arg = ignore_submodule_arg;
s.status_format = status_format;
@@ -1418,19 +1418,19 @@ static const char *implicit_ident_advice(void)
}
-static void print_summary(const char *prefix, const unsigned char *sha1,
+static void print_summary(const char *prefix, const struct object_id *oid,
int initial_commit)
{
struct rev_info rev;
struct commit *commit;
struct strbuf format = STRBUF_INIT;
- unsigned char junk_sha1[20];
+ struct object_id junk_oid;
const char *head;
struct pretty_print_context pctx = {0};
struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT;
- commit = lookup_commit(sha1);
+ commit = lookup_commit(oid->hash);
if (!commit)
die(_("couldn't look up newly created commit"));
if (parse_commit(commit))
@@ -1477,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);
- head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
+ head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
if (!strcmp(head, "HEAD"))
head = _("detached HEAD");
else
@@ -1522,8 +1522,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
return git_status_config(k, v, s);
}
-static int run_rewrite_hook(const unsigned char *oldsha1,
- const unsigned char *newsha1)
+static int run_rewrite_hook(const struct object_id *oldoid,
+ const struct object_id *newoid)
{
struct child_process proc = CHILD_PROCESS_INIT;
const char *argv[3];
@@ -1544,7 +1544,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
code = start_command(&proc);
if (code)
return code;
- strbuf_addf(&sb, "%s %s\n", sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
+ strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
sigchain_push(SIGPIPE, SIG_IGN);
write_in_full(proc.in, sb.buf, sb.len);
close(proc.in);
@@ -1636,7 +1636,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
struct strbuf author_ident = STRBUF_INIT;
const char *index_file, *reflog_msg;
char *nl;
- unsigned char sha1[20];
+ struct object_id oid;
struct commit_list *parents = NULL;
struct stat statbuf;
struct commit *current_head = NULL;
@@ -1651,10 +1651,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
- if (get_sha1("HEAD", sha1))
+ if (get_sha1("HEAD", oid.hash))
current_head = NULL;
else {
- current_head = lookup_commit_or_die(sha1, "HEAD");
+ current_head = lookup_commit_or_die(oid.hash, "HEAD");
if (parse_commit(current_head))
die(_("could not parse HEAD commit"));
}
@@ -1759,7 +1759,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
}
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
- parents, sha1, author_ident.buf, sign_commit, extra)) {
+ parents, oid.hash, author_ident.buf, sign_commit, extra)) {
rollback_index_files();
die(_("failed to write commit object"));
}
@@ -1776,7 +1776,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
transaction = ref_transaction_begin(&err);
if (!transaction ||
- ref_transaction_update(transaction, "HEAD", sha1,
+ ref_transaction_update(transaction, "HEAD", oid.hash,
current_head
? current_head->object.oid.hash : null_sha1,
0, sb.buf, &err) ||
@@ -1805,13 +1805,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
cfg = init_copy_notes_for_rewrite("amend");
if (cfg) {
/* we are amending, so current_head is not NULL */
- copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1);
+ copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
}
- run_rewrite_hook(current_head->object.oid.hash, sha1);
+ run_rewrite_hook(¤t_head->object.oid, &oid);
}
if (!quiet)
- print_summary(prefix, sha1, !current_head);
+ print_summary(prefix, &oid, !current_head);
strbuf_release(&err);
return 0;
--
2.11.0
^ permalink raw reply related
* [PATCH v3 16/19] sha1_file: introduce an nth_packed_object_oid function
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
There are places in the code where we would like to provide a struct
object_id *, yet read the hash directly from the pack. Provide an
nth_packed_object_oid function that is similar to the
nth_packed_object_sha1 function.
In order to avoid a potentially invalid cast, nth_packed_object_oid
provides a variable into which to store the value, which it returns on
success; on error, it returns NULL, as nth_packed_object_sha1 does.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
cache.h | 6 ++++++
sha1_file.c | 17 ++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index e03a672d15..4f3bfc5ee7 100644
--- a/cache.h
+++ b/cache.h
@@ -1608,6 +1608,12 @@ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
* error.
*/
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
+/*
+ * Like nth_packed_object_oid, but write the data into the object specified by
+ * the the first argument. Returns the first argument on success, and NULL on
+ * error.
+ */
+extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
/*
* Return the offset of the nth object within the specified packfile.
diff --git a/sha1_file.c b/sha1_file.c
index ec957db5e1..777b8e8eae 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2628,6 +2628,17 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,
}
}
+const struct object_id *nth_packed_object_oid(struct object_id *oid,
+ struct packed_git *p,
+ uint32_t n)
+{
+ const unsigned char *hash = nth_packed_object_sha1(p, n);
+ if (!hash)
+ return NULL;
+ hashcpy(oid->hash, hash);
+ return oid;
+}
+
void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
{
const unsigned char *ptr = vptr;
@@ -3788,13 +3799,13 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
int r = 0;
for (i = 0; i < p->num_objects; i++) {
- const unsigned char *sha1 = nth_packed_object_sha1(p, i);
+ struct object_id oid;
- if (!sha1)
+ if (!nth_packed_object_oid(&oid, p, i))
return error("unable to get sha1 of object %u in %s",
i, p->pack_name);
- r = cb(sha1, p, i, data);
+ r = cb(oid.hash, p, i, data);
if (r)
break;
}
--
2.11.0
^ permalink raw reply related
* [PATCH v3 12/19] reflog-walk: convert struct reflog_info to struct object_id
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
Convert struct reflog_info to use struct object_id by changing the
structure definition and applying the following semantic patch:
@@
struct reflog_info E1;
@@
- E1.osha1
+ E1.ooid.hash
@@
struct reflog_info *E1;
@@
- E1->osha1
+ E1->ooid.hash
@@
struct reflog_info E1;
@@
- E1.nsha1
+ E1.noid.hash
@@
struct reflog_info *E1;
@@
- E1->nsha1
+ E1->noid.hash
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
reflog-walk.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/reflog-walk.c b/reflog-walk.c
index f98748e2ae..fe5be41471 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -10,7 +10,7 @@ struct complete_reflogs {
char *ref;
const char *short_ref;
struct reflog_info {
- unsigned char osha1[20], nsha1[20];
+ struct object_id ooid, noid;
char *email;
unsigned long timestamp;
int tz;
@@ -28,8 +28,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
ALLOC_GROW(array->items, array->nr + 1, array->alloc);
item = array->items + array->nr;
- hashcpy(item->osha1, osha1);
- hashcpy(item->nsha1, nsha1);
+ hashcpy(item->ooid.hash, osha1);
+ hashcpy(item->noid.hash, nsha1);
item->email = xstrdup(email);
item->timestamp = timestamp;
item->tz = tz;
@@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
do {
reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
commit_reflog->recno--;
- logobj = parse_object(reflog->osha1);
+ logobj = parse_object(reflog->ooid.hash);
} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
- if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->osha1)) {
+ if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->ooid.hash)) {
/* a root commit, but there are still more entries to show */
reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
- logobj = parse_object(reflog->nsha1);
+ logobj = parse_object(reflog->noid.hash);
}
if (!logobj || logobj->type != OBJ_COMMIT) {
--
2.11.0
^ permalink raw reply related
* [PATCH v3 14/19] hex: introduce parse_oid_hex
From: brian m. carlson @ 2017-02-18 0:06 UTC (permalink / raw)
To: git; +Cc: Jeff King, Michael Haggerty, Junio C Hamano
In-Reply-To: <20170218000652.375129-1-sandals@crustytoothpaste.net>
Introduce a function, parse_oid_hex, which parses a hexadecimal object
ID and if successful, sets a pointer to just beyond the last character.
This allows for simpler, more robust parsing without needing to
hard-code integer values throughout the codebase.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
cache.h | 9 +++++++++
hex.c | 8 ++++++++
2 files changed, 17 insertions(+)
diff --git a/cache.h b/cache.h
index 61fc86e6d7..e03a672d15 100644
--- a/cache.h
+++ b/cache.h
@@ -1319,6 +1319,15 @@ extern char *oid_to_hex_r(char *out, const struct object_id *oid);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
+/*
+ * Parse a 40-character hexadecimal object ID starting from hex, updating the
+ * pointer specified by end when parsing stops. The resulting object ID is
+ * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or
+ * other invalid character. end is only updated on success; otherwise, it is
+ * unmodified.
+ */
+extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
+
extern int interpret_branch_name(const char *str, int len, struct strbuf *);
extern int get_oid_mb(const char *str, struct object_id *oid);
diff --git a/hex.c b/hex.c
index 845b01a874..eab7b626ee 100644
--- a/hex.c
+++ b/hex.c
@@ -53,6 +53,14 @@ int get_oid_hex(const char *hex, struct object_id *oid)
return get_sha1_hex(hex, oid->hash);
}
+int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
+{
+ int ret = get_oid_hex(hex, oid);
+ if (!ret)
+ *end = hex + GIT_SHA1_HEXSZ;
+ return ret;
+}
+
char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
{
static const char hex[] = "0123456789abcdef";
--
2.11.0
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox