Skip to content

Commit f767349

Browse files
peffgitster
authored andcommitted
more terse push output
This changes the output of send-pack to match the new, more terse fetch output. It looks like this: To git://host.tld/path/to/repo + f3325dc...3b91d1c hasforce -> mirror/hasforce (forced update) f3325dc..bb022dc master -> mirror/master ! [rejected] needsforce -> mirror/needsforce (non-fast forward) * [new branch] newbranch -> mirror/newbranch * [new tag] v1.0 -> v1.0 instead of: updating 'refs/heads/mirror/hasforce' using 'refs/heads/hasforce' from f3325dca9c4a34d74012c0e159254f454930cec7 to 3b91d1c310ca9d7b547b85466dd876e143498304 updating 'refs/heads/mirror/master' using 'refs/heads/master' from f3325dca9c4a34d74012c0e159254f454930cec7 to bb022dc363d5c2aa9aa3026beb9706d44fbe1328 error: remote 'refs/heads/mirror/needsforce' is not an ancestor of local 'refs/heads/needsforce'. Maybe you are not up-to-date and need to pull first? updating 'refs/heads/mirror/newbranch' using 'refs/heads/newbranch' from 0000000000000000000000000000000000000000 to 3b91d1c310ca9d7b547b85466dd876e143498304 updating 'refs/tags/v1.0' from 0000000000000000000000000000000000000000 to bb022dc363d5c2aa9aa3026beb9706d44fbe1328 Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 96249c0 commit f767349

File tree

1 file changed

+64
-17
lines changed

1 file changed

+64
-17
lines changed

builtin-send-pack.c

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,26 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
206206
}
207207
}
208208

209-
static int do_send_pack(int in, int out, struct remote *remote, int nr_refspec, const char **refspec)
209+
static const char *prettify_ref(const char *name)
210+
{
211+
return name + (
212+
!prefixcmp(name, "refs/heads/") ? 11 :
213+
!prefixcmp(name, "refs/tags/") ? 10 :
214+
!prefixcmp(name, "refs/remotes/") ? 13 :
215+
0);
216+
}
217+
218+
#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
219+
220+
static int do_send_pack(int in, int out, struct remote *remote, const char *dest, int nr_refspec, const char **refspec)
210221
{
211222
struct ref *ref;
212223
int new_refs;
213224
int ret = 0;
214225
int ask_for_status_report = 0;
215226
int allow_deleting_refs = 0;
216227
int expect_status_report = 0;
228+
int shown_dest = 0;
217229

218230
/* No funny business with the matcher */
219231
remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL);
@@ -245,21 +257,33 @@ static int do_send_pack(int in, int out, struct remote *remote, int nr_refspec,
245257
for (ref = remote_refs; ref; ref = ref->next) {
246258
char old_hex[60], *new_hex;
247259
int will_delete_ref;
260+
const char *pretty_ref;
261+
const char *pretty_peer;
248262

249263
if (!ref->peer_ref)
250264
continue;
251265

266+
if (!shown_dest) {
267+
fprintf(stderr, "To %s\n", dest);
268+
shown_dest = 1;
269+
}
270+
271+
pretty_ref = prettify_ref(ref->name);
272+
pretty_peer = prettify_ref(ref->peer_ref->name);
252273

253274
will_delete_ref = is_null_sha1(ref->peer_ref->new_sha1);
254275
if (will_delete_ref && !allow_deleting_refs) {
255-
error("remote does not support deleting refs");
276+
fprintf(stderr, " ! %-*s %s (remote does not support deleting refs)\n",
277+
SUMMARY_WIDTH, "[rejected]", pretty_ref);
256278
ret = -2;
257279
continue;
258280
}
259281
if (!will_delete_ref &&
260282
!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
261283
if (args.verbose)
262-
fprintf(stderr, "'%s': up-to-date\n", ref->name);
284+
fprintf(stderr, " = %-*s %s -> %s\n",
285+
SUMMARY_WIDTH, "[up to date]",
286+
pretty_peer, pretty_ref);
263287
continue;
264288
}
265289

@@ -296,12 +320,9 @@ static int do_send_pack(int in, int out, struct remote *remote, int nr_refspec,
296320
* commits at the remote end and likely
297321
* we were not up to date to begin with.
298322
*/
299-
error("remote '%s' is not a strict "
300-
"subset of local ref '%s'. "
301-
"maybe you are not up-to-date and "
302-
"need to pull first?",
303-
ref->name,
304-
ref->peer_ref->name);
323+
fprintf(stderr, " ! %-*s %s -> %s (non-fast forward)\n",
324+
SUMMARY_WIDTH, "[rejected]",
325+
pretty_peer, pretty_ref);
305326
ret = -2;
306327
continue;
307328
}
@@ -325,14 +346,40 @@ static int do_send_pack(int in, int out, struct remote *remote, int nr_refspec,
325346
old_hex, new_hex, ref->name);
326347
}
327348
if (will_delete_ref)
328-
fprintf(stderr, "deleting '%s'\n", ref->name);
349+
fprintf(stderr, " - %-*s %s\n",
350+
SUMMARY_WIDTH, "[deleting]",
351+
pretty_ref);
352+
else if (is_null_sha1(ref->old_sha1)) {
353+
const char *msg;
354+
355+
if (!prefixcmp(ref->name, "refs/tags/"))
356+
msg = "[new tag]";
357+
else
358+
msg = "[new branch]";
359+
fprintf(stderr, " * %-*s %s -> %s\n",
360+
SUMMARY_WIDTH, msg,
361+
pretty_peer, pretty_ref);
362+
}
329363
else {
330-
fprintf(stderr, "updating '%s'", ref->name);
331-
if (strcmp(ref->name, ref->peer_ref->name))
332-
fprintf(stderr, " using '%s'",
333-
ref->peer_ref->name);
334-
fprintf(stderr, "\n from %s\n to %s\n",
335-
old_hex, new_hex);
364+
char quickref[83];
365+
char type = ' ';
366+
const char *msg = "";
367+
368+
strcpy(quickref, find_unique_abbrev(ref->old_sha1, DEFAULT_ABBREV));
369+
if (ref_newer(ref->peer_ref->new_sha1, ref->old_sha1))
370+
strcat(quickref, "..");
371+
else {
372+
strcat(quickref, "...");
373+
type = '+';
374+
msg = " (forced update)";
375+
}
376+
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
377+
378+
fprintf(stderr, " %c %-*s %s -> %s%s\n",
379+
type,
380+
SUMMARY_WIDTH, quickref,
381+
pretty_peer, pretty_ref,
382+
msg);
336383
}
337384
}
338385

@@ -460,7 +507,7 @@ int send_pack(struct send_pack_args *my_args,
460507
verify_remote_names(nr_heads, heads);
461508

462509
conn = git_connect(fd, dest, args.receivepack, args.verbose ? CONNECT_VERBOSE : 0);
463-
ret = do_send_pack(fd[0], fd[1], remote, nr_heads, heads);
510+
ret = do_send_pack(fd[0], fd[1], remote, dest, nr_heads, heads);
464511
close(fd[0]);
465512
close(fd[1]);
466513
ret |= finish_connect(conn);

0 commit comments

Comments
 (0)