131
return ref_map;
132
}
133
134
-static void show_new(enum object_type type, unsigned char *sha1_new)
135
-{
136
- fprintf(stderr, " %s: %s\n", typename(type),
137
- find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
138
-}
139
-
134
static int s_update_ref(const char *action,
135
struct ref *ref,
136
int check_old)
151
return 0;
152
}
153
154
+#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
155
+
156
static int update_local_ref(struct ref *ref,
161
- const char *note,
162
- int verbose)
157
+ const char *remote,
158
+ int verbose,
159
+ char *display)
160
{
164
- char oldh[41], newh[41];
161
struct commit *current = NULL, *updated;
162
enum object_type type;
163
struct branch *current_branch = branch_get(NULL);
164
+ const char *pretty_ref = ref->name + (
165
+ !prefixcmp(ref->name, "refs/heads/") ? 11 :
166
+ !prefixcmp(ref->name, "refs/tags/") ? 10 :
167
+ !prefixcmp(ref->name, "refs/remotes/") ? 13 :
168
+ 0);
169
170
+ *display = 0;
171
type = sha1_object_info(ref->new_sha1, NULL);
172
if (type < 0)
173
die("object %s not found", sha1_to_hex(ref->new_sha1));
174
175
if (!*ref->name) {
176
/* Not storing */
175
- if (verbose) {
176
- fprintf(stderr, "* fetched %s\n", note);
177
- show_new(type, ref->new_sha1);
178
- }
177
+ if (verbose)
178
+ sprintf(display, "* branch %s -> FETCH_HEAD", remote);
179
return 0;
180
}
181
182
if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
183
- if (verbose) {
184
- fprintf(stderr, "* %s: same as %s\n",
185
- ref->name, note);
186
- show_new(type, ref->new_sha1);
187
- }
183
+ if (verbose)
184
+ sprintf(display, "= %-*s %s -> %s", SUMMARY_WIDTH,
185
+ "[up to date]", remote, pretty_ref);
186
return 0;
187
}
188
194
* If this is the head, and it's not okay to update
195
* the head, and the old value of the head isn't empty...
196
*/
199
- fprintf(stderr,
200
- " * %s: Cannot fetch into the current branch.\n",
201
- ref->name);
197
+ sprintf(display, "! %-*s %s -> %s (can't fetch in current branch)",
198
+ SUMMARY_WIDTH, "[rejected]", remote, pretty_ref);
199
return 1;
200
}
201
202
if (!is_null_sha1(ref->old_sha1) &&
203
!prefixcmp(ref->name, "refs/tags/")) {
207
- fprintf(stderr, "* %s: updating with %s\n",
208
- ref->name, note);
209
- show_new(type, ref->new_sha1);
204
+ sprintf(display, "- %-*s %s -> %s",
205
+ SUMMARY_WIDTH, "[tag update]", remote, pretty_ref);
206
return s_update_ref("updating tag", ref, 0);
207
}
208
209
current = lookup_commit_reference_gently(ref->old_sha1, 1);
210
updated = lookup_commit_reference_gently(ref->new_sha1, 1);
211
if (!current || !updated) {
216
- char *msg;
217
- if (!strncmp(ref->name, "refs/tags/", 10))
212
+ const char *msg;
213
+ const char *what;
214
+ if (!strncmp(ref->name, "refs/tags/", 10)) {
215
msg = "storing tag";
219
- else
216
+ what = "[new tag]";
217
+ }
218
+ else {
219
msg = "storing head";
221
- fprintf(stderr, "* %s: storing %s\n",
222
- ref->name, note);
223
- show_new(type, ref->new_sha1);
220
+ what = "[new branch]";
221
+ }
222
+
223
+ sprintf(display, "* %-*s %s -> %s",
224
+ SUMMARY_WIDTH, what, remote, pretty_ref);
225
return s_update_ref(msg, ref, 0);
226
}
227
227
- strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
228
- strcpy(newh, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
229
-
228
if (in_merge_bases(current, &updated, 1)) {
231
- fprintf(stderr, "* %s: fast forward to %s\n",
232
- ref->name, note);
233
- fprintf(stderr, " old..new: %s..%s\n", oldh, newh);
229
+ char quickref[83];
230
+ strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
231
+ strcat(quickref, "..");
232
+ strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
233
+ sprintf(display, " %-*s %s -> %s (fast forward)",
234
+ SUMMARY_WIDTH, quickref, remote, pretty_ref);
235
return s_update_ref("fast forward", ref, 1);
235
- }
236
- if (!force && !ref->force) {
237
- fprintf(stderr,
238
- "* %s: not updating to non-fast forward %s\n",
239
- ref->name, note);
240
- fprintf(stderr,
241
- " old...new: %s...%s\n", oldh, newh);
236
+ } else if (force || ref->force) {
237
+ char quickref[84];
238
+ strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
239
+ strcat(quickref, "...");
240
+ strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
241
+ sprintf(display, "+ %-*s %s -> %s (forced update)",
242
+ SUMMARY_WIDTH, quickref, remote, pretty_ref);
243
+ return s_update_ref("forced-update", ref, 1);
244
+ } else {
245
+ sprintf(display, "! %-*s %s -> %s (non fast forward)",
246
+ SUMMARY_WIDTH, "[rejected]", remote, pretty_ref);
247
return 1;
248
}
244
- fprintf(stderr,
245
- "* %s: forcing update to non-fast forward %s\n",
246
- ref->name, note);
247
- fprintf(stderr, " old...new: %s...%s\n", oldh, newh);
248
- return s_update_ref("forced-update", ref, 1);
249
}
250
251
static void store_updated_refs(const char *url, struct ref *ref_map)
252
{
253
FILE *fp;
254
struct commit *commit;
255
- int url_len, i, note_len;
255
+ int url_len, i, note_len, shown_url = 0;
256
char note[1024];
257
const char *what, *kind;
258
struct ref *rm;
315
rm->merge ? "" : "not-for-merge",
316
note);
317
318
- if (ref)
319
- update_local_ref(ref, note, verbose);
318
+ if (ref) {
319
+ update_local_ref(ref, what, verbose, note);
320
+ if (*note) {
321
+ if (!shown_url) {
322
+ fprintf(stderr, "From %.*s\n",
323
+ url_len, url);
324
+ shown_url = 1;
325
+ }
326
+ fprintf(stderr, " %s\n", note);
327
+ }
328
+ }
329
}
330
fclose(fp);
331
}
385
if (!path_list_has_path(&existing_refs, ref_name) &&
386
!path_list_has_path(&new_refs, ref_name) &&
387
lookup_object(ref->old_sha1)) {
379
- fprintf(stderr, "Auto-following %s\n",
380
- ref_name);
381
-
388
path_list_insert(ref_name, &new_refs);
389
390
rm = alloc_ref(strlen(ref_name) + 1);