Skip to content

Commit 68fd3b3

Browse files
committed
Merge branch 'ps/fetch-optim-with-commit-graph'
A couple of optimization to "git fetch". * ps/fetch-optim-with-commit-graph: fetch: skip computing output width when not printing anything fetch-pack: use commit-graph when computing cutoff
2 parents fb5e858 + b18aaaa commit 68fd3b3

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

builtin/fetch.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
10941094
struct ref *rm;
10951095
char *url;
10961096
int want_status;
1097-
int summary_width = transport_summary_width(ref_map);
1097+
int summary_width = 0;
10981098

10991099
rc = open_fetch_head(&fetch_head);
11001100
if (rc)
11011101
return -1;
11021102

1103+
if (verbosity >= 0)
1104+
summary_width = transport_summary_width(ref_map);
1105+
11031106
if (raw_url)
11041107
url = transport_anonymize_url(raw_url);
11051108
else
@@ -1345,7 +1348,6 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map,
13451348
int url_len, i, result = 0;
13461349
struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map);
13471350
char *url;
1348-
int summary_width = transport_summary_width(stale_refs);
13491351
const char *dangling_msg = dry_run
13501352
? _(" (%s will become dangling)")
13511353
: _(" (%s has become dangling)");
@@ -1374,6 +1376,8 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map,
13741376
}
13751377

13761378
if (verbosity >= 0) {
1379+
int summary_width = transport_summary_width(stale_refs);
1380+
13771381
for (ref = stale_refs; ref; ref = ref->next) {
13781382
struct strbuf sb = STRBUF_INIT;
13791383
if (!shown_url) {

fetch-pack.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -696,26 +696,30 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
696696

697697
trace2_region_enter("fetch-pack", "parse_remote_refs_and_find_cutoff", NULL);
698698
for (ref = *refs; ref; ref = ref->next) {
699-
struct object *o;
699+
struct commit *commit;
700+
701+
commit = lookup_commit_in_graph(the_repository, &ref->old_oid);
702+
if (!commit) {
703+
struct object *o;
700704

701-
if (!has_object_file_with_flags(&ref->old_oid,
705+
if (!has_object_file_with_flags(&ref->old_oid,
702706
OBJECT_INFO_QUICK |
703-
OBJECT_INFO_SKIP_FETCH_OBJECT))
704-
continue;
705-
o = parse_object(the_repository, &ref->old_oid);
706-
if (!o)
707-
continue;
707+
OBJECT_INFO_SKIP_FETCH_OBJECT))
708+
continue;
709+
o = parse_object(the_repository, &ref->old_oid);
710+
if (!o || o->type != OBJ_COMMIT)
711+
continue;
712+
713+
commit = (struct commit *)o;
714+
}
708715

709716
/*
710717
* We already have it -- which may mean that we were
711718
* in sync with the other side at some time after
712719
* that (it is OK if we guess wrong here).
713720
*/
714-
if (o->type == OBJ_COMMIT) {
715-
struct commit *commit = (struct commit *)o;
716-
if (!cutoff || cutoff < commit->date)
717-
cutoff = commit->date;
718-
}
721+
if (!cutoff || cutoff < commit->date)
722+
cutoff = commit->date;
719723
}
720724
trace2_region_leave("fetch-pack", "parse_remote_refs_and_find_cutoff", NULL);
721725

0 commit comments

Comments
 (0)