commit - 83cc419999b834998fd2a5e5347a8c6226c03f9c
commit + 4cac2b4e3f60c45b2a6550d4b15730d172eab925
blob - 1969207b146b1c39de82a5a2394b4097f809d897
blob + f8f629aca02cc89d790c9c76f79a3a2704601f97
--- got/got.c
+++ got/got.c
static const struct got_error*
build_refs_str(char **refs_str, struct got_reflist_head *refs,
- struct got_object_id *id, struct got_repository *repo)
+ struct got_object_id *id, struct got_repository *repo,
+ int local_only)
{
static const struct got_error *err = NULL;
struct got_reflist_entry *re;
if (strncmp(name, "heads/", 6) == 0)
name += 6;
if (strncmp(name, "remotes/", 8) == 0) {
+ if (local_only)
+ continue;
name += 8;
s = strstr(name, "/" GOT_REF_HEAD);
if (s != NULL && s[strlen(s)] == '\0')
}
static const struct got_error *
-print_commit_oneline(struct got_commit_object *commit, struct got_object_id *id)
+print_commit_oneline(struct got_commit_object *commit, struct got_object_id *id,
+ struct got_repository *repo, struct got_reflist_object_id_map *refs_idmap)
{
const struct got_error *err = NULL;
- char *id_str, *s, *nl, *logmsg0;
-
- err = got_object_id_str(&id_str, id);
- if (err)
- return err;
+ char *ref_str = NULL, *id_str = NULL, *logmsg0 = NULL;
+ char *comma, *s, *nl;
+ struct got_reflist_head *refs;
+ refs = got_reflist_object_id_map_lookup(refs_idmap, id);
+ if (refs) {
+ err = build_refs_str(&ref_str, refs, id, repo, 1);
+ if (err)
+ goto done;
+
+ /* Display the first matching ref only. */
+ if (ref_str && (comma = strchr(ref_str, ',')) != NULL)
+ *comma = '\0';
+ }
+
+ if (ref_str == NULL) {
+ err = got_object_id_str(&id_str, id);
+ if (err)
+ return err;
+ }
+
err = got_object_commit_get_logmsg(&logmsg0, commit);
if (err)
goto done;
*nl = '\0';
}
- printf("%.7s %s\n", id_str, s);
+ if (ref_str)
+ printf("%-7s %s\n", ref_str, s);
+ else
+ printf("%.7s %s\n", id_str, s);
if (fflush(stdout) != 0 && err == NULL)
err = got_error_from_errno("fflush");
done:
free(id_str);
+ free(ref_str);
free(logmsg0);
return err;
}
struct got_reflist_head *refs;
refs = got_reflist_object_id_map_lookup(refs_idmap, id);
if (refs) {
- err = build_refs_str(&refs_str, refs, id, repo);
+ err = build_refs_str(&refs_str, refs, id, repo, 0);
if (err)
goto done;
}
got_object_commit_close(commit);
} else {
if (one_line)
- err = print_commit_oneline(commit, id);
+ err = print_commit_oneline(commit, id,
+ repo, refs_idmap);
else
err = print_commit(commit, id, repo, path,
show_changed_paths ? &changed_paths : NULL,
break;
}
if (one_line)
- err = print_commit_oneline(commit, &qid->id);
+ err = print_commit_oneline(commit, &qid->id,
+ repo, refs_idmap);
else
err = print_commit(commit, &qid->id, repo, path,
show_changed_paths ? &changed_paths : NULL,
refs = got_reflist_object_id_map_lookup(refs_idmap, new_commit_id);
if (refs) {
- err = build_refs_str(&refs_str, refs, new_commit_id, repo);
+ err = build_refs_str(&refs_str, refs, new_commit_id, repo, 0);
if (err)
goto done;
}
refs = got_reflist_object_id_map_lookup(refs_idmap, yca_id);
if (refs) {
- err = build_refs_str(&refs_str, refs, yca_id, repo);
+ err = build_refs_str(&refs_str, refs, yca_id, repo, 0);
if (err)
goto done;
}