@matheusbsbs / matheus-bagliano / commits / d11d44faee
Fork 0

Use OPT_SET_INT and OPT_BIT in builtin-branch

Also remove a spurious after-check on --abbrev (OPT__ABBREV already takes care of that) Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Nov 7, 2007 at 11:20 UTC d11d44faee3334755b2b66618494cd901d226d6f
1 file changed +16 -28
builtin-branch.c
+16 -28
@@ -507,48 +507,36 @@ static void rename_branch(const char *oldname, const char *newname, int force)
507
508 int cmd_branch(int argc, const char **argv, const char *prefix)
509 {
510 - int delete = 0, force_delete = 0, force_create = 0;
511 - int rename = 0, force_rename = 0;
510 + int delete = 0, rename = 0, force_create = 0;
511 int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
512 int reflog = 0, track;
514 - int kinds = REF_LOCAL_BRANCH, kind_remote = 0, kind_any = 0;
513 + int kinds = REF_LOCAL_BRANCH;
514
515 struct option options[] = {
516 OPT_GROUP("Generic options"),
517 OPT__VERBOSE(&verbose),
518 OPT_BOOLEAN( 0 , "track", &track, "set up tracking mode (see git-pull(1))"),
519 OPT_BOOLEAN( 0 , "color", &branch_use_color, "use colored output"),
521 - OPT_BOOLEAN('r', NULL, &kind_remote, "act on remote-tracking branches"),
520 + OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches",
521 + REF_REMOTE_BRANCH),
522 OPT__ABBREV(&abbrev),
523
524 OPT_GROUP("Specific git-branch actions:"),
525 - OPT_BOOLEAN('a', NULL, &kind_any, "list both remote-tracking and local branches"),
526 - OPT_BOOLEAN('d', NULL, &delete, "delete fully merged branch"),
527 - OPT_BOOLEAN('D', NULL, &force_delete, "delete branch (even if not merged)"),
528 - OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
529 - OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
530 - OPT_BOOLEAN('m', NULL, &rename, "move/rename a branch and its reflog"),
531 - OPT_BOOLEAN('M', NULL, &force_rename, "move/rename a branch, even if target exists"),
525 + OPT_SET_INT('a', NULL, &kinds, "list both remote-tracking and local branches",
526 + REF_REMOTE_BRANCH | REF_LOCAL_BRANCH),
527 + OPT_BIT('d', NULL, &delete, "delete fully merged branch", 1),
528 + OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
529 + OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
530 + OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
531 + OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
532 + OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
533 OPT_END(),
534 };
535
536 git_config(git_branch_config);
537 track = branch_track;
538 argc = parse_options(argc, argv, options, builtin_branch_usage, 0);
538 -
539 - delete |= force_delete;
540 - rename |= force_rename;
541 - if (kind_remote)
542 - kinds = REF_REMOTE_BRANCH;
543 - if (kind_any)
544 - kinds = REF_REMOTE_BRANCH | REF_LOCAL_BRANCH;
545 - if (abbrev && abbrev < MINIMUM_ABBREV)
546 - abbrev = MINIMUM_ABBREV;
547 - else if (abbrev > 40)
548 - abbrev = 40;
549 -
550 - if ((delete && rename) || (delete && force_create) ||
551 - (rename && force_create))
539 + if (!!delete + !!rename + !!force_create > 1)
540 usage_with_options(builtin_branch_usage, options);
541
542 head = resolve_ref("HEAD", head_sha1, 0, NULL);
@@ -564,13 +552,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
552 }
553
554 if (delete)
567 - return delete_branches(argc, argv, force_delete, kinds);
555 + return delete_branches(argc, argv, delete > 1, kinds);
556 else if (argc == 0)
557 print_ref_list(kinds, detached, verbose, abbrev);
558 else if (rename && (argc == 1))
571 - rename_branch(head, argv[0], force_rename);
559 + rename_branch(head, argv[0], rename > 1);
560 else if (rename && (argc == 2))
573 - rename_branch(argv[0], argv[1], force_rename);
561 + rename_branch(argv[0], argv[1], rename > 1);
562 else if (argc <= 2)
563 create_branch(argv[0], (argc == 2) ? argv[1] : head,
564 force_create, reflog, track);