Commit graph

174 commits

Author SHA1 Message Date
Junio C Hamano e48ba200be sha1_name.c: get_sha1_1() takes lookup flags
This is to pass the disambiguation hints from the caller down the
callchain.  Nothing is changed in this step, as everybody just
passes 0 in the flag.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-09 16:42:22 -07:00
Junio C Hamano 6269b6b676 sha1_name.c: get_describe_name() by definition groks only commits
Teach get_describe_name() to pass the disambiguation hint down the
callchain to get_short_sha1().

Also add tests to show various syntactic elements that we could take
advantage of the object type information to help disambiguration of
abbreviated object names.  Many of them are marked as broken, and
some of them will be fixed in later patches in this series.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-09 16:42:22 -07:00
Junio C Hamano aa1dec9ef6 sha1_name.c: teach get_short_sha1() a commit-only option
When the caller knows that the parameter is meant to name a commit,
e.g. "56789a" in describe name "v1.2.3-4-g56789a", pass that as a
hint so that lower level can use it to disambiguate objects when
there is only one commit whose name begins with 56789a even if there
are objects of other types whose names share the same prefix.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 11:17:59 -07:00
Junio C Hamano 37c00e5590 sha1_name.c: allow get_short_sha1() to take other flags
Instead of a separate "int quietly" argument, make it take "unsigned
flags" so that we can pass other options to it.

The bit assignment of this flag word is exposed in cache.h because
the mechanism will be exposed to callers of the higher layer in
later commits in this series.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 11:17:59 -07:00
Junio C Hamano c005e98612 get_sha1(): fix error status regression
In finish_object_disambiguation(), if the candidate hasn't been
checked, there are two cases:

 - It is the first and only object that match the prefix; or
 - It replaced another object that matched the prefix but that
   object did not satisfy ds->fn() callback.

And the former case we set ds->candidate_ok to true without doing
anything else, while for the latter we check the candidate, which
may set ds->candidate_ok to false.

At this point in the code, ds->candidate_ok can be false only if
this last-round check found that the candidate does not pass the
check, because the state after update_candidates() returns cannot
satisfy

    !ds->ambiguous && ds->candidate_exists && ds->candidate_checked

and !ds->canidate_ok at the same time.

Hence, when we execute this "return", we know we have seen more than
one object that match the prefix (and none of them satisfied ds->fn),
meaning that we should say "the short name is ambiguous", not "there
is no object that matches the prefix".

Noticed by Jeff King.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 11:17:17 -07:00
Junio C Hamano a78fafe74a sha1_name.c: restructure disambiguation of short names
We try to find zero, one or more matches from loose objects and
packed objects independently and then decide if the given short
object name is unique across them.

Instead, introduce a "struct disambiguate_state" that keeps track of
what we have found so far, that can be one of:

 - We have seen one object that _could_ be what we are looking for;
 - We have also checked that object for additional constraints (if any),
   and found that the object satisfies it;
 - We have also checked that object for additional constraints (if any),
   and found that the object does not satisfy it; or
 - We have seen more than one objects that satisfy the constraints.

and pass it to the enumeration functions for loose and packed
objects.  The disambiguation state can optionally take a callback
function that takes a candidate object name and reports if the
object satisifies additional criteria (e.g. when the caller knows
that the short name must refer to a commit, this mechanism can be
used to check the type of the given object).

Compared to the earlier attempt, this round avoids the optional
check if there is only one candidate that matches the short name in
the first place.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:15 -07:00
Junio C Hamano 1703f9aa0b sha1_name.c: correct misnamed "canonical" and "res"
These are hexadecimal and binary representation of the short object
name given to the callchain as its input.  Rename them with _pfx
suffix to make it clear they are prefixes, and call them hex and bin
respectively.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:15 -07:00
Junio C Hamano f703e6ea5e sha1_name.c: refactor find_short_packed_object()
Extract the logic to find object(s) that match a given prefix inside
a single pack into a separate helper function, and give it a bit more
comment.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:15 -07:00
Junio C Hamano 1b27c2f01a sha1_name.c: rename "now" to "current"
This variable points at the element we are currently looking at, and
does not have anything to do with the current time which the name
"now" implies.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:15 -07:00
Junio C Hamano 274ac009f4 sha1_name.c: clarify what "fake" is for in find_short_object_filename()
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:15 -07:00
Junio C Hamano 249c8f4a16 sha1_name.c: get rid of get_sha1_with_mode()
There are only two callers, and they will benefit from being able to
pass disambiguation hints to underlying get_sha1_with_context() API
once it happens.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:24:11 -07:00
Junio C Hamano 8c135ea260 sha1_name.c: get rid of get_sha1_with_mode_1()
The only external caller is setup.c that tries to give a nicer error
message when an object name is misspelt (e.g. "HEAD:cashe.h").
Retire it and give the caller a dedicated and more intuitive API
function maybe_die_on_misspelt_object_name().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-03 10:22:37 -07:00
Junio C Hamano f01cc14c3c sha1_name.c: hide get_sha1_with_context_1() ugliness
There is no outside caller that cares about the "only-to-die" ugliness.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-02 11:22:57 -07:00
Junio C Hamano a1b475eeb4 sha1_name.c: indentation fix
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-18 14:59:56 -07:00
Junio C Hamano 0445ba2457 Merge branch 'jc/broken-ref-dwim-fix'
* jc/broken-ref-dwim-fix:
  resolve_ref(): report breakage to the caller without warning
  resolve_ref(): expose REF_ISBROKEN flag
  refs.c: move dwim_ref()/dwim_log() from sha1_name.c
2011-10-21 16:04:36 -07:00
Junio C Hamano ff74f7f118 refs.c: move dwim_ref()/dwim_log() from sha1_name.c
Both dwim_ref()/dwim_log() functions are intimately related to the ref
parsing rules defined in refs.c and better fits there. Move them together
with substitute_branch_name(), a file scope static helper function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-12 10:35:38 -07:00
Junio C Hamano 9bd500048d Merge branch 'mh/check-ref-format-3'
* mh/check-ref-format-3: (23 commits)
  add_ref(): verify that the refname is formatted correctly
  resolve_ref(): expand documentation
  resolve_ref(): also treat a too-long SHA1 as invalid
  resolve_ref(): emit warnings for improperly-formatted references
  resolve_ref(): verify that the input refname has the right format
  remote: avoid passing NULL to read_ref()
  remote: use xstrdup() instead of strdup()
  resolve_ref(): do not follow incorrectly-formatted symbolic refs
  resolve_ref(): extract a function get_packed_ref()
  resolve_ref(): turn buffer into a proper string as soon as possible
  resolve_ref(): only follow a symlink that contains a valid, normalized refname
  resolve_ref(): use prefixcmp()
  resolve_ref(): explicitly fail if a symlink is not readable
  Change check_refname_format() to reject unnormalized refnames
  Inline function refname_format_print()
  Make collapse_slashes() allocate memory for its result
  Do not allow ".lock" at the end of any refname component
  Refactor check_refname_format()
  Change check_ref_format() to take a flags argument
  Change bad_ref_char() to return a boolean value
  ...
2011-10-10 15:56:18 -07:00
Michael Haggerty 8d9c50105f Change check_ref_format() to take a flags argument
Change check_ref_format() to take a flags argument that indicates what
is acceptable in the reference name (analogous to "git
check-ref-format"'s "--allow-onelevel" and "--refspec-pattern").  This
is more convenient for callers and also fixes a failure in the test
suite (and likely elsewhere in the code) by enabling "onelevel" and
"refspec-pattern" to be allowed independently of each other.

Also rename check_ref_format() to check_refname_format() to make it
obvious that it deals with refnames rather than references themselves.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-05 13:45:29 -07:00
Junio C Hamano 6099835c19 Allow git merge ":/<pattern>"
It probably is not such a good idea to use ":/<pattern>" to specify which
commit to merge, as ":/<pattern>" can often hit unexpected commits, but
somebody tried it and got a nonsense error message:

	fatal: ':/Foo bar' does not point to a commit

So here is a for-the-sake-of-consistency update that is fairly useless
that allows users to carefully try not shooting in the foot.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-15 16:52:43 -07:00
Junio C Hamano be5ab43566 Merge branch 'jc/magic-pathspec'
* jc/magic-pathspec:
  setup.c: Fix some "symbol not declared" sparse warnings
  t3703: Skip tests using directory name ":" on Windows
  revision.c: leave a note for "a lone :" enhancement
  t3703, t4208: add test cases for magic pathspec
  rev/path disambiguation: further restrict "misspelled index entry" diag
  fix overslow :/no-such-string-ever-existed diagnostics
  fix overstrict :<path> diagnosis
  grep: use get_pathspec() correctly
  pathspec: drop "lone : means no pathspec" from get_pathspec()
  Revert "magic pathspec: add ":(icase)path" to match case insensitively"
  magic pathspec: add ":(icase)path" to match case insensitively
  magic pathspec: futureproof shorthand form
  magic pathspec: add tentative ":/path/from/top/level" pathspec support
2011-05-23 09:58:35 -07:00
Junio C Hamano 2e83b66c32 fix overslow :/no-such-string-ever-existed diagnostics
"git cmd :/no-such-string-ever-existed" runs an extra round of get_sha1()
since 009fee4 (Detailed diagnosis when parsing an object name fails.,
2009-12-07).  Once without error diagnosis to see there is no commit with
such a string in the log message (hence "it cannot be a ref"), and after
seeing that :/no-such-string-ever-existed is not a filename (hence "it
cannot be a path, either"), another time to give "better diagnosis".

The thing is, the second time it runs, we already know that traversing the
history all the way down to the root will _not_ find any matching commit.

Rename misguided "gently" parameter, which is turned off _only_ when the
"detailed diagnosis" codepath knows that it cannot be a ref and making the
call only for the caller to die with a message.  Flip its meaning (and
adjust the callers) and call it "only_to_die", which is not a great name,
but it describes far more clearly what the codepaths that switches their
behaviour based on this variable do.

On my box, the command spends ~1.8 seconds without the patch to make the
report; with the patch it spends ~1.12 seconds.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-10 12:37:54 -07:00
Junio C Hamano 9619617d33 fix overstrict :<path> diagnosis
Given "git log :", we get a disambiguation message that tries to be
helpful and yet totally misses the point, i.e.

    $ git log :
    fatal: Path '' does not exist (neither on disk nor in the index).
    $ git log :/
    fatal: Path '/' exists on disk, but not in the index.

An empty path nor anything that begins with '/' cannot possibly in the
index, and it is wrong to guess that the user might have meant to access
such an index entry.

It should yield the same error message as "git log '*.c'", i.e.

    $ git log '*.c'
    fatal: ambiguous argument '*.c': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-10 12:36:06 -07:00
Michael J Gruber e41d718c7d sha1_name: Suggest commit:./file for path in subdir
Currently, the "Did you mean..." message suggests "commit:fullpath"
only. Extend this to show the more convenient "commit:./file" form also.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-03 12:24:27 -07:00
Junio C Hamano ea2c69ed47 Revert "core.abbrevguard: Ensure short object names stay unique a bit longer"
This reverts commit 72a5b561fc, as adding
fixed number of hexdigits more than necessary to make one object name
locally unique does not help in futureproofing the uniqueness of names
we generate today.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-10 22:41:14 -08:00
Junio C Hamano 716958c9a2 Merge branch 'tf/commit-list-prefix'
* tf/commit-list-prefix:
  commit: Add commit_list prefix in two function names.

Conflicts:
	sha1_name.c
2010-12-22 14:40:17 -08:00
Junio C Hamano 41cd7974b0 Merge branch 'nd/oneline-sha1-name-from-specific-ref'
* nd/oneline-sha1-name-from-specific-ref:
  get_sha1: handle special case $commit^{/}
  get_sha1: support $commit^{/regex} syntax
  get_sha1_oneline: make callers prepare the commit list to traverse
  get_sha1_oneline: fix lifespan rule of temp_commit_buffer variable
2010-12-21 14:30:19 -08:00
Nguyễn Thái Ngọc Duy 4322842acf get_sha1: handle special case $commit^{/}
Empty regex pattern should always match. But the exact behavior of
regexec() may vary. Because it always matches anyway, we can just
return 'matched' without calling regex machinery.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-16 13:11:42 -08:00
Junio C Hamano 620b89cd98 Merge branch 'nd/extended-sha1-relpath'
* nd/extended-sha1-relpath:
  get_sha1: teach ":$n:<path>" the same relative path logic
  get_sha1: support relative path ":path" syntax
  Make prefix_path() return char* without const

Conflicts:
	sha1_name.c
2010-12-16 12:51:05 -08:00
Nguyễn Thái Ngọc Duy 32574b68c5 get_sha1: support $commit^{/regex} syntax
This works like ":/regex" syntax that finds a recently created commit
starting from all refs, but limits the discovery to those reachable from
the named commit.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-14 16:50:45 -08:00
Nguyễn Thái Ngọc Duy 84baa31bcb get_sha1_oneline: make callers prepare the commit list to traverse
This gives callers more control, i.e. which ref will be searched from.
They must prepare the list ordered by committer date.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-12 22:32:01 -08:00
Junio C Hamano 28042dbcd6 get_sha1_oneline: fix lifespan rule of temp_commit_buffer variable
This is trying to free only what we ourselves read (as opposed to what
we borrowed from commit->buffer) but do so lazily only to work around
the fact that the code has many irregular exit points, and doing it right
makes it necessary to call free() from many different places in the loop.

Rewrite the structure of the code inside the loop so that the variable
has to live within a single iteration, ever.  This should make the logic
easier to follow as well.

Also we didn't free a temporary commit list we kept to hold the original
set of commits.  Free it.

Noticed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-12 22:31:45 -08:00
Junio C Hamano 3d6e0f745e get_sha1: teach ":$n:<path>" the same relative path logic
We taught the object name parser to take ":./<path>", ":../<path>", etc.
and understand them to be relative to the current working directory.

Given that ":<path>" is just a short-hand for ":0:<path>" (i.e. "take
stage #0 of that path"), we should allow ":$n:<path>" to interpret them
the same way.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-09 13:38:05 -08:00
Nguyễn Thái Ngọc Duy 979f792951 get_sha1: support relative path ":path" syntax
Currently :path and ref:path can be used to refer to a specific object
in index or ref respectively. "path" component is absolute path. This
patch allows "path" to be written as "./path" or "../path", which is
relative to user's original cwd.

This does not work in commands for which startup_info is NULL
(i.e. non-builtin ones, it seems none of them needs this anyway).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-07 14:25:46 -08:00
Junio C Hamano 39f04dbaac Merge branch 'jn/thinner-wrapper'
* jn/thinner-wrapper:
  Remove pack file handling dependency from wrapper.o
  pack-objects: mark file-local variable static
  wrapper: give zlib wrappers their own translation unit
  strbuf: move strbuf_branchname to sha1_name.c
  path helpers: move git_mkstemp* to wrapper.c
  wrapper: move odb_* to environment.c
  wrapper: move xmmap() to sha1_file.c
2010-12-03 16:13:06 -08:00
Junio C Hamano 63ae595c6d Merge branch 'jc/abbrev-guard'
* jc/abbrev-guard:
  core.abbrevguard: Ensure short object names stay unique a bit longer
2010-12-03 16:10:35 -08:00
Thiago Farina 47e44ed1dc commit: Add commit_list prefix in two function names.
Add commit_list prefix to insert_by_date function and to sort_by_date,
so it's clear that these functions refer to commit_list structure.

Signed-off-by: Thiago Farina <tfransosi@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-29 14:01:52 -08:00
Junio C Hamano dd9d290bc9 Merge branch 'ks/no-textconv-symlink'
* ks/no-textconv-symlink:
  blame,cat-file --textconv: Don't assume mode is ``S_IFREF | 0664''
  blame,cat-file: Demonstrate --textconv is wrongly running converter on symlinks
  blame,cat-file: Prepare --textconv tests for correctly-failing conversion program
2010-11-17 14:59:27 -08:00
Jonathan Nieder 6bab74e7fb strbuf: move strbuf_branchname to sha1_name.c
strbuf_branchname is a thin wrapper around interpret_branch_name
from sha1_name.o.  Most strbuf.o users do not need it.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 11:07:04 -08:00
Junio C Hamano 72a5b561fc core.abbrevguard: Ensure short object names stay unique a bit longer
Even though git makes sure that it uses enough hexdigits to show an
abbreviated object name unambiguously, as more objects are added to the
repository over time, a short name that used to be unique will stop being
unique.  Git uses this many extra hexdigits that are more than necessary
to make the object name currently unique, in the hope that its output will
stay unique a bit longer.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-28 17:37:35 -07:00
Kirill Smelkov 900647104e blame,cat-file --textconv: Don't assume mode is ``S_IFREF | 0664''
We need to get the correct mode when blame reads the source from the
working tree, the index, or trees.  This allows us to omit running
textconv filters on symbolic links.

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Reviewed-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-29 16:53:25 -07:00
Matthieu Moy 95ad6d2de1 update comment and documentation for :/foo syntax
The documentation in revisions.txt did not match the implementation, and
the comment in sha1_name.c was incomplete.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-27 10:54:52 -07:00
Junio C Hamano 306d7e5556 Merge branch 'js/maint-reflog-beyond-horizon'
* js/maint-reflog-beyond-horizon:
  t1503: fix broken test_must_fail calls
  rev-parse: tests git rev-parse --verify master@{n}, for various n
  sha1_name.c: use warning in preference to fprintf(stderr
  rev-parse: exit with non-zero status if ref@{n} is not valid.
2010-09-03 22:24:29 -07:00
Jon Seymour eedce784a7 sha1_name.c: use warning in preference to fprintf(stderr
This commit changes sha1_name.c to use warning instead of
fprintf(stderr).

Trailing newlines from message formats have been removed
since warning adds one itself.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-24 10:46:14 -07:00
Jon Seymour e6eedc31d5 rev-parse: exit with non-zero status if ref@{n} is not valid.
"The current behaviour of ref@{...} syntax parser is suboptimal:

    $ git rev-parse --verify jch@{99999} && echo true
    warning: Log for 'jch' only has 1368 entries.
    cfb88e9a8d
    true

It even knows that it is running off the cut-off point; it should just
cause the caller to notice that fact.  I don't think changing it to error
out should cause any harm to existing callers."

With this change:

   $ git rev-parse --verify jch@{99999} || echo false
   fatal: Log for 'jch' only has 1368 entries.
   false

   $ git rev-parse jch@{99999} || echo false
   fatal: Log for 'jch' only has 1368 entries.
   false

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-24 10:46:11 -07:00
Junio C Hamano 6baa9bd882 Merge branch 'jc/sha1-name-find-fix' into maint
* jc/sha1-name-find-fix:
  sha1_name.c: fix parsing of ":/token" syntax

Conflicts:
	sha1_name.c
2010-08-19 15:49:24 -07:00
Junio C Hamano 3d04589758 Merge branch 'jc/sha1-name-find-fix'
* jc/sha1-name-find-fix:
  sha1_name.c: fix parsing of ":/token" syntax

Conflicts:
	sha1_name.c
2010-08-12 18:32:49 -07:00
Junio C Hamano f7bff00314 sha1_name.c: fix parsing of ":/token" syntax
The parser tried to clean up the object flags it used while finding
commits with matching string, but was not doing a very good job at it.

This caused "checkout -b new ':/token'", which internally tries to parse
':/token' twice as an object name, to fail when the commit in question
was reachable from only one ref.

The mask bits given to pop_most_recent_commit(&list, MASK) means "I have
already been on the list to be processed, so please do not place me again
even if I am found to be a parent of some other commit on the list."  So
mark them when we add them to the list at the beginning.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-02 14:40:48 -07:00
Junio C Hamano cf4403a010 Merge branch 'cp/textconv-cat-file'
* cp/textconv-cat-file:
  git-cat-file.txt: Document --textconv
  t/t8007: test textconv support for cat-file
  textconv: support for cat_file
  sha1_name: add get_sha1_with_context()
2010-06-27 12:07:55 -07:00
Clément Poulain 573285e552 sha1_name: add get_sha1_with_context()
Textconv is defined by the diff driver, which is associated with a pathname,
not a blob. This fonction permits to know the context for the sha1 you're
looking for, especially his pathname

Signed-off-by: Clément Poulain <clement.poulain@ensimag.imag.fr>
Signed-off-by: Diane Gasselin <diane.gasselin@ensimag.imag.fr>
Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-18 09:41:29 -07:00
Linus Torvalds 57895105c4 Make :/ accept a regex rather than a fixed pattern
This also makes it trigger anywhere in the commit message, rather than
just at the beginning. Which tends to be a lot more useful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-14 10:31:11 -07:00