-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] Implement git-checkout-cache -u to update stat information in…
… the cache. With -u flag, git-checkout-cache picks up the stat information from newly created file and updates the cache. This removes the need to run git-update-cache --refresh immediately after running git-checkout-cache. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
- Loading branch information
Junio C Hamano
authored and
Linus Torvalds
committed
May 19, 2005
1 parent
875d0f8
commit 415e96c
Showing
8 changed files
with
157 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2005, Junio C Hamano | ||
*/ | ||
#include <signal.h> | ||
#include "cache.h" | ||
|
||
static struct cache_file *cache_file_list; | ||
|
||
static void remove_lock_file(void) | ||
{ | ||
while (cache_file_list) { | ||
if (cache_file_list->lockfile[0]) | ||
unlink(cache_file_list->lockfile); | ||
cache_file_list = cache_file_list->next; | ||
} | ||
} | ||
|
||
static void remove_lock_file_on_signal(int signo) | ||
{ | ||
remove_lock_file(); | ||
} | ||
|
||
int hold_index_file_for_update(struct cache_file *cf, const char *path) | ||
{ | ||
sprintf(cf->lockfile, "%s.lock", path); | ||
cf->next = cache_file_list; | ||
cache_file_list = cf; | ||
if (!cf->next) { | ||
signal(SIGINT, remove_lock_file_on_signal); | ||
atexit(remove_lock_file); | ||
} | ||
return open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0600); | ||
} | ||
|
||
int commit_index_file(struct cache_file *cf) | ||
{ | ||
char indexfile[PATH_MAX]; | ||
int i; | ||
strcpy(indexfile, cf->lockfile); | ||
i = strlen(indexfile) - 5; /* .lock */ | ||
indexfile[i] = 0; | ||
i = rename(cf->lockfile, indexfile); | ||
cf->lockfile[0] = 0; | ||
return i; | ||
} | ||
|
||
void rollback_index_file(struct cache_file *cf) | ||
{ | ||
if (cf->lockfile[0]) | ||
unlink(cf->lockfile); | ||
cf->lockfile[0] = 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (c) 2005 Junio C Hamano | ||
# | ||
|
||
test_description='git-checkout-cache -u test. | ||
With -u flag, git-checkout-cache internally runs the equivalent of | ||
git-update-cache --refresh on the checked out entry.' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success \ | ||
'preparation' ' | ||
echo frotz >path0 && | ||
git-update-cache --add path0 && | ||
t=$(git-write-tree)' | ||
|
||
test_expect_failure \ | ||
'without -u, git-checkout-cache smudges stat information.' ' | ||
rm -f path0 && | ||
git-read-tree $t && | ||
git-checkout-cache -f -a && | ||
git-diff-files | diff - /dev/null' | ||
|
||
test_expect_success \ | ||
'with -u, git-checkout-cache picks up stat information from new files.' ' | ||
rm -f path0 && | ||
git-read-tree $t && | ||
git-checkout-cache -u -f -a && | ||
git-diff-files | diff - /dev/null' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters