checkout: rename 'new' variables
Rename C++ keyword in order to bring the codebase closer to being able to be compiled with a C++ compiler. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Feb 14, 2018 at 10:59 UTC
c8a3ea1f2972cb18715f06f99973c594b329c472
1 file changed
+98
-98
builtin/checkout.c
+98
-98
@@ -54,14 +54,14 @@ struct checkout_opts {
54
struct tree *source_tree;
55
};
56
57
-static int post_checkout_hook(struct commit *old, struct commit *new,
57
+static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
58
int changed)
59
{
60
return run_hook_le(NULL, "post-checkout",
61
- oid_to_hex(old ? &old->object.oid : &null_oid),
62
- oid_to_hex(new ? &new->object.oid : &null_oid),
61
+ oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid),
62
+ oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid),
63
changed ? "1" : "0", NULL);
64
- /* "new" can be NULL when checking out from the index before
64
+ /* "new_commit" can be NULL when checking out from the index before
65
a commit exists. */
66
67
}
@@ -472,8 +472,8 @@ static void setup_branch_path(struct branch_info *branch)
472
}
473
474
static int merge_working_tree(const struct checkout_opts *opts,
475
- struct branch_info *old,
476
- struct branch_info *new,
475
+ struct branch_info *old_branch_info,
476
+ struct branch_info *new_branch_info,
477
int *writeout_error)
478
{
479
int ret;
@@ -485,7 +485,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
485
486
resolve_undo_clear();
487
if (opts->force) {
488
- ret = reset_tree(new->commit->tree, opts, 1, writeout_error);
488
+ ret = reset_tree(new_branch_info->commit->tree, opts, 1, writeout_error);
489
if (ret)
490
return ret;
491
} else {
@@ -511,7 +511,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
511
topts.initial_checkout = is_cache_unborn();
512
topts.update = 1;
513
topts.merge = 1;
514
- topts.gently = opts->merge && old->commit;
514
+ topts.gently = opts->merge && old_branch_info->commit;
515
topts.verbose_update = opts->show_progress;
516
topts.fn = twoway_merge;
517
if (opts->overwrite_ignore) {
@@ -519,11 +519,11 @@ static int merge_working_tree(const struct checkout_opts *opts,
519
topts.dir->flags |= DIR_SHOW_IGNORED;
520
setup_standard_excludes(topts.dir);
521
}
522
- tree = parse_tree_indirect(old->commit ?
523
- &old->commit->object.oid :
522
+ tree = parse_tree_indirect(old_branch_info->commit ?
523
+ &old_branch_info->commit->object.oid :
524
the_hash_algo->empty_tree);
525
init_tree_desc(&trees[0], tree->buffer, tree->size);
526
- tree = parse_tree_indirect(&new->commit->object.oid);
526
+ tree = parse_tree_indirect(&new_branch_info->commit->object.oid);
527
init_tree_desc(&trees[1], tree->buffer, tree->size);
528
529
ret = unpack_trees(2, trees, &topts);
@@ -540,10 +540,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
540
return 1;
541
542
/*
543
- * Without old->commit, the below is the same as
543
+ * Without old_branch_info->commit, the below is the same as
544
* the two-tree unpack we already tried and failed.
545
*/
546
- if (!old->commit)
546
+ if (!old_branch_info->commit)
547
return 1;
548
549
/* Do more real merge */
@@ -571,18 +571,18 @@ static int merge_working_tree(const struct checkout_opts *opts,
571
o.verbosity = 0;
572
work = write_tree_from_memory(&o);
573
574
- ret = reset_tree(new->commit->tree, opts, 1,
574
+ ret = reset_tree(new_branch_info->commit->tree, opts, 1,
575
writeout_error);
576
if (ret)
577
return ret;
578
- o.ancestor = old->name;
579
- o.branch1 = new->name;
578
+ o.ancestor = old_branch_info->name;
579
+ o.branch1 = new_branch_info->name;
580
o.branch2 = "local";
581
- ret = merge_trees(&o, new->commit->tree, work,
582
- old->commit->tree, &result);
581
+ ret = merge_trees(&o, new_branch_info->commit->tree, work,
582
+ old_branch_info->commit->tree, &result);
583
if (ret < 0)
584
exit(128);
585
- ret = reset_tree(new->commit->tree, opts, 0,
585
+ ret = reset_tree(new_branch_info->commit->tree, opts, 0,
586
writeout_error);
587
strbuf_release(&o.obuf);
588
if (ret)
@@ -600,15 +600,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
600
die(_("unable to write new index file"));
601
602
if (!opts->force && !opts->quiet)
603
- show_local_changes(&new->commit->object, &opts->diff_options);
603
+ show_local_changes(&new_branch_info->commit->object, &opts->diff_options);
604
605
return 0;
606
}
607
608
-static void report_tracking(struct branch_info *new)
608
+static void report_tracking(struct branch_info *new_branch_info)
609
{
610
struct strbuf sb = STRBUF_INIT;
611
- struct branch *branch = branch_get(new->name);
611
+ struct branch *branch = branch_get(new_branch_info->name);
612
613
if (!format_tracking_info(branch, &sb))
614
return;
@@ -617,8 +617,8 @@ static void report_tracking(struct branch_info *new)
617
}
618
619
static void update_refs_for_switch(const struct checkout_opts *opts,
620
- struct branch_info *old,
621
- struct branch_info *new)
620
+ struct branch_info *old_branch_info,
621
+ struct branch_info *new_branch_info)
622
{
623
struct strbuf msg = STRBUF_INIT;
624
const char *old_desc, *reflog_msg;
@@ -645,69 +645,69 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
645
free(refname);
646
}
647
else
648
- create_branch(opts->new_branch, new->name,
648
+ create_branch(opts->new_branch, new_branch_info->name,
649
opts->new_branch_force ? 1 : 0,
650
opts->new_branch_force ? 1 : 0,
651
opts->new_branch_log,
652
opts->quiet,
653
opts->track);
654
- new->name = opts->new_branch;
655
- setup_branch_path(new);
654
+ new_branch_info->name = opts->new_branch;
655
+ setup_branch_path(new_branch_info);
656
}
657
658
- old_desc = old->name;
659
- if (!old_desc && old->commit)
660
- old_desc = oid_to_hex(&old->commit->object.oid);
658
+ old_desc = old_branch_info->name;
659
+ if (!old_desc && old_branch_info->commit)
660
+ old_desc = oid_to_hex(&old_branch_info->commit->object.oid);
661
662
reflog_msg = getenv("GIT_REFLOG_ACTION");
663
if (!reflog_msg)
664
strbuf_addf(&msg, "checkout: moving from %s to %s",
665
- old_desc ? old_desc : "(invalid)", new->name);
665
+ old_desc ? old_desc : "(invalid)", new_branch_info->name);
666
else
667
strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
668
669
- if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
669
+ if (!strcmp(new_branch_info->name, "HEAD") && !new_branch_info->path && !opts->force_detach) {
670
/* Nothing to do. */
671
- } else if (opts->force_detach || !new->path) { /* No longer on any branch. */
672
- update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL,
671
+ } else if (opts->force_detach || !new_branch_info->path) { /* No longer on any branch. */
672
+ update_ref(msg.buf, "HEAD", &new_branch_info->commit->object.oid, NULL,
673
REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
674
if (!opts->quiet) {
675
- if (old->path &&
675
+ if (old_branch_info->path &&
676
advice_detached_head && !opts->force_detach)
677
- detach_advice(new->name);
678
- describe_detached_head(_("HEAD is now at"), new->commit);
677
+ detach_advice(new_branch_info->name);
678
+ describe_detached_head(_("HEAD is now at"), new_branch_info->commit);
679
}
680
- } else if (new->path) { /* Switch branches. */
681
- if (create_symref("HEAD", new->path, msg.buf) < 0)
680
+ } else if (new_branch_info->path) { /* Switch branches. */
681
+ if (create_symref("HEAD", new_branch_info->path, msg.buf) < 0)
682
die(_("unable to update HEAD"));
683
if (!opts->quiet) {
684
- if (old->path && !strcmp(new->path, old->path)) {
684
+ if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) {
685
if (opts->new_branch_force)
686
fprintf(stderr, _("Reset branch '%s'\n"),
687
- new->name);
687
+ new_branch_info->name);
688
else
689
fprintf(stderr, _("Already on '%s'\n"),
690
- new->name);
690
+ new_branch_info->name);
691
} else if (opts->new_branch) {
692
if (opts->branch_exists)
693
- fprintf(stderr, _("Switched to and reset branch '%s'\n"), new->name);
693
+ fprintf(stderr, _("Switched to and reset branch '%s'\n"), new_branch_info->name);
694
else
695
- fprintf(stderr, _("Switched to a new branch '%s'\n"), new->name);
695
+ fprintf(stderr, _("Switched to a new branch '%s'\n"), new_branch_info->name);
696
} else {
697
fprintf(stderr, _("Switched to branch '%s'\n"),
698
- new->name);
698
+ new_branch_info->name);
699
}
700
}
701
- if (old->path && old->name) {
702
- if (!ref_exists(old->path) && reflog_exists(old->path))
703
- delete_reflog(old->path);
701
+ if (old_branch_info->path && old_branch_info->name) {
702
+ if (!ref_exists(old_branch_info->path) && reflog_exists(old_branch_info->path))
703
+ delete_reflog(old_branch_info->path);
704
}
705
}
706
remove_branch_state();
707
strbuf_release(&msg);
708
if (!opts->quiet &&
709
- (new->path || (!opts->force_detach && !strcmp(new->name, "HEAD"))))
710
- report_tracking(new);
709
+ (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
710
+ report_tracking(new_branch_info);
711
}
712
713
static int add_pending_uninteresting_ref(const char *refname,
@@ -787,10 +787,10 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
787
* HEAD. If it is not reachable from any ref, this is the last chance
788
* for the user to do so without resorting to reflog.
789
*/
790
-static void orphaned_commit_warning(struct commit *old, struct commit *new)
790
+static void orphaned_commit_warning(struct commit *old_commit, struct commit *new_commit)
791
{
792
struct rev_info revs;
793
- struct object *object = &old->object;
793
+ struct object *object = &old_commit->object;
794
795
init_revisions(&revs, NULL);
796
setup_revisions(0, NULL, &revs, NULL);
@@ -799,57 +799,57 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
799
add_pending_object(&revs, object, oid_to_hex(&object->oid));
800
801
for_each_ref(add_pending_uninteresting_ref, &revs);
802
- add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING);
802
+ add_pending_oid(&revs, "HEAD", &new_commit->object.oid, UNINTERESTING);
803
804
if (prepare_revision_walk(&revs))
805
die(_("internal error in revision walk"));
806
- if (!(old->object.flags & UNINTERESTING))
807
- suggest_reattach(old, &revs);
806
+ if (!(old_commit->object.flags & UNINTERESTING))
807
+ suggest_reattach(old_commit, &revs);
808
else
809
- describe_detached_head(_("Previous HEAD position was"), old);
809
+ describe_detached_head(_("Previous HEAD position was"), old_commit);
810
811
/* Clean up objects used, as they will be reused. */
812
clear_commit_marks_all(ALL_REV_FLAGS);
813
}
814
815
static int switch_branches(const struct checkout_opts *opts,
816
- struct branch_info *new)
816
+ struct branch_info *new_branch_info)
817
{
818
int ret = 0;
819
- struct branch_info old;
819
+ struct branch_info old_branch_info;
820
void *path_to_free;
821
struct object_id rev;
822
int flag, writeout_error = 0;
823
- memset(&old, 0, sizeof(old));
824
- old.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
825
- if (old.path)
826
- old.commit = lookup_commit_reference_gently(&rev, 1);
823
+ memset(&old_branch_info, 0, sizeof(old_branch_info));
824
+ old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
825
+ if (old_branch_info.path)
826
+ old_branch_info.commit = lookup_commit_reference_gently(&rev, 1);
827
if (!(flag & REF_ISSYMREF))
828
- old.path = NULL;
828
+ old_branch_info.path = NULL;
829
830
- if (old.path)
831
- skip_prefix(old.path, "refs/heads/", &old.name);
830
+ if (old_branch_info.path)
831
+ skip_prefix(old_branch_info.path, "refs/heads/", &old_branch_info.name);
832
833
- if (!new->name) {
834
- new->name = "HEAD";
835
- new->commit = old.commit;
836
- if (!new->commit)
833
+ if (!new_branch_info->name) {
834
+ new_branch_info->name = "HEAD";
835
+ new_branch_info->commit = old_branch_info.commit;
836
+ if (!new_branch_info->commit)
837
die(_("You are on a branch yet to be born"));
838
- parse_commit_or_die(new->commit);
838
+ parse_commit_or_die(new_branch_info->commit);
839
}
840
841
- ret = merge_working_tree(opts, &old, new, &writeout_error);
841
+ ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
842
if (ret) {
843
free(path_to_free);
844
return ret;
845
}
846
847
- if (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
848
- orphaned_commit_warning(old.commit, new->commit);
847
+ if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)
848
+ orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
849
850
- update_refs_for_switch(opts, &old, new);
850
+ update_refs_for_switch(opts, &old_branch_info, new_branch_info);
851
852
- ret = post_checkout_hook(old.commit, new->commit, 1);
852
+ ret = post_checkout_hook(old_branch_info.commit, new_branch_info->commit, 1);
853
free(path_to_free);
854
return ret || writeout_error;
855
}
@@ -870,7 +870,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
870
871
static int parse_branchname_arg(int argc, const char **argv,
872
int dwim_new_local_branch_ok,
873
- struct branch_info *new,
873
+ struct branch_info *new_branch_info,
874
struct checkout_opts *opts,
875
struct object_id *rev)
876
{
@@ -988,22 +988,22 @@ static int parse_branchname_arg(int argc, const char **argv,
988
argv++;
989
argc--;
990
991
- new->name = arg;
992
- setup_branch_path(new);
991
+ new_branch_info->name = arg;
992
+ setup_branch_path(new_branch_info);
993
994
- if (!check_refname_format(new->path, 0) &&
995
- !read_ref(new->path, &branch_rev))
994
+ if (!check_refname_format(new_branch_info->path, 0) &&
995
+ !read_ref(new_branch_info->path, &branch_rev))
996
oidcpy(rev, &branch_rev);
997
else
998
- new->path = NULL; /* not an existing branch */
998
+ new_branch_info->path = NULL; /* not an existing branch */
999
1000
- new->commit = lookup_commit_reference_gently(rev, 1);
1001
- if (!new->commit) {
1000
+ new_branch_info->commit = lookup_commit_reference_gently(rev, 1);
1001
+ if (!new_branch_info->commit) {
1002
/* not a commit */
1003
*source_tree = parse_tree_indirect(rev);
1004
} else {
1005
- parse_commit_or_die(new->commit);
1006
- *source_tree = new->commit->tree;
1005
+ parse_commit_or_die(new_branch_info->commit);
1006
+ *source_tree = new_branch_info->commit->tree;
1007
}
1008
1009
if (!*source_tree) /* case (1): want a tree */
@@ -1043,7 +1043,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
1043
}
1044
1045
static int checkout_branch(struct checkout_opts *opts,
1046
- struct branch_info *new)
1046
+ struct branch_info *new_branch_info)
1047
{
1048
if (opts->pathspec.nr)
1049
die(_("paths cannot be used with switching branches"));
@@ -1072,21 +1072,21 @@ static int checkout_branch(struct checkout_opts *opts,
1072
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1073
opts->track = git_branch_track;
1074
1075
- if (new->name && !new->commit)
1075
+ if (new_branch_info->name && !new_branch_info->commit)
1076
die(_("Cannot switch branch to a non-commit '%s'"),
1077
- new->name);
1077
+ new_branch_info->name);
1078
1079
- if (new->path && !opts->force_detach && !opts->new_branch &&
1079
+ if (new_branch_info->path && !opts->force_detach && !opts->new_branch &&
1080
!opts->ignore_other_worktrees) {
1081
int flag;
1082
char *head_ref = resolve_refdup("HEAD", 0, NULL, &flag);
1083
if (head_ref &&
1084
- (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
1085
- die_if_checked_out(new->path, 1);
1084
+ (!(flag & REF_ISSYMREF) || strcmp(head_ref, new_branch_info->path)))
1085
+ die_if_checked_out(new_branch_info->path, 1);
1086
free(head_ref);
1087
}
1088
1089
- if (!new->commit && opts->new_branch) {
1089
+ if (!new_branch_info->commit && opts->new_branch) {
1090
struct object_id rev;
1091
int flag;
1092
@@ -1094,13 +1094,13 @@ static int checkout_branch(struct checkout_opts *opts,
1094
(flag & REF_ISSYMREF) && is_null_oid(&rev))
1095
return switch_unborn_to_new_branch(opts);
1096
}
1097
- return switch_branches(opts, new);
1097
+ return switch_branches(opts, new_branch_info);
1098
}
1099
1100
int cmd_checkout(int argc, const char **argv, const char *prefix)
1101
{
1102
struct checkout_opts opts;
1103
- struct branch_info new;
1103
+ struct branch_info new_branch_info;
1104
char *conflict_style = NULL;
1105
int dwim_new_local_branch = 1;
1106
struct option options[] = {
@@ -1138,7 +1138,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1138
};
1139
1140
memset(&opts, 0, sizeof(opts));
1141
- memset(&new, 0, sizeof(new));
1141
+ memset(&new_branch_info, 0, sizeof(new_branch_info));
1142
opts.overwrite_ignore = 1;
1143
opts.prefix = prefix;
1144
opts.show_progress = -1;
@@ -1210,7 +1210,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1210
opts.track == BRANCH_TRACK_UNSPECIFIED &&
1211
!opts.new_branch;
1212
int n = parse_branchname_arg(argc, argv, dwim_ok,
1213
- &new, &opts, &rev);
1213
+ &new_branch_info, &opts, &rev);
1214
argv += n;
1215
argc -= n;
1216
}
@@ -1253,7 +1253,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1253
1254
UNLEAK(opts);
1255
if (opts.patch_mode || opts.pathspec.nr)
1256
- return checkout_paths(&opts, new.name);
1256
+ return checkout_paths(&opts, new_branch_info.name);
1257
else
1258
- return checkout_branch(&opts, &new);
1258
+ return checkout_branch(&opts, &new_branch_info);
1259
}