Skip to content

Commit f87dd21

Browse files
committed
Merge branch 'maint'
* maint: SunOS grep does not understand -C<n> nor -e Fix export_marks() error handling. git branch: clean up detached branch handling git branch: avoid unnecessary object lookups git branch: fix performance problem do_one_ref(): null_sha1 check is not about broken ref Conflicts: Makefile
2 parents 4aacaeb + 01ae841 commit f87dd21

4 files changed

Lines changed: 53 additions & 33 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ ifeq ($(uname_S),SunOS)
728728
NO_MKDTEMP = YesPlease
729729
NO_MKSTEMPS = YesPlease
730730
NO_REGEX = YesPlease
731+
NO_EXTERNAL_GREP = YesPlease
731732
ifeq ($(uname_R),5.7)
732733
NEEDS_RESOLV = YesPlease
733734
NO_IPV6 = YesPlease

builtin-branch.c

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct ref_item {
191191

192192
struct ref_list {
193193
struct rev_info revs;
194-
int index, alloc, maxwidth;
194+
int index, alloc, maxwidth, verbose, abbrev;
195195
struct ref_item *list;
196196
struct commit_list *with_commit;
197197
int kinds;
@@ -240,21 +240,24 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
240240
if (ARRAY_SIZE(ref_kind) <= i)
241241
return 0;
242242

243-
commit = lookup_commit_reference_gently(sha1, 1);
244-
if (!commit)
245-
return error("branch '%s' does not point at a commit", refname);
246-
247-
/* Filter with with_commit if specified */
248-
if (!is_descendant_of(commit, ref_list->with_commit))
249-
return 0;
250-
251243
/* Don't add types the caller doesn't want */
252244
if ((kind & ref_list->kinds) == 0)
253245
return 0;
254246

255-
if (merge_filter != NO_FILTER)
256-
add_pending_object(&ref_list->revs,
257-
(struct object *)commit, refname);
247+
commit = NULL;
248+
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
249+
commit = lookup_commit_reference_gently(sha1, 1);
250+
if (!commit)
251+
return error("branch '%s' does not point at a commit", refname);
252+
253+
/* Filter with with_commit if specified */
254+
if (!is_descendant_of(commit, ref_list->with_commit))
255+
return 0;
256+
257+
if (merge_filter != NO_FILTER)
258+
add_pending_object(&ref_list->revs,
259+
(struct object *)commit, refname);
260+
}
258261

259262
/* Resize buffer */
260263
if (ref_list->index >= ref_list->alloc) {
@@ -415,18 +418,38 @@ static int calc_maxwidth(struct ref_list *refs)
415418
return w;
416419
}
417420

421+
422+
static void show_detached(struct ref_list *ref_list)
423+
{
424+
struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);
425+
426+
if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
427+
struct ref_item item;
428+
item.name = xstrdup("(no branch)");
429+
item.len = strlen(item.name);
430+
item.kind = REF_LOCAL_BRANCH;
431+
item.dest = NULL;
432+
item.commit = head_commit;
433+
if (item.len > ref_list->maxwidth)
434+
ref_list->maxwidth = item.len;
435+
print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
436+
free(item.name);
437+
}
438+
}
439+
418440
static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
419441
{
420442
int i;
421443
struct ref_list ref_list;
422-
struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);
423444

424445
memset(&ref_list, 0, sizeof(ref_list));
425446
ref_list.kinds = kinds;
447+
ref_list.verbose = verbose;
448+
ref_list.abbrev = abbrev;
426449
ref_list.with_commit = with_commit;
427450
if (merge_filter != NO_FILTER)
428451
init_revisions(&ref_list.revs, NULL);
429-
for_each_ref(append_ref, &ref_list);
452+
for_each_rawref(append_ref, &ref_list);
430453
if (merge_filter != NO_FILTER) {
431454
struct commit *filter;
432455
filter = lookup_commit_reference_gently(merge_filter_ref, 0);
@@ -442,19 +465,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
442465
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
443466

444467
detached = (detached && (kinds & REF_LOCAL_BRANCH));
445-
if (detached && head_commit &&
446-
is_descendant_of(head_commit, with_commit)) {
447-
struct ref_item item;
448-
item.name = xstrdup("(no branch)");
449-
item.len = strlen(item.name);
450-
item.kind = REF_LOCAL_BRANCH;
451-
item.dest = NULL;
452-
item.commit = head_commit;
453-
if (item.len > ref_list.maxwidth)
454-
ref_list.maxwidth = item.len;
455-
print_ref_item(&item, ref_list.maxwidth, verbose, abbrev, 1, "");
456-
free(item.name);
457-
}
468+
if (detached)
469+
show_detached(&ref_list);
458470

459471
for (i = 0; i < ref_list.index; i++) {
460472
int current = !detached &&

builtin-fast-export.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,27 @@ static void export_marks(char *file)
428428
uint32_t mark;
429429
struct object_decoration *deco = idnums.hash;
430430
FILE *f;
431+
int e = 0;
431432

432433
f = fopen(file, "w");
433434
if (!f)
434-
error("Unable to open marks file %s for writing", file);
435+
error("Unable to open marks file %s for writing.", file);
435436

436437
for (i = 0; i < idnums.size; i++) {
437438
if (deco->base && deco->base->type == 1) {
438439
mark = ptr_to_mark(deco->decoration);
439-
fprintf(f, ":%"PRIu32" %s\n", mark,
440-
sha1_to_hex(deco->base->sha1));
440+
if (fprintf(f, ":%"PRIu32" %s\n", mark,
441+
sha1_to_hex(deco->base->sha1)) < 0) {
442+
e = 1;
443+
break;
444+
}
441445
}
442446
deco++;
443447
}
444448

445-
if (ferror(f) || fclose(f))
449+
e |= ferror(f);
450+
e |= fclose(f);
451+
if (e)
446452
error("Unable to write marks file %s.", file);
447453
}
448454

refs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
531531
{
532532
if (strncmp(base, entry->name, trim))
533533
return 0;
534+
/* Is this a "negative ref" that represents a deleted ref? */
535+
if (is_null_sha1(entry->sha1))
536+
return 0;
534537
if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
535-
if (is_null_sha1(entry->sha1))
536-
return 0;
537538
if (!has_sha1_file(entry->sha1)) {
538539
error("%s does not point to a valid object!", entry->name);
539540
return 0;

0 commit comments

Comments
 (0)