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 <lehmacdj@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Devin Lehmacher committed
Mar 13, 2017 at 16:43 UTC
e7f136bf93132c24183c168a9a054540e6216c06
2 files changed
+22
cache.h
+7
@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);
1169
*/
1170
extern char *xdg_config_home(const char *filename);
1171
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
+
1179
/* object replacement */
1180
#define LOOKUP_REPLACE_OBJECT 1
1181
#define LOOKUP_UNKNOWN_OBJECT 2
path.c
+15
@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)
1272
return NULL;
1273
}
1274
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
+
1290
GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
1291
GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
1292
GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")