@matheusbsbs / matheus-bagliano / commits / 569012bf91
Fork 0

Clean up reporting differences on branch switch

This also changes it such that: $ git checkout will give the same information without changing branches. This is good for finding out if the fetch you did recently had anything to say about the branch you've been on, whose name you don't remember at the moment. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Feb 19, 2008 at 02:52 UTC 569012bf91ddb25220483e8912e079ce8a501525
1 file changed +7 -71
builtin-checkout.c
+7 -71
@@ -291,71 +291,6 @@ static int merge_working_tree(struct checkout_opts *opts,
291 return 0;
292 }
293
294 -/*
295 - * We really should allow cb_data... Yuck
296 - */
297 -static const char *branch_name;
298 -static int branch_name_len;
299 -static char *found_remote;
300 -static char *found_merge;
301 -static int read_branch_config(const char *var, const char *value)
302 -{
303 - const char *name;
304 - if (prefixcmp(var, "branch."))
305 - return 0; /* not ours */
306 - name = var + strlen("branch.");
307 - if (strncmp(name, branch_name, branch_name_len) ||
308 - name[branch_name_len] != '.')
309 - return 0; /* not ours either */
310 - if (!strcmp(name + branch_name_len, ".remote")) {
311 - /*
312 - * Yeah, I know Christian's clean-up should
313 - * be used here, but the topic is based on an
314 - * older fork point.
315 - */
316 - if (!value)
317 - return error("'%s' not string", var);
318 - found_remote = xstrdup(value);
319 - return 0;
320 - }
321 - if (!strcmp(name + branch_name_len, ".merge")) {
322 - if (!value)
323 - return error("'%s' not string", var);
324 - found_merge = xstrdup(value);
325 - return 0;
326 - }
327 - return 0; /* not ours */
328 -}
329 -
330 -static int find_build_base(const char *ours, char **base)
331 -{
332 - struct remote *remote;
333 - struct refspec spec;
334 -
335 - *base = NULL;
336 -
337 - branch_name = ours + strlen("refs/heads/");
338 - branch_name_len = strlen(branch_name);
339 - found_remote = NULL;
340 - found_merge = NULL;
341 - git_config(read_branch_config);
342 -
343 - if (!found_remote || !found_merge) {
344 - cleanup:
345 - free(found_remote);
346 - free(found_merge);
347 - return 0;
348 - }
349 -
350 - remote = remote_get(found_remote);
351 - memset(&spec, 0, sizeof(spec));
352 - spec.src = found_merge;
353 - if (remote_find_tracking(remote, &spec))
354 - goto cleanup;
355 - *base = spec.dst;
356 - return 1;
357 -}
358 -
294 static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *opts)
295 {
296 /*
@@ -369,15 +304,16 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
304 const char *msgfmt;
305 char symmetric[84];
306 int show_log;
307 + struct branch *branch = branch_get(NULL);
308
373 - if (!resolve_ref(new->path, sha1, 1, NULL))
309 + if (!branch || !branch->merge)
310 return;
375 - ours = lookup_commit(sha1);
311
377 - if (!find_build_base(new->path, &base))
378 - return;
312 + base = branch->merge[0]->dst;
313 +
314 + ours = new->commit;
315
380 - sprintf(symmetric, "%s", sha1_to_hex(sha1));
316 + sprintf(symmetric, "%s", sha1_to_hex(ours->object.sha1));
317
318 /*
319 * Ok, it is tracking base; is it ahead of us?
@@ -466,7 +402,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
402 }
403 remove_branch_state();
404 strbuf_release(&msg);
469 - if (new->path)
405 + if (new->path || !strcmp(new->name, "HEAD"))
406 adjust_to_tracking(new, opts);
407 }
408