11 #include "sha1-array.h"
13 #include "object-store.h"
14 #include "repository.h"
16 #include "commit-reach.h"
18 static int get_oid_oneline(const char *, struct object_id
*, struct commit_list
*);
20 typedef int (*disambiguate_hint_fn
)(const struct object_id
*, void *);
22 struct disambiguate_state
{
23 int len
; /* length of prefix in hex chars */
24 char hex_pfx
[GIT_MAX_HEXSZ
+ 1];
25 struct object_id bin_pfx
;
27 disambiguate_hint_fn fn
;
29 struct object_id candidate
;
30 unsigned candidate_exists
:1;
31 unsigned candidate_checked
:1;
32 unsigned candidate_ok
:1;
33 unsigned disambiguate_fn_used
:1;
35 unsigned always_call_fn
:1;
38 static void update_candidates(struct disambiguate_state
*ds
, const struct object_id
*current
)
40 if (ds
->always_call_fn
) {
41 ds
->ambiguous
= ds
->fn(current
, ds
->cb_data
) ? 1 : 0;
44 if (!ds
->candidate_exists
) {
45 /* this is the first candidate */
46 oidcpy(&ds
->candidate
, current
);
47 ds
->candidate_exists
= 1;
49 } else if (oideq(&ds
->candidate
, current
)) {
50 /* the same as what we already have seen */
55 /* cannot disambiguate between ds->candidate and current */
60 if (!ds
->candidate_checked
) {
61 ds
->candidate_ok
= ds
->fn(&ds
->candidate
, ds
->cb_data
);
62 ds
->disambiguate_fn_used
= 1;
63 ds
->candidate_checked
= 1;
66 if (!ds
->candidate_ok
) {
67 /* discard the candidate; we know it does not satisfy fn */
68 oidcpy(&ds
->candidate
, current
);
69 ds
->candidate_checked
= 0;
73 /* if we reach this point, we know ds->candidate satisfies fn */
74 if (ds
->fn(current
, ds
->cb_data
)) {
76 * if both current and candidate satisfy fn, we cannot
83 /* otherwise, current can be discarded and candidate is still good */
86 static int match_sha(unsigned, const unsigned char *, const unsigned char *);
88 static void find_short_object_filename(struct disambiguate_state
*ds
)
90 struct object_directory
*odb
;
92 for (odb
= the_repository
->objects
->odb
;
93 odb
&& !ds
->ambiguous
;
96 struct oid_array
*loose_objects
;
98 loose_objects
= odb_loose_cache(odb
, &ds
->bin_pfx
);
99 pos
= oid_array_lookup(loose_objects
, &ds
->bin_pfx
);
102 while (!ds
->ambiguous
&& pos
< loose_objects
->nr
) {
103 const struct object_id
*oid
;
104 oid
= loose_objects
->oid
+ pos
;
105 if (!match_sha(ds
->len
, ds
->bin_pfx
.hash
, oid
->hash
))
107 update_candidates(ds
, oid
);
113 static int match_sha(unsigned len
, const unsigned char *a
, const unsigned char *b
)
123 if ((*a
^ *b
) & 0xf0)
128 static void unique_in_midx(struct multi_pack_index
*m
,
129 struct disambiguate_state
*ds
)
131 uint32_t num
, i
, first
= 0;
132 const struct object_id
*current
= NULL
;
133 num
= m
->num_objects
;
138 bsearch_midx(&ds
->bin_pfx
, m
, &first
);
141 * At this point, "first" is the location of the lowest object
142 * with an object name that could match "bin_pfx". See if we have
143 * 0, 1 or more objects that actually match(es).
145 for (i
= first
; i
< num
&& !ds
->ambiguous
; i
++) {
146 struct object_id oid
;
147 current
= nth_midxed_object_oid(&oid
, m
, i
);
148 if (!match_sha(ds
->len
, ds
->bin_pfx
.hash
, current
->hash
))
150 update_candidates(ds
, current
);
154 static void unique_in_pack(struct packed_git
*p
,
155 struct disambiguate_state
*ds
)
157 uint32_t num
, i
, first
= 0;
158 const struct object_id
*current
= NULL
;
160 if (open_pack_index(p
) || !p
->num_objects
)
163 num
= p
->num_objects
;
164 bsearch_pack(&ds
->bin_pfx
, p
, &first
);
167 * At this point, "first" is the location of the lowest object
168 * with an object name that could match "bin_pfx". See if we have
169 * 0, 1 or more objects that actually match(es).
171 for (i
= first
; i
< num
&& !ds
->ambiguous
; i
++) {
172 struct object_id oid
;
173 current
= nth_packed_object_oid(&oid
, p
, i
);
174 if (!match_sha(ds
->len
, ds
->bin_pfx
.hash
, current
->hash
))
176 update_candidates(ds
, current
);
180 static void find_short_packed_object(struct disambiguate_state
*ds
)
182 struct multi_pack_index
*m
;
183 struct packed_git
*p
;
185 for (m
= get_multi_pack_index(the_repository
); m
&& !ds
->ambiguous
;
187 unique_in_midx(m
, ds
);
188 for (p
= get_packed_git(the_repository
); p
&& !ds
->ambiguous
;
190 unique_in_pack(p
, ds
);
193 static int finish_object_disambiguation(struct disambiguate_state
*ds
,
194 struct object_id
*oid
)
197 return SHORT_NAME_AMBIGUOUS
;
199 if (!ds
->candidate_exists
)
200 return MISSING_OBJECT
;
202 if (!ds
->candidate_checked
)
204 * If this is the only candidate, there is no point
205 * calling the disambiguation hint callback.
207 * On the other hand, if the current candidate
208 * replaced an earlier candidate that did _not_ pass
209 * the disambiguation hint callback, then we do have
210 * more than one objects that match the short name
211 * given, so we should make sure this one matches;
212 * otherwise, if we discovered this one and the one
213 * that we previously discarded in the reverse order,
214 * we would end up showing different results in the
217 ds
->candidate_ok
= (!ds
->disambiguate_fn_used
||
218 ds
->fn(&ds
->candidate
, ds
->cb_data
));
220 if (!ds
->candidate_ok
)
221 return SHORT_NAME_AMBIGUOUS
;
223 oidcpy(oid
, &ds
->candidate
);
227 static int disambiguate_commit_only(const struct object_id
*oid
, void *cb_data_unused
)
229 int kind
= oid_object_info(the_repository
, oid
, NULL
);
230 return kind
== OBJ_COMMIT
;
233 static int disambiguate_committish_only(const struct object_id
*oid
, void *cb_data_unused
)
238 kind
= oid_object_info(the_repository
, oid
, NULL
);
239 if (kind
== OBJ_COMMIT
)
244 /* We need to do this the hard way... */
245 obj
= deref_tag(the_repository
, parse_object(the_repository
, oid
),
247 if (obj
&& obj
->type
== OBJ_COMMIT
)
252 static int disambiguate_tree_only(const struct object_id
*oid
, void *cb_data_unused
)
254 int kind
= oid_object_info(the_repository
, oid
, NULL
);
255 return kind
== OBJ_TREE
;
258 static int disambiguate_treeish_only(const struct object_id
*oid
, void *cb_data_unused
)
263 kind
= oid_object_info(the_repository
, oid
, NULL
);
264 if (kind
== OBJ_TREE
|| kind
== OBJ_COMMIT
)
269 /* We need to do this the hard way... */
270 obj
= deref_tag(the_repository
, parse_object(the_repository
, oid
),
272 if (obj
&& (obj
->type
== OBJ_TREE
|| obj
->type
== OBJ_COMMIT
))
277 static int disambiguate_blob_only(const struct object_id
*oid
, void *cb_data_unused
)
279 int kind
= oid_object_info(the_repository
, oid
, NULL
);
280 return kind
== OBJ_BLOB
;
283 static disambiguate_hint_fn default_disambiguate_hint
;
285 int set_disambiguate_hint_config(const char *var
, const char *value
)
287 static const struct {
289 disambiguate_hint_fn fn
;
292 { "commit", disambiguate_commit_only
},
293 { "committish", disambiguate_committish_only
},
294 { "tree", disambiguate_tree_only
},
295 { "treeish", disambiguate_treeish_only
},
296 { "blob", disambiguate_blob_only
}
301 return config_error_nonbool(var
);
303 for (i
= 0; i
< ARRAY_SIZE(hints
); i
++) {
304 if (!strcasecmp(value
, hints
[i
].name
)) {
305 default_disambiguate_hint
= hints
[i
].fn
;
310 return error("unknown hint type for '%s': %s", var
, value
);
313 static int init_object_disambiguation(const char *name
, int len
,
314 struct disambiguate_state
*ds
)
318 if (len
< MINIMUM_ABBREV
|| len
> the_hash_algo
->hexsz
)
321 memset(ds
, 0, sizeof(*ds
));
323 for (i
= 0; i
< len
;i
++) {
324 unsigned char c
= name
[i
];
326 if (c
>= '0' && c
<= '9')
328 else if (c
>= 'a' && c
<= 'f')
330 else if (c
>= 'A' && c
<='F') {
339 ds
->bin_pfx
.hash
[i
>> 1] |= val
;
343 ds
->hex_pfx
[len
] = '\0';
344 prepare_alt_odb(the_repository
);
348 static int show_ambiguous_object(const struct object_id
*oid
, void *data
)
350 const struct disambiguate_state
*ds
= data
;
351 struct strbuf desc
= STRBUF_INIT
;
354 if (ds
->fn
&& !ds
->fn(oid
, ds
->cb_data
))
357 type
= oid_object_info(the_repository
, oid
, NULL
);
358 if (type
== OBJ_COMMIT
) {
359 struct commit
*commit
= lookup_commit(the_repository
, oid
);
361 struct pretty_print_context pp
= {0};
362 pp
.date_mode
.type
= DATE_SHORT
;
363 format_commit_message(commit
, " %ad - %s", &desc
, &pp
);
365 } else if (type
== OBJ_TAG
) {
366 struct tag
*tag
= lookup_tag(the_repository
, oid
);
367 if (!parse_tag(tag
) && tag
->tag
)
368 strbuf_addf(&desc
, " %s", tag
->tag
);
372 find_unique_abbrev(oid
, DEFAULT_ABBREV
),
373 type_name(type
) ? type_name(type
) : "unknown type",
376 strbuf_release(&desc
);
380 static int collect_ambiguous(const struct object_id
*oid
, void *data
)
382 oid_array_append(data
, oid
);
386 static int sort_ambiguous(const void *a
, const void *b
)
388 int a_type
= oid_object_info(the_repository
, a
, NULL
);
389 int b_type
= oid_object_info(the_repository
, b
, NULL
);
394 * Sorts by hash within the same object type, just as
395 * oid_array_for_each_unique() would do.
397 if (a_type
== b_type
)
401 * Between object types show tags, then commits, and finally
404 * The object_type enum is commit, tree, blob, tag, but we
405 * want tag, commit, tree blob. Cleverly (perhaps too
406 * cleverly) do that with modulus, since the enum assigns 1 to
407 * commit, so tag becomes 0.
409 a_type_sort
= a_type
% 4;
410 b_type_sort
= b_type
% 4;
411 return a_type_sort
> b_type_sort
? 1 : -1;
414 static enum get_oid_result
get_short_oid(const char *name
, int len
,
415 struct object_id
*oid
,
419 struct disambiguate_state ds
;
420 int quietly
= !!(flags
& GET_OID_QUIETLY
);
422 if (init_object_disambiguation(name
, len
, &ds
) < 0)
425 if (HAS_MULTI_BITS(flags
& GET_OID_DISAMBIGUATORS
))
426 BUG("multiple get_short_oid disambiguator flags");
428 if (flags
& GET_OID_COMMIT
)
429 ds
.fn
= disambiguate_commit_only
;
430 else if (flags
& GET_OID_COMMITTISH
)
431 ds
.fn
= disambiguate_committish_only
;
432 else if (flags
& GET_OID_TREE
)
433 ds
.fn
= disambiguate_tree_only
;
434 else if (flags
& GET_OID_TREEISH
)
435 ds
.fn
= disambiguate_treeish_only
;
436 else if (flags
& GET_OID_BLOB
)
437 ds
.fn
= disambiguate_blob_only
;
439 ds
.fn
= default_disambiguate_hint
;
441 find_short_object_filename(&ds
);
442 find_short_packed_object(&ds
);
443 status
= finish_object_disambiguation(&ds
, oid
);
445 if (!quietly
&& (status
== SHORT_NAME_AMBIGUOUS
)) {
446 struct oid_array collect
= OID_ARRAY_INIT
;
448 error(_("short SHA1 %s is ambiguous"), ds
.hex_pfx
);
451 * We may still have ambiguity if we simply saw a series of
452 * candidates that did not satisfy our hint function. In
453 * that case, we still want to show them, so disable the hint
459 advise(_("The candidates are:"));
460 for_each_abbrev(ds
.hex_pfx
, collect_ambiguous
, &collect
);
461 QSORT(collect
.oid
, collect
.nr
, sort_ambiguous
);
463 if (oid_array_for_each(&collect
, show_ambiguous_object
, &ds
))
464 BUG("show_ambiguous_object shouldn't return non-zero");
465 oid_array_clear(&collect
);
471 int for_each_abbrev(const char *prefix
, each_abbrev_fn fn
, void *cb_data
)
473 struct oid_array collect
= OID_ARRAY_INIT
;
474 struct disambiguate_state ds
;
477 if (init_object_disambiguation(prefix
, strlen(prefix
), &ds
) < 0)
480 ds
.always_call_fn
= 1;
481 ds
.fn
= collect_ambiguous
;
482 ds
.cb_data
= &collect
;
483 find_short_object_filename(&ds
);
484 find_short_packed_object(&ds
);
486 ret
= oid_array_for_each_unique(&collect
, fn
, cb_data
);
487 oid_array_clear(&collect
);
492 * Return the slot of the most-significant bit set in "val". There are various
493 * ways to do this quickly with fls() or __builtin_clzl(), but speed is
494 * probably not a big deal here.
496 static unsigned msb(unsigned long val
)
504 struct min_abbrev_data
{
505 unsigned int init_len
;
506 unsigned int cur_len
;
508 const struct object_id
*oid
;
511 static inline char get_hex_char_from_oid(const struct object_id
*oid
,
514 static const char hex
[] = "0123456789abcdef";
517 return hex
[oid
->hash
[pos
>> 1] >> 4];
519 return hex
[oid
->hash
[pos
>> 1] & 0xf];
522 static int extend_abbrev_len(const struct object_id
*oid
, void *cb_data
)
524 struct min_abbrev_data
*mad
= cb_data
;
526 unsigned int i
= mad
->init_len
;
527 while (mad
->hex
[i
] && mad
->hex
[i
] == get_hex_char_from_oid(oid
, i
))
530 if (i
< GIT_MAX_RAWSZ
&& i
>= mad
->cur_len
)
531 mad
->cur_len
= i
+ 1;
536 static void find_abbrev_len_for_midx(struct multi_pack_index
*m
,
537 struct min_abbrev_data
*mad
)
540 uint32_t num
, first
= 0;
541 struct object_id oid
;
542 const struct object_id
*mad_oid
;
547 num
= m
->num_objects
;
549 match
= bsearch_midx(mad_oid
, m
, &first
);
552 * first is now the position in the packfile where we would insert
553 * mad->hash if it does not exist (or the position of mad->hash if
554 * it does exist). Hence, we consider a maximum of two objects
555 * nearby for the abbreviation length.
559 if (nth_midxed_object_oid(&oid
, m
, first
))
560 extend_abbrev_len(&oid
, mad
);
561 } else if (first
< num
- 1) {
562 if (nth_midxed_object_oid(&oid
, m
, first
+ 1))
563 extend_abbrev_len(&oid
, mad
);
566 if (nth_midxed_object_oid(&oid
, m
, first
- 1))
567 extend_abbrev_len(&oid
, mad
);
569 mad
->init_len
= mad
->cur_len
;
572 static void find_abbrev_len_for_pack(struct packed_git
*p
,
573 struct min_abbrev_data
*mad
)
576 uint32_t num
, first
= 0;
577 struct object_id oid
;
578 const struct object_id
*mad_oid
;
580 if (open_pack_index(p
) || !p
->num_objects
)
583 num
= p
->num_objects
;
585 match
= bsearch_pack(mad_oid
, p
, &first
);
588 * first is now the position in the packfile where we would insert
589 * mad->hash if it does not exist (or the position of mad->hash if
590 * it does exist). Hence, we consider a maximum of two objects
591 * nearby for the abbreviation length.
595 if (nth_packed_object_oid(&oid
, p
, first
))
596 extend_abbrev_len(&oid
, mad
);
597 } else if (first
< num
- 1) {
598 if (nth_packed_object_oid(&oid
, p
, first
+ 1))
599 extend_abbrev_len(&oid
, mad
);
602 if (nth_packed_object_oid(&oid
, p
, first
- 1))
603 extend_abbrev_len(&oid
, mad
);
605 mad
->init_len
= mad
->cur_len
;
608 static void find_abbrev_len_packed(struct min_abbrev_data
*mad
)
610 struct multi_pack_index
*m
;
611 struct packed_git
*p
;
613 for (m
= get_multi_pack_index(the_repository
); m
; m
= m
->next
)
614 find_abbrev_len_for_midx(m
, mad
);
615 for (p
= get_packed_git(the_repository
); p
; p
= p
->next
)
616 find_abbrev_len_for_pack(p
, mad
);
619 int find_unique_abbrev_r(char *hex
, const struct object_id
*oid
, int len
)
621 struct disambiguate_state ds
;
622 struct min_abbrev_data mad
;
623 struct object_id oid_ret
;
624 const unsigned hexsz
= the_hash_algo
->hexsz
;
627 unsigned long count
= approximate_object_count();
629 * Add one because the MSB only tells us the highest bit set,
630 * not including the value of all the _other_ bits (so "15"
631 * is only one off of 2^4, but the MSB is the 3rd bit.
633 len
= msb(count
) + 1;
635 * We now know we have on the order of 2^len objects, which
636 * expects a collision at 2^(len/2). But we also care about hex
637 * chars, not bits, and there are 4 bits per hex. So all
638 * together we need to divide by 2 and round up.
640 len
= DIV_ROUND_UP(len
, 2);
642 * For very small repos, we stick with our regular fallback.
644 if (len
< FALLBACK_DEFAULT_ABBREV
)
645 len
= FALLBACK_DEFAULT_ABBREV
;
648 oid_to_hex_r(hex
, oid
);
649 if (len
== hexsz
|| !len
)
657 find_abbrev_len_packed(&mad
);
659 if (init_object_disambiguation(hex
, mad
.cur_len
, &ds
) < 0)
662 ds
.fn
= extend_abbrev_len
;
663 ds
.always_call_fn
= 1;
664 ds
.cb_data
= (void *)&mad
;
666 find_short_object_filename(&ds
);
667 (void)finish_object_disambiguation(&ds
, &oid_ret
);
669 hex
[mad
.cur_len
] = 0;
673 const char *find_unique_abbrev(const struct object_id
*oid
, int len
)
676 static char hexbuffer
[4][GIT_MAX_HEXSZ
+ 1];
677 char *hex
= hexbuffer
[bufno
];
678 bufno
= (bufno
+ 1) % ARRAY_SIZE(hexbuffer
);
679 find_unique_abbrev_r(hex
, oid
, len
);
683 static int ambiguous_path(const char *path
, int len
)
688 for (cnt
= 0; cnt
< len
; cnt
++) {
708 static inline int at_mark(const char *string
, int len
,
709 const char **suffix
, int nr
)
713 for (i
= 0; i
< nr
; i
++) {
714 int suffix_len
= strlen(suffix
[i
]);
715 if (suffix_len
<= len
716 && !strncasecmp(string
, suffix
[i
], suffix_len
))
722 static inline int upstream_mark(const char *string
, int len
)
724 const char *suffix
[] = { "@{upstream}", "@{u}" };
725 return at_mark(string
, len
, suffix
, ARRAY_SIZE(suffix
));
728 static inline int push_mark(const char *string
, int len
)
730 const char *suffix
[] = { "@{push}" };
731 return at_mark(string
, len
, suffix
, ARRAY_SIZE(suffix
));
734 static enum get_oid_result
get_oid_1(const char *name
, int len
, struct object_id
*oid
, unsigned lookup_flags
);
735 static int interpret_nth_prior_checkout(const char *name
, int namelen
, struct strbuf
*buf
);
737 static int get_oid_basic(const char *str
, int len
, struct object_id
*oid
,
740 static const char *warn_msg
= "refname '%.*s' is ambiguous.";
741 static const char *object_name_msg
= N_(
742 "Git normally never creates a ref that ends with 40 hex characters\n"
743 "because it will be ignored when you just specify 40-hex. These refs\n"
744 "may be created by mistake. For example,\n"
746 " git checkout -b $br $(git rev-parse ...)\n"
748 "where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
749 "examine these refs and maybe delete them. Turn this message off by\n"
750 "running \"git config advice.objectNameWarning false\"");
751 struct object_id tmp_oid
;
752 char *real_ref
= NULL
;
754 int at
, reflog_len
, nth_prior
= 0;
756 if (len
== the_hash_algo
->hexsz
&& !get_oid_hex(str
, oid
)) {
757 if (warn_ambiguous_refs
&& warn_on_object_refname_ambiguity
) {
758 refs_found
= dwim_ref(str
, len
, &tmp_oid
, &real_ref
);
759 if (refs_found
> 0) {
760 warning(warn_msg
, len
, str
);
761 if (advice_object_name_warning
)
762 fprintf(stderr
, "%s\n", _(object_name_msg
));
769 /* basic@{time or number or -number} format to query ref-log */
771 if (len
&& str
[len
-1] == '}') {
772 for (at
= len
-4; at
>= 0; at
--) {
773 if (str
[at
] == '@' && str
[at
+1] == '{') {
774 if (str
[at
+2] == '-') {
776 /* @{-N} not at start */
781 if (!upstream_mark(str
+ at
, len
- at
) &&
782 !push_mark(str
+ at
, len
- at
)) {
783 reflog_len
= (len
-1) - (at
+2);
791 /* Accept only unambiguous ref paths. */
792 if (len
&& ambiguous_path(str
, len
))
796 struct strbuf buf
= STRBUF_INIT
;
799 if (interpret_nth_prior_checkout(str
, len
, &buf
) > 0) {
800 detached
= (buf
.len
== the_hash_algo
->hexsz
&& !get_oid_hex(buf
.buf
, oid
));
801 strbuf_release(&buf
);
807 if (!len
&& reflog_len
)
808 /* allow "@{...}" to mean the current branch reflog */
809 refs_found
= dwim_ref("HEAD", 4, oid
, &real_ref
);
811 refs_found
= dwim_log(str
, len
, oid
, &real_ref
);
813 refs_found
= dwim_ref(str
, len
, oid
, &real_ref
);
818 if (warn_ambiguous_refs
&& !(flags
& GET_OID_QUIETLY
) &&
820 !get_short_oid(str
, len
, &tmp_oid
, GET_OID_QUIETLY
)))
821 warning(warn_msg
, len
, str
);
829 /* Is it asking for N-th entry, or approxidate? */
830 for (i
= nth
= 0; 0 <= nth
&& i
< reflog_len
; i
++) {
831 char ch
= str
[at
+2+i
];
832 if ('0' <= ch
&& ch
<= '9')
833 nth
= nth
* 10 + ch
- '0';
837 if (100000000 <= nth
) {
844 char *tmp
= xstrndup(str
+ at
+ 2, reflog_len
);
845 at_time
= approxidate_careful(tmp
, &errors
);
852 if (read_ref_at(get_main_ref_store(the_repository
),
853 real_ref
, flags
, at_time
, nth
, oid
, NULL
,
854 &co_time
, &co_tz
, &co_cnt
)) {
856 if (starts_with(real_ref
, "refs/heads/")) {
858 len
= strlen(real_ref
+ 11);
866 if (!(flags
& GET_OID_QUIETLY
)) {
867 warning("Log for '%.*s' only goes "
868 "back to %s.", len
, str
,
869 show_date(co_time
, co_tz
, DATE_MODE(RFC2822
)));
872 if (flags
& GET_OID_QUIETLY
) {
875 die("Log for '%.*s' only has %d entries.",
885 static enum get_oid_result
get_parent(const char *name
, int len
,
886 struct object_id
*result
, int idx
)
888 struct object_id oid
;
889 enum get_oid_result ret
= get_oid_1(name
, len
, &oid
,
891 struct commit
*commit
;
892 struct commit_list
*p
;
896 commit
= lookup_commit_reference(the_repository
, &oid
);
897 if (parse_commit(commit
))
898 return MISSING_OBJECT
;
900 oidcpy(result
, &commit
->object
.oid
);
906 oidcpy(result
, &p
->item
->object
.oid
);
911 return MISSING_OBJECT
;
914 static enum get_oid_result
get_nth_ancestor(const char *name
, int len
,
915 struct object_id
*result
,
918 struct object_id oid
;
919 struct commit
*commit
;
922 ret
= get_oid_1(name
, len
, &oid
, GET_OID_COMMITTISH
);
925 commit
= lookup_commit_reference(the_repository
, &oid
);
927 return MISSING_OBJECT
;
929 while (generation
--) {
930 if (parse_commit(commit
) || !commit
->parents
)
931 return MISSING_OBJECT
;
932 commit
= commit
->parents
->item
;
934 oidcpy(result
, &commit
->object
.oid
);
938 struct object
*peel_to_type(const char *name
, int namelen
,
939 struct object
*o
, enum object_type expected_type
)
941 if (name
&& !namelen
)
942 namelen
= strlen(name
);
944 if (!o
|| (!o
->parsed
&& !parse_object(the_repository
, &o
->oid
)))
946 if (expected_type
== OBJ_ANY
|| o
->type
== expected_type
)
948 if (o
->type
== OBJ_TAG
)
949 o
= ((struct tag
*) o
)->tagged
;
950 else if (o
->type
== OBJ_COMMIT
)
951 o
= &(get_commit_tree(((struct commit
*)o
))->object
);
954 error("%.*s: expected %s type, but the object "
955 "dereferences to %s type",
956 namelen
, name
, type_name(expected_type
),
963 static int peel_onion(const char *name
, int len
, struct object_id
*oid
,
964 unsigned lookup_flags
)
966 struct object_id outer
;
968 unsigned int expected_type
= 0;
972 * "ref^{type}" dereferences ref repeatedly until you cannot
973 * dereference anymore, or you get an object of given type,
974 * whichever comes first. "ref^{}" means just dereference
975 * tags until you get a non-tag. "ref^0" is a shorthand for
976 * "ref^{commit}". "commit^{tree}" could be used to find the
977 * top-level tree of the given commit.
979 if (len
< 4 || name
[len
-1] != '}')
982 for (sp
= name
+ len
- 1; name
<= sp
; sp
--) {
984 if (ch
== '{' && name
< sp
&& sp
[-1] == '^')
990 sp
++; /* beginning of type name, or closing brace for empty */
991 if (starts_with(sp
, "commit}"))
992 expected_type
= OBJ_COMMIT
;
993 else if (starts_with(sp
, "tag}"))
994 expected_type
= OBJ_TAG
;
995 else if (starts_with(sp
, "tree}"))
996 expected_type
= OBJ_TREE
;
997 else if (starts_with(sp
, "blob}"))
998 expected_type
= OBJ_BLOB
;
999 else if (starts_with(sp
, "object}"))
1000 expected_type
= OBJ_ANY
;
1001 else if (sp
[0] == '}')
1002 expected_type
= OBJ_NONE
;
1003 else if (sp
[0] == '/')
1004 expected_type
= OBJ_COMMIT
;
1008 lookup_flags
&= ~GET_OID_DISAMBIGUATORS
;
1009 if (expected_type
== OBJ_COMMIT
)
1010 lookup_flags
|= GET_OID_COMMITTISH
;
1011 else if (expected_type
== OBJ_TREE
)
1012 lookup_flags
|= GET_OID_TREEISH
;
1014 if (get_oid_1(name
, sp
- name
- 2, &outer
, lookup_flags
))
1017 o
= parse_object(the_repository
, &outer
);
1020 if (!expected_type
) {
1021 o
= deref_tag(the_repository
, o
, name
, sp
- name
- 2);
1022 if (!o
|| (!o
->parsed
&& !parse_object(the_repository
, &o
->oid
)))
1024 oidcpy(oid
, &o
->oid
);
1029 * At this point, the syntax look correct, so
1030 * if we do not get the needed object, we should
1033 o
= peel_to_type(name
, len
, o
, expected_type
);
1037 oidcpy(oid
, &o
->oid
);
1039 /* "$commit^{/foo}" */
1042 struct commit_list
*list
= NULL
;
1045 * $commit^{/}. Some regex implementation may reject.
1046 * We don't need regex anyway. '' pattern always matches.
1051 prefix
= xstrndup(sp
+ 1, name
+ len
- 1 - (sp
+ 1));
1052 commit_list_insert((struct commit
*)o
, &list
);
1053 ret
= get_oid_oneline(prefix
, oid
, list
);
1060 static int get_describe_name(const char *name
, int len
, struct object_id
*oid
)
1063 unsigned flags
= GET_OID_QUIETLY
| GET_OID_COMMIT
;
1065 for (cp
= name
+ len
- 1; name
+ 2 <= cp
; cp
--) {
1067 if (!isxdigit(ch
)) {
1068 /* We must be looking at g in "SOMETHING-g"
1069 * for it to be describe output.
1071 if (ch
== 'g' && cp
[-1] == '-') {
1074 return get_short_oid(cp
, len
, oid
, flags
);
1081 static enum get_oid_result
get_oid_1(const char *name
, int len
,
1082 struct object_id
*oid
,
1083 unsigned lookup_flags
)
1085 int ret
, has_suffix
;
1089 * "name~3" is "name^^^", "name~" is "name~1", and "name^" is "name^1".
1092 for (cp
= name
+ len
- 1; name
<= cp
; cp
--) {
1094 if ('0' <= ch
&& ch
<= '9')
1096 if (ch
== '~' || ch
== '^')
1103 int len1
= cp
- name
;
1105 while (cp
< name
+ len
)
1106 num
= num
* 10 + *cp
++ - '0';
1107 if (!num
&& len1
== len
- 1)
1109 if (has_suffix
== '^')
1110 return get_parent(name
, len1
, oid
, num
);
1111 /* else if (has_suffix == '~') -- goes without saying */
1112 return get_nth_ancestor(name
, len1
, oid
, num
);
1115 ret
= peel_onion(name
, len
, oid
, lookup_flags
);
1119 ret
= get_oid_basic(name
, len
, oid
, lookup_flags
);
1123 /* It could be describe output that is "SOMETHING-gXXXX" */
1124 ret
= get_describe_name(name
, len
, oid
);
1128 return get_short_oid(name
, len
, oid
, lookup_flags
);
1132 * This interprets names like ':/Initial revision of "git"' by searching
1133 * through history and returning the first commit whose message starts
1134 * the given regular expression.
1136 * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
1138 * For a literal '!' character at the beginning of a pattern, you have to repeat
1139 * that, like: ':/!!foo'
1141 * For future extension, all other sequences beginning with ':/!' are reserved.
1144 /* Remember to update object flag allocation in object.h */
1145 #define ONELINE_SEEN (1u<<20)
1147 static int handle_one_ref(const char *path
, const struct object_id
*oid
,
1148 int flag
, void *cb_data
)
1150 struct commit_list
**list
= cb_data
;
1151 struct object
*object
= parse_object(the_repository
, oid
);
1154 if (object
->type
== OBJ_TAG
) {
1155 object
= deref_tag(the_repository
, object
, path
,
1160 if (object
->type
!= OBJ_COMMIT
)
1162 commit_list_insert((struct commit
*)object
, list
);
1166 static int get_oid_oneline(const char *prefix
, struct object_id
*oid
,
1167 struct commit_list
*list
)
1169 struct commit_list
*backup
= NULL
, *l
;
1174 if (prefix
[0] == '!') {
1177 if (prefix
[0] == '-') {
1180 } else if (prefix
[0] != '!') {
1185 if (regcomp(®ex
, prefix
, REG_EXTENDED
))
1188 for (l
= list
; l
; l
= l
->next
) {
1189 l
->item
->object
.flags
|= ONELINE_SEEN
;
1190 commit_list_insert(l
->item
, &backup
);
1193 const char *p
, *buf
;
1194 struct commit
*commit
;
1197 commit
= pop_most_recent_commit(&list
, ONELINE_SEEN
);
1198 if (!parse_object(the_repository
, &commit
->object
.oid
))
1200 buf
= get_commit_buffer(commit
, NULL
);
1201 p
= strstr(buf
, "\n\n");
1202 matches
= negative
^ (p
&& !regexec(®ex
, p
+ 2, 0, NULL
, 0));
1203 unuse_commit_buffer(commit
, buf
);
1206 oidcpy(oid
, &commit
->object
.oid
);
1212 free_commit_list(list
);
1213 for (l
= backup
; l
; l
= l
->next
)
1214 clear_commit_marks(l
->item
, ONELINE_SEEN
);
1215 free_commit_list(backup
);
1216 return found
? 0 : -1;
1219 struct grab_nth_branch_switch_cbdata
{
1224 static int grab_nth_branch_switch(struct object_id
*ooid
, struct object_id
*noid
,
1225 const char *email
, timestamp_t timestamp
, int tz
,
1226 const char *message
, void *cb_data
)
1228 struct grab_nth_branch_switch_cbdata
*cb
= cb_data
;
1229 const char *match
= NULL
, *target
= NULL
;
1232 if (skip_prefix(message
, "checkout: moving from ", &match
))
1233 target
= strstr(match
, " to ");
1235 if (!match
|| !target
)
1237 if (--(cb
->remaining
) == 0) {
1238 len
= target
- match
;
1239 strbuf_reset(&cb
->buf
);
1240 strbuf_add(&cb
->buf
, match
, len
);
1241 return 1; /* we are done */
1247 * Parse @{-N} syntax, return the number of characters parsed
1248 * if successful; otherwise signal an error with negative value.
1250 static int interpret_nth_prior_checkout(const char *name
, int namelen
,
1255 struct grab_nth_branch_switch_cbdata cb
;
1261 if (name
[0] != '@' || name
[1] != '{' || name
[2] != '-')
1263 brace
= memchr(name
, '}', namelen
);
1266 nth
= strtol(name
+ 3, &num_end
, 10);
1267 if (num_end
!= brace
)
1272 strbuf_init(&cb
.buf
, 20);
1275 if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch
, &cb
)) {
1277 strbuf_addbuf(buf
, &cb
.buf
);
1278 retval
= brace
- name
+ 1;
1281 strbuf_release(&cb
.buf
);
1285 int get_oid_mb(const char *name
, struct object_id
*oid
)
1287 struct commit
*one
, *two
;
1288 struct commit_list
*mbs
;
1289 struct object_id oid_tmp
;
1293 dots
= strstr(name
, "...");
1295 return get_oid(name
, oid
);
1297 st
= get_oid("HEAD", &oid_tmp
);
1300 strbuf_init(&sb
, dots
- name
);
1301 strbuf_add(&sb
, name
, dots
- name
);
1302 st
= get_oid_committish(sb
.buf
, &oid_tmp
);
1303 strbuf_release(&sb
);
1307 one
= lookup_commit_reference_gently(the_repository
, &oid_tmp
, 0);
1311 if (get_oid_committish(dots
[3] ? (dots
+ 3) : "HEAD", &oid_tmp
))
1313 two
= lookup_commit_reference_gently(the_repository
, &oid_tmp
, 0);
1316 mbs
= get_merge_bases(one
, two
);
1317 if (!mbs
|| mbs
->next
)
1321 oidcpy(oid
, &mbs
->item
->object
.oid
);
1323 free_commit_list(mbs
);
1327 /* parse @something syntax, when 'something' is not {.*} */
1328 static int interpret_empty_at(const char *name
, int namelen
, int len
, struct strbuf
*buf
)
1332 if (len
|| name
[1] == '{')
1335 /* make sure it's a single @, or @@{.*}, not @foo */
1336 next
= memchr(name
+ len
+ 1, '@', namelen
- len
- 1);
1337 if (next
&& next
[1] != '{')
1340 next
= name
+ namelen
;
1341 if (next
!= name
+ 1)
1345 strbuf_add(buf
, "HEAD", 4);
1349 static int reinterpret(const char *name
, int namelen
, int len
,
1350 struct strbuf
*buf
, unsigned allowed
)
1352 /* we have extra data, which might need further processing */
1353 struct strbuf tmp
= STRBUF_INIT
;
1354 int used
= buf
->len
;
1357 strbuf_add(buf
, name
+ len
, namelen
- len
);
1358 ret
= interpret_branch_name(buf
->buf
, buf
->len
, &tmp
, allowed
);
1359 /* that data was not interpreted, remove our cruft */
1361 strbuf_setlen(buf
, used
);
1365 strbuf_addbuf(buf
, &tmp
);
1366 strbuf_release(&tmp
);
1367 /* tweak for size of {-N} versus expanded ref name */
1368 return ret
- used
+ len
;
1371 static void set_shortened_ref(struct strbuf
*buf
, const char *ref
)
1373 char *s
= shorten_unambiguous_ref(ref
, 0);
1375 strbuf_addstr(buf
, s
);
1379 static int branch_interpret_allowed(const char *refname
, unsigned allowed
)
1384 if ((allowed
& INTERPRET_BRANCH_LOCAL
) &&
1385 starts_with(refname
, "refs/heads/"))
1387 if ((allowed
& INTERPRET_BRANCH_REMOTE
) &&
1388 starts_with(refname
, "refs/remotes/"))
1394 static int interpret_branch_mark(const char *name
, int namelen
,
1395 int at
, struct strbuf
*buf
,
1396 int (*get_mark
)(const char *, int),
1397 const char *(*get_data
)(struct branch
*,
1402 struct branch
*branch
;
1403 struct strbuf err
= STRBUF_INIT
;
1406 len
= get_mark(name
+ at
, namelen
- at
);
1410 if (memchr(name
, ':', at
))
1414 char *name_str
= xmemdupz(name
, at
);
1415 branch
= branch_get(name_str
);
1418 branch
= branch_get(NULL
);
1420 value
= get_data(branch
, &err
);
1424 if (!branch_interpret_allowed(value
, allowed
))
1427 set_shortened_ref(buf
, value
);
1431 int repo_interpret_branch_name(struct repository
*r
,
1432 const char *name
, int namelen
,
1440 if (r
!= the_repository
)
1441 BUG("interpret_branch_name() does not really use 'r' yet");
1443 namelen
= strlen(name
);
1445 if (!allowed
|| (allowed
& INTERPRET_BRANCH_LOCAL
)) {
1446 len
= interpret_nth_prior_checkout(name
, namelen
, buf
);
1448 return len
; /* syntax Ok, not enough switches */
1449 } else if (len
> 0) {
1451 return len
; /* consumed all */
1453 return reinterpret(name
, namelen
, len
, buf
, allowed
);
1458 (at
= memchr(start
, '@', namelen
- (start
- name
)));
1461 if (!allowed
|| (allowed
& INTERPRET_BRANCH_HEAD
)) {
1462 len
= interpret_empty_at(name
, namelen
, at
- name
, buf
);
1464 return reinterpret(name
, namelen
, len
, buf
,
1468 len
= interpret_branch_mark(name
, namelen
, at
- name
, buf
,
1469 upstream_mark
, branch_get_upstream
,
1474 len
= interpret_branch_mark(name
, namelen
, at
- name
, buf
,
1475 push_mark
, branch_get_push
,
1484 void strbuf_branchname(struct strbuf
*sb
, const char *name
, unsigned allowed
)
1486 int len
= strlen(name
);
1487 int used
= interpret_branch_name(name
, len
, sb
, allowed
);
1491 strbuf_add(sb
, name
+ used
, len
- used
);
1494 int strbuf_check_branch_ref(struct strbuf
*sb
, const char *name
)
1496 if (startup_info
->have_repository
)
1497 strbuf_branchname(sb
, name
, INTERPRET_BRANCH_LOCAL
);
1499 strbuf_addstr(sb
, name
);
1502 * This splice must be done even if we end up rejecting the
1503 * name; builtin/branch.c::copy_or_rename_branch() still wants
1504 * to see what the name expanded to so that "branch -m" can be
1505 * used as a tool to correct earlier mistakes.
1507 strbuf_splice(sb
, 0, 0, "refs/heads/", 11);
1510 !strcmp(sb
->buf
, "refs/heads/HEAD"))
1513 return check_refname_format(sb
->buf
, 0);
1517 * This is like "get_oid_basic()", except it allows "object ID expressions",
1518 * notably "xyz^" for "parent of xyz"
1520 int get_oid(const char *name
, struct object_id
*oid
)
1522 struct object_context unused
;
1523 return get_oid_with_context(the_repository
, name
, 0, oid
, &unused
);
1528 * Many callers know that the user meant to name a commit-ish by
1529 * syntactical positions where the object name appears. Calling this
1530 * function allows the machinery to disambiguate shorter-than-unique
1531 * abbreviated object names between commit-ish and others.
1533 * Note that this does NOT error out when the named object is not a
1534 * commit-ish. It is merely to give a hint to the disambiguation
1537 int get_oid_committish(const char *name
, struct object_id
*oid
)
1539 struct object_context unused
;
1540 return get_oid_with_context(the_repository
,
1541 name
, GET_OID_COMMITTISH
,
1545 int get_oid_treeish(const char *name
, struct object_id
*oid
)
1547 struct object_context unused
;
1548 return get_oid_with_context(the_repository
,
1549 name
, GET_OID_TREEISH
,
1553 int get_oid_commit(const char *name
, struct object_id
*oid
)
1555 struct object_context unused
;
1556 return get_oid_with_context(the_repository
,
1557 name
, GET_OID_COMMIT
,
1561 int get_oid_tree(const char *name
, struct object_id
*oid
)
1563 struct object_context unused
;
1564 return get_oid_with_context(the_repository
,
1569 int get_oid_blob(const char *name
, struct object_id
*oid
)
1571 struct object_context unused
;
1572 return get_oid_with_context(the_repository
,
1577 /* Must be called only when object_name:filename doesn't exist. */
1578 static void diagnose_invalid_oid_path(const char *prefix
,
1579 const char *filename
,
1580 const struct object_id
*tree_oid
,
1581 const char *object_name
,
1582 int object_name_len
)
1584 struct object_id oid
;
1590 if (file_exists(filename
))
1591 die("Path '%s' exists on disk, but not in '%.*s'.",
1592 filename
, object_name_len
, object_name
);
1593 if (is_missing_file_error(errno
)) {
1594 char *fullname
= xstrfmt("%s%s", prefix
, filename
);
1596 if (!get_tree_entry(tree_oid
, fullname
, &oid
, &mode
)) {
1597 die("Path '%s' exists, but not '%s'.\n"
1598 "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
1601 object_name_len
, object_name
,
1603 object_name_len
, object_name
,
1606 die("Path '%s' does not exist in '%.*s'",
1607 filename
, object_name_len
, object_name
);
1611 /* Must be called only when :stage:filename doesn't exist. */
1612 static void diagnose_invalid_index_path(struct index_state
*istate
,
1615 const char *filename
)
1617 const struct cache_entry
*ce
;
1619 unsigned namelen
= strlen(filename
);
1620 struct strbuf fullname
= STRBUF_INIT
;
1625 /* Wrong stage number? */
1626 pos
= index_name_pos(istate
, filename
, namelen
);
1629 if (pos
< istate
->cache_nr
) {
1630 ce
= istate
->cache
[pos
];
1631 if (ce_namelen(ce
) == namelen
&&
1632 !memcmp(ce
->name
, filename
, namelen
))
1633 die("Path '%s' is in the index, but not at stage %d.\n"
1634 "Did you mean ':%d:%s'?",
1636 ce_stage(ce
), filename
);
1639 /* Confusion between relative and absolute filenames? */
1640 strbuf_addstr(&fullname
, prefix
);
1641 strbuf_addstr(&fullname
, filename
);
1642 pos
= index_name_pos(istate
, fullname
.buf
, fullname
.len
);
1645 if (pos
< istate
->cache_nr
) {
1646 ce
= istate
->cache
[pos
];
1647 if (ce_namelen(ce
) == fullname
.len
&&
1648 !memcmp(ce
->name
, fullname
.buf
, fullname
.len
))
1649 die("Path '%s' is in the index, but not '%s'.\n"
1650 "Did you mean ':%d:%s' aka ':%d:./%s'?",
1651 fullname
.buf
, filename
,
1652 ce_stage(ce
), fullname
.buf
,
1653 ce_stage(ce
), filename
);
1656 if (file_exists(filename
))
1657 die("Path '%s' exists on disk, but not in the index.", filename
);
1658 if (is_missing_file_error(errno
))
1659 die("Path '%s' does not exist (neither on disk nor in the index).",
1662 strbuf_release(&fullname
);
1666 static char *resolve_relative_path(const char *rel
)
1668 if (!starts_with(rel
, "./") && !starts_with(rel
, "../"))
1671 if (!is_inside_work_tree())
1672 die("relative path syntax can't be used outside working tree.");
1674 /* die() inside prefix_path() if resolved path is outside worktree */
1675 return prefix_path(startup_info
->prefix
,
1676 startup_info
->prefix
? strlen(startup_info
->prefix
) : 0,
1680 static enum get_oid_result
get_oid_with_context_1(struct repository
*repo
,
1684 struct object_id
*oid
,
1685 struct object_context
*oc
)
1687 int ret
, bracket_depth
;
1688 int namelen
= strlen(name
);
1690 int only_to_die
= flags
& GET_OID_ONLY_TO_DIE
;
1693 flags
|= GET_OID_QUIETLY
;
1695 memset(oc
, 0, sizeof(*oc
));
1696 oc
->mode
= S_IFINVALID
;
1697 strbuf_init(&oc
->symlink_path
, 0);
1698 ret
= get_oid_1(name
, namelen
, oid
, flags
);
1702 * sha1:path --> object name of path in ent sha1
1703 * :path -> object name of absolute path in index
1704 * :./path -> object name of path relative to cwd in index
1705 * :[0-3]:path -> object name of path in index at stage
1706 * :/foo -> recent commit matching foo
1708 if (name
[0] == ':') {
1710 const struct cache_entry
*ce
;
1711 char *new_path
= NULL
;
1713 if (!only_to_die
&& namelen
> 2 && name
[1] == '/') {
1714 struct commit_list
*list
= NULL
;
1716 for_each_ref(handle_one_ref
, &list
);
1717 head_ref(handle_one_ref
, &list
);
1718 commit_list_sort_by_date(&list
);
1719 return get_oid_oneline(name
+ 2, oid
, list
);
1723 name
[1] < '0' || '3' < name
[1])
1726 stage
= name
[1] - '0';
1729 new_path
= resolve_relative_path(cp
);
1731 namelen
= namelen
- (cp
- name
);
1734 namelen
= strlen(cp
);
1737 if (flags
& GET_OID_RECORD_PATH
)
1738 oc
->path
= xstrdup(cp
);
1740 if (!repo
->index
->cache
)
1741 repo_read_index(the_repository
);
1742 pos
= index_name_pos(repo
->index
, cp
, namelen
);
1745 while (pos
< repo
->index
->cache_nr
) {
1746 ce
= repo
->index
->cache
[pos
];
1747 if (ce_namelen(ce
) != namelen
||
1748 memcmp(ce
->name
, cp
, namelen
))
1750 if (ce_stage(ce
) == stage
) {
1751 oidcpy(oid
, &ce
->oid
);
1752 oc
->mode
= ce
->ce_mode
;
1758 if (only_to_die
&& name
[1] && name
[1] != '/')
1759 diagnose_invalid_index_path(repo
->index
, stage
, prefix
, cp
);
1763 for (cp
= name
, bracket_depth
= 0; *cp
; cp
++) {
1766 else if (bracket_depth
&& *cp
== '}')
1768 else if (!bracket_depth
&& *cp
== ':')
1772 struct object_id tree_oid
;
1773 int len
= cp
- name
;
1774 unsigned sub_flags
= flags
;
1776 sub_flags
&= ~GET_OID_DISAMBIGUATORS
;
1777 sub_flags
|= GET_OID_TREEISH
;
1779 if (!get_oid_1(name
, len
, &tree_oid
, sub_flags
)) {
1780 const char *filename
= cp
+1;
1781 char *new_filename
= NULL
;
1783 new_filename
= resolve_relative_path(filename
);
1785 filename
= new_filename
;
1786 if (flags
& GET_OID_FOLLOW_SYMLINKS
) {
1787 ret
= get_tree_entry_follow_symlinks(&tree_oid
,
1788 filename
, oid
, &oc
->symlink_path
,
1791 ret
= get_tree_entry(&tree_oid
, filename
, oid
,
1793 if (ret
&& only_to_die
) {
1794 diagnose_invalid_oid_path(prefix
,
1800 if (flags
& GET_OID_RECORD_PATH
)
1801 oc
->path
= xstrdup(filename
);
1807 die("Invalid object name '%.*s'.", len
, name
);
1814 * Call this function when you know "name" given by the end user must
1815 * name an object but it doesn't; the function _may_ die with a better
1816 * diagnostic message than "no such object 'name'", e.g. "Path 'doc' does not
1817 * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
1818 * you have a chance to diagnose the error further.
1820 void maybe_die_on_misspelt_object_name(const char *name
, const char *prefix
)
1822 struct object_context oc
;
1823 struct object_id oid
;
1824 get_oid_with_context_1(the_repository
, name
, GET_OID_ONLY_TO_DIE
,
1828 enum get_oid_result
get_oid_with_context(struct repository
*repo
,
1831 struct object_id
*oid
,
1832 struct object_context
*oc
)
1834 if (flags
& GET_OID_FOLLOW_SYMLINKS
&& flags
& GET_OID_ONLY_TO_DIE
)
1835 BUG("incompatible flags for get_sha1_with_context");
1836 return get_oid_with_context_1(repo
, str
, flags
, NULL
, oid
, oc
);