Skip to content

Commit e7f136b

Browse files
lehmacdjgitster
authored andcommitted
path.c: add xdg_cache_home
We already have xdg_config_home to format paths relative to XDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do the same for paths relative to XDG_CACHE_HOME. Signed-off-by: Devin Lehmacher <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6db3f2 commit e7f136b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cache.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);
11691169
*/
11701170
extern char *xdg_config_home(const char *filename);
11711171

1172+
/**
1173+
* Return a newly allocated string with the evaluation of
1174+
* "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
1175+
* "$HOME/.cache/git/$filename". Return NULL upon error.
1176+
*/
1177+
extern char *xdg_cache_home(const char *filename);
1178+
11721179
/* object replacement */
11731180
#define LOOKUP_REPLACE_OBJECT 1
11741181
#define LOOKUP_UNKNOWN_OBJECT 2

path.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)
12721272
return NULL;
12731273
}
12741274

1275+
char *xdg_cache_home(const char *filename)
1276+
{
1277+
const char *home, *cache_home;
1278+
1279+
assert(filename);
1280+
cache_home = getenv("XDG_CACHE_HOME");
1281+
if (cache_home && *cache_home)
1282+
return mkpathdup("%s/git/%s", cache_home, filename);
1283+
1284+
home = getenv("HOME");
1285+
if (home)
1286+
return mkpathdup("%s/.cache/git/%s", home, filename);
1287+
return NULL;
1288+
}
1289+
12751290
GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
12761291
GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
12771292
GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")

0 commit comments

Comments
 (0)