summaryrefslogtreecommitdiff
path: root/stagit.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-04-27 19:19:50 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-04-27 19:19:50 +0200
commit8df54926f2ad80ae46a4cc701f3341e97839e0c8 (patch)
treea93c6821454f166f9a6c62fcfadf215d1ca6ae97 /stagit.c
parent70b777831a80a7a204f02697563d39dba612c8c4 (diff)
resolve absolute paths to repodir, remove basename just use strrchr.
- resolve repodir, for example: stagit-index ../ used to use ".." as the name, now it will resolve to the real directory name. - just use strrchr(path, '/') instead of basename, '/' path separator is now used.
Diffstat (limited to 'stagit.c')
-rw-r--r--stagit.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/stagit.c b/stagit.c
index e3c921d..cbb0a77 100644
--- a/stagit.c
+++ b/stagit.c
@@ -42,7 +42,7 @@ static git_repository *repo;
static const char *relpath = "";
static const char *repodir;
-static char *name;
+static char *name = "";
static char *stripped_name;
static char description[255];
static char cloneurl[1024];
@@ -162,27 +162,6 @@ xdirname(const char *path)
return b;
}
-/* Some implementations of basename(3) return a pointer to a static
- * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
- * This is a wrapper function that is compatible with both versions.
- * The program will error out if basename(3) failed, this can only happen
- * with the OpenBSD version. */
-char *
-xbasename(const char *path)
-{
- char *p, *b;
-
- if (!(p = strdup(path)))
- err(1, "strdup");
- if (!(b = basename(p)))
- err(1, "basename");
- if (!(b = strdup(b)))
- err(1, "strdup");
- free(p);
-
- return b;
-}
-
int
mkdirp(const char *path)
{
@@ -879,7 +858,7 @@ main(int argc, char *argv[])
const git_oid *head = NULL;
const git_error *e = NULL;
FILE *fp, *fpread;
- char path[PATH_MAX], *p;
+ char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
int r, status;
if (argc != 2) {
@@ -887,6 +866,8 @@ main(int argc, char *argv[])
return 1;
}
repodir = argv[1];
+ if (!realpath(repodir, repodirabs))
+ err(1, "realpath");
git_libgit2_init();
@@ -904,7 +885,10 @@ main(int argc, char *argv[])
git_object_free(obj);
/* use directory name as name */
- name = xbasename(repodir);
+ if ((name = strrchr(repodirabs, '/')))
+ name++;
+ else
+ name = "";
/* strip .git suffix */
if (!(stripped_name = strdup(name)))