summaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2008-04-17 20:24:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-04-21 01:16:46 (GMT)
commite8b404c27e98a8d1b0e123fe80ce19efbdbf73d7 (patch)
tree14b9ca7c2d0af2eba2cf914c61242f4092121f8c /builtin-branch.c
parent5909ca92d8b2c6a0534597f52f7733ff61a64d63 (diff)
downloadgit-e8b404c27e98a8d1b0e123fe80ce19efbdbf73d7.zip
git-e8b404c27e98a8d1b0e123fe80ce19efbdbf73d7.tar.gz
git-e8b404c27e98a8d1b0e123fe80ce19efbdbf73d7.tar.bz2
git-branch: add support for --merged and --no-merged
These options filter the output from git branch to only include branches whose tip is either merged or not merged into HEAD. The use-case for these options is when working with integration of branches from many remotes: `git branch --no-merged -a` will show a nice list of merge candidates while `git branch --merged -a` will show the progress of your integration work. Also, a plain `git branch --merged` is a quick way to find local branches which you might want to delete. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-branch.c')
-rw-r--r--builtin-branch.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index 5bc4526..19c508a 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -15,7 +15,7 @@
#include "branch.h"
static const char * const builtin_branch_usage[] = {
- "git-branch [options] [-r | -a]",
+ "git-branch [options] [-r | -a] [--merged | --no-merged]",
"git-branch [options] [-l] [-f] <branchname> [<start-point>]",
"git-branch [options] [-r] (-d | -D) <branchname>",
"git-branch [options] (-m | -M) [<oldbranch>] <newbranch>",
@@ -46,6 +46,8 @@ enum color_branch {
COLOR_BRANCH_CURRENT = 4,
};
+static int mergefilter = -1;
+
static int parse_branch_color_slot(const char *var, int ofs)
{
if (!strcasecmp(var+ofs, "plain"))
@@ -210,6 +212,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
struct ref_item *newitem;
int kind = REF_UNKNOWN_TYPE;
int len;
+ static struct commit_list branch;
/* Detect kind */
if (!prefixcmp(refname, "refs/heads/")) {
@@ -231,6 +234,16 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
if ((kind & ref_list->kinds) == 0)
return 0;
+ if (mergefilter > -1) {
+ branch.item = lookup_commit_reference_gently(sha1, 1);
+ if (!branch.item)
+ die("Unable to lookup tip of branch %s", refname);
+ if (mergefilter == 0 && has_commit(head_sha1, &branch))
+ return 0;
+ if (mergefilter == 1 && !has_commit(head_sha1, &branch))
+ return 0;
+ }
+
/* Resize buffer */
if (ref_list->index >= ref_list->alloc) {
ref_list->alloc = alloc_nr(ref_list->alloc);
@@ -444,6 +457,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
+ OPT_SET_INT(0, "merged", &mergefilter, "list only merged branches", 1),
OPT_END(),
};