Skip to content

Commit

Permalink
abspath.h: move absolute path functions from cache.h
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
newren authored and gitster committed Mar 21, 2023
1 parent 7ee24e1 commit 0b027f6
Show file tree
Hide file tree
Showing 65 changed files with 98 additions and 28 deletions.
4 changes: 3 additions & 1 deletion abspath.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 33 additions & 0 deletions abspath.h
Original file line number Diff line number Diff line change
@@ -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 */
1 change: 1 addition & 0 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "object-store.h"
Expand Down
1 change: 1 addition & 0 deletions archive.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "abspath.h"
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/bugreport.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
#include "parse-options.h"
#include "strbuf.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/bundle.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
#include "strvec.h"
#include "parse-options.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "cache.h"
#include "config.h"
#include "dir.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "color.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/credential-cache--daemon.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "alloc.h"
#include "gettext.h"
#include "parse-options.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diagnose.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
#include "parse-options.h"
#include "diagnose.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "abspath.h"
#include "config.h"
#include "builtin.h"
#include "run-command.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "cache.h"
#include "gettext.h"
#include "hex.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/fsmonitor--daemon.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include "builtin.h"
#include "abspath.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/hash-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) Junio C Hamano, 2005
*/
#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "abspath.h"
#include "config.h"
#include "gettext.h"
#include "refs.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2006 Junio Hamano
*/
#include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* email to figure out authorship and subject
*/
#include "cache.h"
#include "abspath.h"
#include "builtin.h"
#include "gettext.h"
#include "utf8.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/merge-file.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "cache.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "environment.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/multi-pack-index.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "cache.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
#include "hex.h"
#include "run-command.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtin.h"
#include "abspath.h"
#include "repository.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "commit.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/stash.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/submodule--helper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "alloc.h"
#include "gettext.h"
#include "hex.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "checkout.h"
#include "config.h"
#include "builtin.h"
Expand Down
27 changes: 0 additions & 27 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,6 @@ const char *setup_git_directory(void);
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);

/*
* 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);
void verify_filename(const char *prefix,
const char *name,
Expand Down Expand Up @@ -1160,18 +1145,6 @@ char *interpolate_path(const char *path, int real_home);
/* NEEDSWORK: remove this synonym once in-flight topics have migrated */
#define expand_user_path interpolate_path
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 *relative_path(const char *in, const char *prefix, struct strbuf *sb);
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
Expand Down
1 change: 1 addition & 0 deletions chdir-notify.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "chdir-notify.h"
#include "list.h"
#include "strbuf.h"
Expand Down
1 change: 1 addition & 0 deletions compat/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define COMPAT_DISK_H

#include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h"

static int get_disk_info(struct strbuf *out)
Expand Down
1 change: 1 addition & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../strbuf.h"
#include "../run-command.h"
#include "../cache.h"
#include "../abspath.h"
#include "../alloc.h"
#include "win32/lazyload.h"
#include "../config.h"
Expand Down
1 change: 1 addition & 0 deletions compat/simple-ipc/ipc-win32.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "gettext.h"
#include "simple-ipc.h"
#include "strbuf.h"
Expand Down
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/
#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "date.h"
#include "branch.h"
Expand Down
1 change: 1 addition & 0 deletions credential.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "config.h"
#include "credential.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions daemon.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "pkt-line.h"
Expand Down
1 change: 1 addition & 0 deletions diff-no-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "cache.h"
#include "abspath.h"
#include "color.h"
#include "commit.h"
#include "blob.h"
Expand Down
1 change: 1 addition & 0 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "cache.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Junio Hamano, 2005-2006
*/
#include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "dir.h"
Expand Down
1 change: 1 addition & 0 deletions editor.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "config.h"
#include "gettext.h"
#include "strbuf.h"
Expand Down
1 change: 1 addition & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* are.
*/
#include "cache.h"
#include "abspath.h"
#include "branch.h"
#include "environment.h"
#include "gettext.h"
Expand Down
1 change: 1 addition & 0 deletions exec-cmd.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "abspath.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "quote.h"
Expand Down
1 change: 1 addition & 0 deletions gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

#include "cache.h"
#include "abspath.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "strbuf.h"
Expand Down
1 change: 1 addition & 0 deletions lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

#include "cache.h"
#include "abspath.h"
#include "gettext.h"
#include "lockfile.h"

Expand Down
1 change: 1 addition & 0 deletions midx.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "alloc.h"
#include "config.h"
#include "csum-file.h"
Expand Down
Loading

0 comments on commit 0b027f6

Please sign in to comment.