summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-08-21 23:27:59 -0700
committerJunio C Hamano <gitster@pobox.com>2010-08-21 23:27:59 -0700
commit2d984464c6be7ced6772a8dcf95d6a461a659a78 (patch)
treeebde8778f17609acc0587524636ec4862c065ca9 /path.c
parentd25c72f7da5116f7b7a1f88a59d2bc14415a03b2 (diff)
parent68d03e4a6e448aa557f52adef92595ac4d6cd4bd (diff)
downloadgit-2d984464c6be7ced6772a8dcf95d6a461a659a78.tar.gz
Merge branch 'hv/submodule-find-ff-merge'
* hv/submodule-find-ff-merge: Implement automatic fast-forward merge for submodules setup_revisions(): Allow walking history in a submodule Teach ref iteration module about submodules Conflicts: submodule.c
Diffstat (limited to 'path.c')
-rw-r--r--path.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/path.c b/path.c
index 6b23023095..a2c9d1e24a 100644
--- a/path.c
+++ b/path.c
@@ -122,6 +122,44 @@ char *git_path(const char *fmt, ...)
return cleanup_path(pathname);
}
+char *git_path_submodule(const char *path, const char *fmt, ...)
+{
+ char *pathname = get_pathname();
+ struct strbuf buf = STRBUF_INIT;
+ const char *git_dir;
+ va_list args;
+ unsigned len;
+
+ len = strlen(path);
+ if (len > PATH_MAX-100)
+ return bad_path;
+
+ strbuf_addstr(&buf, path);
+ if (len && path[len-1] != '/')
+ strbuf_addch(&buf, '/');
+ strbuf_addstr(&buf, ".git");
+
+ git_dir = read_gitfile_gently(buf.buf);
+ if (git_dir) {
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, git_dir);
+ }
+ strbuf_addch(&buf, '/');
+
+ if (buf.len >= PATH_MAX)
+ return bad_path;
+ memcpy(pathname, buf.buf, buf.len + 1);
+
+ strbuf_release(&buf);
+ len = strlen(pathname);
+
+ va_start(args, fmt);
+ len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
+ va_end(args);
+ if (len >= PATH_MAX)
+ return bad_path;
+ return cleanup_path(pathname);
+}
/* git_mkstemp() - create tmp file honoring TMPDIR variable */
int git_mkstemp(char *path, size_t len, const char *template)