abspath.h: move absolute path functions from cache.h

This is another step towards letting us remove the include of cache.h in
strbuf.c.  It does mean that we also need to add includes of abspath.h
in a number of C files.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren 2023-03-21 06:25:58 +00:00 committed by Junio C Hamano
parent 7ee24e18e5
commit 0b027f6ca7
65 changed files with 98 additions and 28 deletions

View File

@ -1,4 +1,6 @@
#include "cache.h" #include "git-compat-util.h"
#include "abspath.h"
#include "strbuf.h"
/* /*
* Do not use this for inspecting *tracked* content. When path is a * Do not use this for inspecting *tracked* content. When path is a

33
abspath.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef ABSPATH_H
#define ABSPATH_H
int is_directory(const char *);
char *strbuf_realpath(struct strbuf *resolved, const char *path,
int die_on_error);
char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
int die_on_error);
char *real_pathdup(const char *path, int die_on_error);
const char *absolute_path(const char *path);
char *absolute_pathdup(const char *path);
/*
* Concatenate "prefix" (if len is non-zero) and "path", with no
* connecting characters (so "prefix" should end with a "/").
* Unlike prefix_path, this should be used if the named file does
* not have to interact with index entry; i.e. name of a random file
* on the filesystem.
*
* The return value is always a newly allocated string (even if the
* prefix was empty).
*/
char *prefix_filename(const char *prefix, const char *path);
/* Likewise, but path=="-" always yields "-" */
char *prefix_filename_except_for_dash(const char *prefix, const char *path);
static inline int is_absolute_path(const char *path)
{
return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
}
#endif /* ABSPATH_H */

View File

@ -8,6 +8,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "object-store.h" #include "object-store.h"

View File

@ -1,4 +1,5 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -5,6 +5,7 @@
*/ */
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"
#include "exec-cmd.h" #include "exec-cmd.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "parse-options.h" #include "parse-options.h"
#include "strbuf.h" #include "strbuf.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "strvec.h" #include "strvec.h"
#include "parse-options.h" #include "parse-options.h"

View File

@ -8,6 +8,7 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"

View File

@ -10,6 +10,7 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "color.h" #include "color.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "gettext.h" #include "gettext.h"
#include "parse-options.h" #include "parse-options.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "parse-options.h" #include "parse-options.h"
#include "diagnose.h" #include "diagnose.h"

View File

@ -13,6 +13,7 @@
*/ */
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "cache.h" #include "cache.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -11,6 +11,7 @@
*/ */
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "hex.h" #include "hex.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -5,6 +5,7 @@
* Copyright (C) Junio C Hamano, 2005 * Copyright (C) Junio C Hamano, 2005
*/ */
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"

View File

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "refs.h" #include "refs.h"

View File

@ -5,6 +5,7 @@
* 2006 Junio Hamano * 2006 Junio Hamano
*/ */
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -3,6 +3,7 @@
* email to figure out authorship and subject * email to figure out authorship and subject
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "builtin.h" #include "builtin.h"
#include "gettext.h" #include "gettext.h"
#include "utf8.h" #include "utf8.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -8,6 +8,7 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "environment.h" #include "environment.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -5,6 +5,7 @@
*/ */
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -6,6 +6,7 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"
#include "run-command.h" #include "run-command.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -5,6 +5,7 @@
*/ */
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "commit.h" #include "commit.h"

View File

@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"

View File

@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "checkout.h" #include "checkout.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

27
cache.h
View File

@ -598,21 +598,6 @@ const char *setup_git_directory(void);
char *prefix_path(const char *prefix, int len, const char *path); char *prefix_path(const char *prefix, int len, const char *path);
char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
/*
* Concatenate "prefix" (if len is non-zero) and "path", with no
* connecting characters (so "prefix" should end with a "/").
* Unlike prefix_path, this should be used if the named file does
* not have to interact with index entry; i.e. name of a random file
* on the filesystem.
*
* The return value is always a newly allocated string (even if the
* prefix was empty).
*/
char *prefix_filename(const char *prefix, const char *path);
/* Likewise, but path=="-" always yields "-" */
char *prefix_filename_except_for_dash(const char *prefix, const char *path);
int check_filename(const char *prefix, const char *name); int check_filename(const char *prefix, const char *name);
void verify_filename(const char *prefix, void verify_filename(const char *prefix,
const char *name, const char *name,
@ -1160,18 +1145,6 @@ char *interpolate_path(const char *path, int real_home);
/* NEEDSWORK: remove this synonym once in-flight topics have migrated */ /* NEEDSWORK: remove this synonym once in-flight topics have migrated */
#define expand_user_path interpolate_path #define expand_user_path interpolate_path
const char *enter_repo(const char *path, int strict); const char *enter_repo(const char *path, int strict);
static inline int is_absolute_path(const char *path)
{
return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
}
int is_directory(const char *);
char *strbuf_realpath(struct strbuf *resolved, const char *path,
int die_on_error);
char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path,
int die_on_error);
char *real_pathdup(const char *path, int die_on_error);
const char *absolute_path(const char *path);
char *absolute_pathdup(const char *path);
const char *remove_leading_path(const char *in, const char *prefix); const char *remove_leading_path(const char *in, const char *prefix);
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len); int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "chdir-notify.h" #include "chdir-notify.h"
#include "list.h" #include "list.h"
#include "strbuf.h" #include "strbuf.h"

View File

@ -2,6 +2,7 @@
#define COMPAT_DISK_H #define COMPAT_DISK_H
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
static int get_disk_info(struct strbuf *out) static int get_disk_info(struct strbuf *out)

View File

@ -7,6 +7,7 @@
#include "../strbuf.h" #include "../strbuf.h"
#include "../run-command.h" #include "../run-command.h"
#include "../cache.h" #include "../cache.h"
#include "../abspath.h"
#include "../alloc.h" #include "../alloc.h"
#include "win32/lazyload.h" #include "win32/lazyload.h"
#include "../config.h" #include "../config.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "simple-ipc.h" #include "simple-ipc.h"
#include "strbuf.h" #include "strbuf.h"

View File

@ -6,6 +6,7 @@
* *
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "date.h" #include "date.h"
#include "branch.h" #include "branch.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "credential.h" #include "credential.h"
#include "gettext.h" #include "gettext.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "pkt-line.h" #include "pkt-line.h"

View File

@ -5,6 +5,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "color.h" #include "color.h"
#include "commit.h" #include "commit.h"
#include "blob.h" #include "blob.h"

1
diff.c
View File

@ -2,6 +2,7 @@
* Copyright (C) 2005 Junio C Hamano * Copyright (C) 2005 Junio C Hamano
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

1
dir.c
View File

@ -6,6 +6,7 @@
* Junio Hamano, 2005-2006 * Junio Hamano, 2005-2006
*/ */
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "strbuf.h" #include "strbuf.h"

View File

@ -8,6 +8,7 @@
* are. * are.
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "branch.h" #include "branch.h"
#include "environment.h" #include "environment.h"
#include "gettext.h" #include "gettext.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "gettext.h" #include "gettext.h"
#include "quote.h" #include "quote.h"

View File

@ -3,6 +3,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "gettext.h" #include "gettext.h"
#include "strbuf.h" #include "strbuf.h"

View File

@ -3,6 +3,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "lockfile.h" #include "lockfile.h"

1
midx.c
View File

@ -1,4 +1,5 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "csum-file.h" #include "csum-file.h"

View File

@ -7,6 +7,7 @@
* creation etc. * creation etc.
*/ */
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -1,5 +1,6 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "parse-options.h" #include "parse-options.h"
#include "abspath.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "commit.h" #include "commit.h"

1
path.c
View File

@ -2,6 +2,7 @@
* Utilities for paths and pathnames * Utilities for paths and pathnames
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "hex.h" #include "hex.h"
#include "repository.h" #include "repository.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"
#include "gettext.h" #include "gettext.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -4,6 +4,7 @@
*/ */
#define USE_THE_INDEX_VARIABLE #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "repository.h" #include "repository.h"
#include "object-store.h" #include "object-store.h"
#include "config.h" #include "config.h"

View File

@ -1,4 +1,5 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"

View File

@ -3,6 +3,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "parse-options.h" #include "parse-options.h"
#include "config.h" #include "config.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "config.h" #include "config.h"
#include "environment.h" #include "environment.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "gettext.h" #include "gettext.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "environment.h" #include "environment.h"
#include "gettext.h" #include "gettext.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -1,5 +1,6 @@
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "string-list.h" #include "string-list.h"
#include "utf8.h" #include "utf8.h"

View File

@ -1,5 +1,6 @@
#include "cache.h" #include "cache.h"
#include "tmp-objdir.h" #include "tmp-objdir.h"
#include "abspath.h"
#include "chdir-notify.h" #include "chdir-notify.h"
#include "dir.h" #include "dir.h"
#include "sigchain.h" #include "sigchain.h"

View File

@ -22,6 +22,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "quote.h" #include "quote.h"
struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "sigchain.h" #include "sigchain.h"
#include "trace2/tr2_dst.h" #include "trace2/tr2_dst.h"
#include "trace2/tr2_sid.h" #include "trace2/tr2_sid.h"

View File

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "alloc.h" #include "alloc.h"
#include "gettext.h" #include "gettext.h"
#include "repository.h" #include "repository.h"

View File

@ -2,6 +2,7 @@
* Various trivial helper wrappers around standard functions * Various trivial helper wrappers around standard functions
*/ */
#include "cache.h" #include "cache.h"
#include "abspath.h"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"