read-cache: relocate and unexport commit_locked_index()

This function is now only used by write_locked_index(). Move it to read-cache.c (because read-cache.c will need to be aware of alternate_index_output later) and unexport it. 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 Jun 13, 2014 at 19:19 UTC 626f35c89332059980251f7cdf8e94bc49d68834
3 files changed +20 -21
cache.h
-1
@@ -552,7 +552,6 @@ extern int commit_lock_file(struct lock_file *);
552 extern void update_index_if_able(struct index_state *, struct lock_file *);
553
554 extern int hold_locked_index(struct lock_file *, int);
555 -extern int commit_locked_index(struct lock_file *);
555 extern void set_alternate_index_output(const char *);
556 extern int close_lock_file(struct lock_file *);
557 extern void rollback_lock_file(struct lock_file *);
lockfile.c
-20
@@ -5,7 +5,6 @@
5 #include "sigchain.h"
6
7 static struct lock_file *lock_file_list;
8 -static const char *alternate_index_output;
8
9 static void remove_lock_file(void)
10 {
@@ -252,25 +251,6 @@ int hold_locked_index(struct lock_file *lk, int die_on_error)
251 : 0);
252 }
253
255 -void set_alternate_index_output(const char *name)
256 -{
257 - alternate_index_output = name;
258 -}
259 -
260 -int commit_locked_index(struct lock_file *lk)
261 -{
262 - if (alternate_index_output) {
263 - if (lk->fd >= 0 && close_lock_file(lk))
264 - return -1;
265 - if (rename(lk->filename, alternate_index_output))
266 - return -1;
267 - lk->filename[0] = 0;
268 - return 0;
269 - }
270 - else
271 - return commit_lock_file(lk);
272 -}
273 -
254 void rollback_lock_file(struct lock_file *lk)
255 {
256 if (lk->filename[0]) {
read-cache.c
+20
@@ -36,6 +36,7 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
36 #define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
37
38 struct index_state the_index;
39 +static const char *alternate_index_output;
40
41 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
42 {
@@ -1875,6 +1876,25 @@ static int do_write_index(struct index_state *istate, int newfd)
1876 return 0;
1877 }
1878
1879 +void set_alternate_index_output(const char *name)
1880 +{
1881 + alternate_index_output = name;
1882 +}
1883 +
1884 +static int commit_locked_index(struct lock_file *lk)
1885 +{
1886 + if (alternate_index_output) {
1887 + if (lk->fd >= 0 && close_lock_file(lk))
1888 + return -1;
1889 + if (rename(lk->filename, alternate_index_output))
1890 + return -1;
1891 + lk->filename[0] = 0;
1892 + return 0;
1893 + } else {
1894 + return commit_lock_file(lk);
1895 + }
1896 +}
1897 +
1898 static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
1899 unsigned flags)
1900 {