From 4da588357a4a8b73f6a8d9c24435dabee74d0a7e Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 6 May 2014 15:45:52 -0700 Subject: refs.c: add new functions reflog_exists and delete_reflog Add two new functions, reflog_exists and delete_reflog, to hide the internal reflog implementation (that they are files under .git/logs/...) from callers. Update checkout.c to use these functions in update_refs_for_switch instead of building pathnames and calling out to file access functions. Update reflog.c to use these to check if the reflog exists. Now there are still many places in reflog.c where we are still leaking the reflog storage implementation but this at least reduces the number of such dependencies by one. Finally change two places in refs.c itself to use the new function to check if a ref exists or not isntead of build-path-and-stat(). Now, this is strictly not all that important since these are in parts of refs that are implementing the actual file storage backend but on the other hand it will not hurt either. Signed-off-by: Ronnie Sahlberg Acked-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/checkout.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index 07cf555309..d3fc3a8532 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,12 +651,11 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char log_file[PATH_MAX], ref_file[PATH_MAX]; + char ref_file[PATH_MAX]; - git_snpath(log_file, sizeof(log_file), "logs/%s", old->path); git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && file_exists(log_file)) - remove_path(log_file); + if (!file_exists(ref_file) && reflog_exists(old->path)) + delete_reflog(old->path); } } remove_branch_state(); -- cgit v1.2.1 From 482b8f3208e797f00db58edd7ff0d67275e898f5 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 6 May 2014 15:45:53 -0700 Subject: checkout.c: use ref_exists instead of file_exist Change checkout.c to check if a ref exists instead of checking if a loose ref file exists when deciding if to delete an orphaned log file. Otherwise, if a ref only exists as a packed ref without a corresponding loose ref for the currently checked out branch, we risk that the reflog will be deleted when we switch to a different branch. Update the reflog tests to check for this bug. The following reproduces the bug: $ git init-db $ git config core.logallrefupdates true $ git commit -m Initial --allow-empty [master (root-commit) bb11abe] Initial $ git reflog master [8561dcb master@{0}: commit (initial): Initial] $ find .git/{refs,logs} -type f | grep master [.git/refs/heads/master] [.git/logs/refs/heads/master] $ git branch foo $ git pack-refs --all $ find .git/{refs,logs} -type f | grep master [.git/logs/refs/heads/master] $ git checkout foo $ find .git/{refs,logs} -type f | grep master ... reflog file is missing ... $ git reflog master ... nothing ... Signed-off-by: Ronnie Sahlberg Acked-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/checkout.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index d3fc3a8532..c4db4ca931 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,10 +651,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char ref_file[PATH_MAX]; - - git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && reflog_exists(old->path)) + if (!ref_exists(old->path) && reflog_exists(old->path)) delete_reflog(old->path); } } -- cgit v1.2.1