diff options
author | David Turner <dturner@twopensource.com> | 2015-07-21 17:04:52 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-07-21 14:07:59 -0700 |
commit | abd0cd3a3018e1c4e9e4437fb3911d6658e99fec (patch) | |
tree | f6d25ec6ea6d7ee8897f0f2b45fe7cfecbd47285 /builtin/checkout.c | |
parent | 4e2bef57c9629ef869091d9ad41dc6d09528a662 (diff) | |
download | git-abd0cd3a3018e1c4e9e4437fb3911d6658e99fec.tar.gz |
refs: new public ref function: safe_create_reflog
The safe_create_reflog function creates a reflog, if it does not
already exist.
The log_ref_setup function becomes private and gains a force_create
parameter to force the creation of a reflog even if log_all_ref_updates
is false or the refname is not one of the special refnames.
The new parameter also reduces the need to store, modify, and restore
the log_all_ref_updates global before reflog creation.
In a moment, we will use this to add reflog creation commands to
git-reflog.
Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 8faa2d141d..3eaa73b983 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -619,24 +619,20 @@ static void update_refs_for_switch(const struct checkout_opts *opts, if (opts->new_branch) { if (opts->new_orphan_branch) { if (opts->new_branch_log && !log_all_ref_updates) { - int temp; - struct strbuf log_file = STRBUF_INIT; int ret; - const char *ref_name; + char *refname; struct strbuf err = STRBUF_INIT; - ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch); - temp = log_all_ref_updates; - log_all_ref_updates = 1; - ret = log_ref_setup(ref_name, &log_file, &err); - log_all_ref_updates = temp; - strbuf_release(&log_file); + refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch); + ret = safe_create_reflog(refname, 1, &err); + free(refname); if (ret) { fprintf(stderr, _("Can not do reflog for '%s': %s\n"), opts->new_orphan_branch, err.buf); strbuf_release(&err); return; } + strbuf_release(&err); } } else |