* Re: gnulib-tool --version
[not found] ` <200803150512.53166.bruno@clisp.org>
@ 2008-03-15 4:37 ` Eric Blake
2008-03-15 6:08 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2008-03-15 4:37 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib, git
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[adding the git list]
According to Bruno Haible on 3/14/2008 10:12 PM:
| Take an example: Until 3 days ago,
| $ git log 532f
| was equivalent to
| $ git log 532f4b4a94e7df8e730e433d4cba9e4119641691
|
| But then there was a commit 532f65ac8de5a89ea0b159fc3b76ead5a53e9fea. Since
| then,
| $ git log 532f
| gives an error message
| error: short SHA1 532f is ambiguous.
| fatal: ambiguous argument '532f': unknown revision or path not in the
working tree.
| Use '--' to separate paths from revisions
The message comes from 'git rev-parse', which is called under the hood by
most other git commands to resolve a SHA1 prefix into a commit.
|
| To exclude the problem of ambiguous commit ids, with a reasonable
probability,
| I would therefore take the first 8 hex digits, not only the first 4.
'git rev-parse', and thus 'git describe', defaults to 7 hex digits, and
will display no fewer than 4 (although it displays as many as are
necessary to have a non-ambiguous output at the time it is run). gnulib's
git-version-gen script intentionally asks 'git describe' for the shortest
prefix, on the grounds that developers don't like to type long random
strings, rather than sticking with the default of 7.
What is really needed is a method in git where once a SHA1 prefix becomes
ambiguous, you can still easily choose to resolve the ambiguity in favor
of the oldest commit that matches the prefix. This is on the grounds that
there are times when the user knows that the prefix was generated by 'git
describe', and was not ambiguous at the time it was abbreviated.
Unfortunately, I don't know such a command option or special syntax to
'git rev-parse' to make this resolution occur. And what's worse, the
error message from 'git rev-parse' doesn't help - it only states that the
prefix is either missing or ambiguous. It would be much nicer to know
that the prefix is now too short (vs. never existed), to then know to try
the option to list all the alternative candidates and/or pick the oldest.
- --
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkfbUpUACgkQ84KuGfSFAYDsewCgrD9hRriDEYGWd/WlWIxLDRk6
yVYAoJMIPljUvCnqS4w38Kg2ckI9g88C
=dDhg
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: gnulib-tool --version
2008-03-15 4:37 ` gnulib-tool --version Eric Blake
@ 2008-03-15 6:08 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-03-15 6:08 UTC (permalink / raw)
To: Eric Blake; +Cc: Bruno Haible, git
Eric Blake <ebb9@byu.net> writes:
> What is really needed is a method in git where once a SHA1 prefix becomes
> ambiguous, you can still easily choose to resolve the ambiguity in favor
> of the oldest commit that matches the prefix.
"Oldest commit" does not make much sense in a distributed environment. In
git.git, I tend to have many objects in my primary repository that nobody
else has, and other people would probably have many objects that I do not
have. "Oldest among the ones reachable from these heads" and specifying
only the ones that are publicly available may have some value, though.
I agree that we would want a reverse operation of find_unique_abbrev();
here is a quick and dirty one.
$ git rev-parse --disamb=aba1 |
git name-rev --stdin
aba14750f47700b8923b411a9348fb251b788967 tree
aba15f7f592c302196401d17a42c772d744555b4 (tags/gitgui-0.9.3~5) commit
aba16b190c54a107521801ad77ab66586553ba69 blob
aba170cdb4874b72dd619e6f7bbc13c33295f831 (tags/v1.5.2^0) commit
It is very tempting to say that we should favor commits over other types,
but at the "extended sha1 expression" level, we traditionally haven't
favored one type over others, so it has to wait until 1.6.0 at least.
---
builtin-rev-parse.c | 13 +++++++++++++
cache.h | 3 +++
sha1_name.c | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 0351d54..c64b43e 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -365,6 +365,15 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
return 0;
}
+static void disamb_show(const unsigned char *sha1, void *cb_data)
+{
+ char *orig = cb_data;
+ enum object_type type;
+
+ type = sha1_object_info(sha1, NULL);
+ printf("%s %s %s\n", sha1_to_hex(sha1), typename(type), orig);
+}
+
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
int i, as_is = 0, verify = 0;
@@ -548,6 +557,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
show_datestring("--min-age=", arg+8);
continue;
}
+ if (!prefixcmp(arg, "--disamb=")) {
+ for_each_sha1(arg + 9, disamb_show, NULL);
+ continue;
+ }
if (show_flag(arg) && verify)
die("Needed a single revision");
continue;
diff --git a/cache.h b/cache.h
index 2a1e7ec..fa15140 100644
--- a/cache.h
+++ b/cache.h
@@ -454,6 +454,9 @@ extern char *sha1_file_name(const unsigned char *sha1);
extern char *sha1_pack_name(const unsigned char *sha1);
extern char *sha1_pack_index_name(const unsigned char *sha1);
extern const char *find_unique_abbrev(const unsigned char *sha1, int);
+typedef void for_each_sha1_fn(const unsigned char *sha1, void *);
+int for_each_sha1(const char *prefix, for_each_sha1_fn fn, void *cb_data);
+
extern const unsigned char null_sha1[20];
static inline int is_null_sha1(const unsigned char *sha1)
{
diff --git a/sha1_name.c b/sha1_name.c
index 8b6c76f..2703831 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -213,6 +213,43 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
return hex;
}
+static int for_each_sha1_rec(char *prefix, int len, for_each_sha1_fn fn, void *cb_data)
+{
+ unsigned char sha1[20];
+ int status, i, found;
+
+ if (40 <= len)
+ return 0;
+ status = get_short_sha1(prefix, len, sha1, 1);
+ if (status == SHORT_NAME_NOT_FOUND)
+ return 0;
+ if (!status) {
+ fn(sha1, cb_data);
+ return 1;
+ }
+ /* Ambiguous */
+ found = 0;
+ for (i = 0; i < 16; i++) {
+ prefix[len] = "0123456789abcdef"[i];
+ prefix[len+1] = '\0';
+ found += for_each_sha1_rec(prefix, len + 1, fn, cb_data);
+ }
+ return found;
+}
+
+int for_each_sha1(const char *prefix, for_each_sha1_fn fn, void *cb_data)
+{
+ int len;
+ char hex[41];
+
+ len = strlen(prefix);
+ if (40 <= len)
+ return 0;
+ memcpy(hex, prefix, len+1);
+
+ return for_each_sha1_rec(hex, len, fn, cb_data);
+}
+
static int ambiguous_path(const char *path, int len)
{
int slash = 1;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-03-15 6:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <910CF843580B3C40A25CD0D04B3908E286A29C@exchange4.comune.prato.local>
[not found] ` <200803150052.44573.bruno@clisp.org>
[not found] ` <47DB12F3.8020504@byu.net>
[not found] ` <200803150512.53166.bruno@clisp.org>
2008-03-15 4:37 ` gnulib-tool --version Eric Blake
2008-03-15 6:08 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).