branch.c: remove the_repository reference
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 10, 2018 at 06:49 UTC
4edce1729a257ec9a420ff108e3b832b14d113c5
7 files changed
+27
-19
branch.c
+11
-10
@@ -242,7 +242,8 @@ N_("\n"
242
"will track its remote counterpart, you may want to use\n"
243
"\"git push -u\" to set the upstream config as you push.");
244
245
-void create_branch(const char *name, const char *start_name,
245
+void create_branch(struct repository *r,
246
+ const char *name, const char *start_name,
247
int force, int clobber_head_ok, int reflog,
248
int quiet, enum branch_track track)
249
{
@@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
301
break;
302
}
303
303
- if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
304
+ if ((commit = lookup_commit_reference(r, &oid)) == NULL)
305
die(_("Not a valid branch point: '%s'."), start_name);
306
oidcpy(&oid, &commit->object.oid);
307
@@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,
337
free(real_ref);
338
}
339
339
-void remove_branch_state(void)
340
+void remove_branch_state(struct repository *r)
341
{
341
- unlink(git_path_cherry_pick_head(the_repository));
342
- unlink(git_path_revert_head(the_repository));
343
- unlink(git_path_merge_head(the_repository));
344
- unlink(git_path_merge_rr(the_repository));
345
- unlink(git_path_merge_msg(the_repository));
346
- unlink(git_path_merge_mode(the_repository));
347
- unlink(git_path_squash_msg(the_repository));
342
+ unlink(git_path_cherry_pick_head(r));
343
+ unlink(git_path_revert_head(r));
344
+ unlink(git_path_merge_head(r));
345
+ unlink(git_path_merge_rr(r));
346
+ unlink(git_path_merge_msg(r));
347
+ unlink(git_path_merge_mode(r));
348
+ unlink(git_path_squash_msg(r));
349
}
350
351
void die_if_checked_out(const char *branch, int ignore_current_worktree)
branch.h
+6
-2
@@ -1,6 +1,7 @@
1
#ifndef BRANCH_H
2
#define BRANCH_H
3
4
+struct repository;
5
struct strbuf;
6
7
enum branch_track {
@@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;
20
/*
21
* Creates a new branch, where:
22
*
23
+ * - r is the repository to add a branch to
24
+ *
25
* - name is the new branch name
26
*
27
* - start_name is the name of the existing branch that the new branch should
@@ -37,7 +40,8 @@ extern enum branch_track git_branch_track;
40
* that start_name is a tracking branch for (if any).
41
*
42
*/
40
-void create_branch(const char *name, const char *start_name,
43
+void create_branch(struct repository *r,
44
+ const char *name, const char *start_name,
45
int force, int clobber_head_ok,
46
int reflog, int quiet, enum branch_track track);
47
@@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for
64
* Remove information about the state of working on the current
65
* branch. (E.g., MERGE_HEAD)
66
*/
63
-void remove_branch_state(void);
67
+void remove_branch_state(struct repository *r);
68
69
/*
70
* Configure local branch "local" as downstream to branch "remote"
builtin/am.c
+1
-1
@@ -2022,7 +2022,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
2022
if (merge_tree(remote_tree))
2023
return -1;
2024
2025
- remove_branch_state();
2025
+ remove_branch_state(the_repository);
2026
2027
return 0;
2028
}
builtin/branch.c
+4
-2
@@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
783
* create_branch takes care of setting up the tracking
784
* info and making sure new_upstream is correct
785
*/
786
- create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
786
+ create_branch(the_repository, branch->name, new_upstream,
787
+ 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
788
} else if (unset_upstream) {
789
struct branch *branch = branch_get(argv[0]);
790
struct strbuf buf = STRBUF_INIT;
@@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
815
if (track == BRANCH_TRACK_OVERRIDE)
816
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
817
817
- create_branch(argv[0], (argc == 2) ? argv[1] : head,
818
+ create_branch(the_repository,
819
+ argv[0], (argc == 2) ? argv[1] : head,
820
force, 0, reflog, quiet, track);
821
822
} else
builtin/checkout.c
+3
-2
@@ -753,7 +753,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
753
free(refname);
754
}
755
else
756
- create_branch(opts->new_branch, new_branch_info->name,
756
+ create_branch(the_repository,
757
+ opts->new_branch, new_branch_info->name,
758
opts->new_branch_force ? 1 : 0,
759
opts->new_branch_force ? 1 : 0,
760
opts->new_branch_log,
@@ -811,7 +812,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
812
delete_reflog(old_branch_info->path);
813
}
814
}
814
- remove_branch_state();
815
+ remove_branch_state(the_repository);
816
strbuf_release(&msg);
817
if (!opts->quiet &&
818
(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
builtin/reset.c
+1
-1
@@ -400,7 +400,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
400
print_new_head_line(lookup_commit_reference(the_repository, &oid));
401
}
402
if (!pathspec.nr)
403
- remove_branch_state();
403
+ remove_branch_state(the_repository);
404
405
return update_ref_status;
406
}
builtin/revert.c
+1
-1
@@ -195,7 +195,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
195
if (cmd == 'q') {
196
int ret = sequencer_remove_state(opts);
197
if (!ret)
198
- remove_branch_state();
198
+ remove_branch_state(the_repository);
199
return ret;
200
}
201
if (cmd == 'c')