ref-filter: implement '--merged' and '--no-merged' options
[gitweb.git] / builtin / branch.c
index b7202b33990a68cfa41b1a302c286c38ddfb713e..e63102e47bdb11010838b7e854b0c2a08d04659c 100644 (file)
@@ -240,7 +240,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                                            sha1, &flags);
                if (!target) {
                        error(remote_branch
-                             ? _("remote branch '%s' not found.")
+                             ? _("remote-tracking branch '%s' not found.")
                              : _("branch '%s' not found."), bname.buf);
                        ret = 1;
                        continue;
@@ -255,7 +255,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 
                if (delete_ref(name, sha1, REF_NODEREF)) {
                        error(remote_branch
-                             ? _("Error deleting remote branch '%s'")
+                             ? _("Error deleting remote-tracking branch '%s'")
                              : _("Error deleting branch '%s'"),
                              bname.buf);
                        ret = 1;
@@ -263,7 +263,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                }
                if (!quiet) {
                        printf(remote_branch
-                              ? _("Deleted remote branch %s (was %s).\n")
+                              ? _("Deleted remote-tracking branch %s (was %s).\n")
                               : _("Deleted branch %s (was %s).\n"),
                               bname.buf,
                               (flags & REF_ISBROKEN) ? "broken"
@@ -326,7 +326,7 @@ static int match_patterns(const char **pattern, const char *refname)
        return 0;
 }
 
-static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
+static int append_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data)
 {
        struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
        struct ref_list *ref_list = cb->ref_list;
@@ -363,7 +363,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
 
        commit = NULL;
        if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
-               commit = lookup_commit_reference_gently(sha1, 1);
+               commit = lookup_commit_reference_gently(oid->hash, 1);
                if (!commit) {
                        cb->ret = error(_("branch '%s' does not point at a commit"), refname);
                        return 0;
@@ -425,25 +425,19 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
        int ours, theirs;
        char *ref = NULL;
        struct branch *branch = branch_get(branch_name);
+       const char *upstream;
        struct strbuf fancy = STRBUF_INIT;
        int upstream_is_gone = 0;
        int added_decoration = 1;
 
-       switch (stat_tracking_info(branch, &ours, &theirs)) {
-       case 0:
-               /* no base */
-               return;
-       case -1:
-               /* with "gone" base */
+       if (stat_tracking_info(branch, &ours, &theirs, &upstream) < 0) {
+               if (!upstream)
+                       return;
                upstream_is_gone = 1;
-               break;
-       default:
-               /* with base */
-               break;
        }
 
        if (show_upstream_ref) {
-               ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
+               ref = shorten_unambiguous_ref(upstream, 0);
                if (want_color(branch_use_color))
                        strbuf_addf(&fancy, "%s%s%s",
                                        branch_get_color(BRANCH_COLOR_UPSTREAM),
@@ -641,6 +635,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
        cb.pattern = pattern;
        cb.ret = 0;
        for_each_rawref(append_ref, &cb);
+       /*
+        * The following implementation is currently duplicated in ref-filter. It
+        * will eventually be removed when we port branch.c to use ref-filter APIs.
+        */
        if (merge_filter != NO_FILTER) {
                struct commit *filter;
                filter = lookup_commit_reference_gently(merge_filter_ref, 0);
@@ -751,6 +749,10 @@ static void rename_branch(const char *oldname, const char *newname, int force)
        strbuf_release(&newsection);
 }
 
+/*
+ * This function is duplicated in ref-filter. It will eventually be removed
+ * when we port branch.c to use ref-filter APIs.
+ */
 static int opt_parse_merge_filter(const struct option *opt, const char *arg, int unset)
 {
        merge_filter = ((opt->long_name[0] == 'n')
@@ -769,7 +771,6 @@ static const char edit_description[] = "BRANCH_DESCRIPTION";
 
 static int edit_branch_description(const char *branch_name)
 {
-       FILE *fp;
        int status;
        struct strbuf buf = STRBUF_INIT;
        struct strbuf name = STRBUF_INIT;
@@ -782,8 +783,7 @@ static int edit_branch_description(const char *branch_name)
                    "  %s\n"
                    "Lines starting with '%c' will be stripped.\n",
                    branch_name, comment_line_char);
-       fp = fopen(git_path(edit_description), "w");
-       if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
+       if (write_file(git_path(edit_description), 0, "%s", buf.buf)) {
                strbuf_release(&buf);
                return error(_("could not write branch description template: %s"),
                             strerror(errno));