summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a662e8)
raw | patch | inline | side by side (parent: 7a662e8)
author | Linus Torvalds <torvalds@g5.osdl.org> | |
Tue, 5 Jul 2005 18:31:32 +0000 (11:31 -0700) | ||
committer | Linus Torvalds <torvalds@g5.osdl.org> | |
Tue, 5 Jul 2005 18:31:32 +0000 (11:31 -0700) |
"git_path()" returns a static pathname pointer into the git directory
using a printf-like format specifier.
"head_ref()" works like "for_each_ref()", except for just the HEAD.
using a printf-like format specifier.
"head_ref()" works like "for_each_ref()", except for just the HEAD.
cache.h | patch | blob | history | |
fetch-pack.c | patch | blob | history | |
refs.c | patch | blob | history | |
refs.h | patch | blob | history | |
send-pack.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
upload-pack.c | patch | blob | history |
index c79c70f713b16975c0622eb69d4a172cc73307ba..c84e797fdb4f6988a6a8a3294ee6de5d11951276 100644 (file)
--- a/cache.h
+++ b/cache.h
#define TYPE_CHANGED 0x0040
/* Return a statically allocated filename matching the sha1 signature */
+extern char *git_path(const char *fmt, ...);
extern char *sha1_file_name(const unsigned char *sha1);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
diff --git a/fetch-pack.c b/fetch-pack.c
index b8367a4d625fdfe59cf30e0a4aed40443139c40c..a4c1eccf7132f33674f631f50681fa5ce0f30dba 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
static int get_old_sha1(const char *refname, unsigned char *sha1)
{
- static char pathname[PATH_MAX];
- const char *git_dir;
int fd, ret;
- git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
- snprintf(pathname, sizeof(pathname), "%s/%s", git_dir, refname);
- fd = open(pathname, O_RDONLY);
+ fd = open(git_path("%s", refname), O_RDONLY);
ret = -1;
if (fd >= 0) {
char buffer[60];
index 7ccd721a4abdfec68fa9cab1f380569152fe61e9..6ca04d3b0fb4b9c40e816820309fd879ffc1d40b 100644 (file)
--- a/refs.c
+++ b/refs.c
return retval;
}
+int head_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+ unsigned char sha1[20];
+ const char *headpath = git_path("HEAD");
+ if (!read_ref(headpath, sha1))
+ fn(headpath, sha1);
+ return do_for_each_ref(get_refs_directory(), fn);
+}
+
int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
{
return do_for_each_ref(get_refs_directory(), fn);
index a79cb13cd9027aa451716556207d4619a881b2f7..26255967013c7fa4086681bba7636efb4b0157ec 100644 (file)
--- a/refs.h
+++ b/refs.h
* Calls the specified function for each ref file until it returns nonzero,
* and returns the value
*/
+extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));
extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));
/** Reads the refs file specified into sha1 **/
diff --git a/send-pack.c b/send-pack.c
index f098acb5fd0510285fa5d4aa63460a57e8183bda..7287c3df828f89a4fa90ceb84b5e0df6bf23d901 100644 (file)
--- a/send-pack.c
+++ b/send-pack.c
static int read_ref(const char *ref, unsigned char *sha1)
{
int fd, ret;
- static char pathname[PATH_MAX];
char buffer[60];
- const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
- snprintf(pathname, sizeof(pathname), "%s/%s", git_dir, ref);
- fd = open(pathname, O_RDONLY);
+ fd = open(git_path("%s", ref), O_RDONLY);
if (fd < 0)
return -1;
ret = -1;
diff --git a/sha1_file.c b/sha1_file.c
index 8f20e2f82182a2ab25d7f07a13ac038faececcbc..74dc2aab26c0e9f87e9238686ad0a077b1570d4a 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return git_index_file;
}
-int get_sha1(const char *str, unsigned char *sha1)
+char *git_path(const char *fmt, ...)
{
static char pathname[PATH_MAX];
+ va_list args;
+ int len;
+
+ if (!git_dir)
+ setup_git_env();
+ len = strlen(git_dir);
+ if (len == 1 && *git_dir == '.')
+ len = 0;
+ if (len > PATH_MAX-100)
+ return "pad-path";
+ memcpy(pathname, git_dir, len);
+ if (len && git_dir[len-1] != '/')
+ pathname[len++] = '/';
+ va_start(args, fmt);
+ vsnprintf(pathname + len, sizeof(pathname) - len, fmt, args);
+ va_end(args);
+ return pathname;
+}
+
+int get_sha1(const char *str, unsigned char *sha1)
+{
static const char *prefix[] = {
"",
"refs",
if (!get_sha1_hex(str, sha1))
return 0;
- if (!git_dir)
- setup_git_env();
for (p = prefix; *p; p++) {
- snprintf(pathname, sizeof(pathname), "%s/%s/%s",
- git_dir, *p, str);
+ char * pathname = git_path("%s/%s", *p, str);
if (!get_sha1_file(pathname, sha1))
return 0;
}
diff --git a/upload-pack.c b/upload-pack.c
index d35c0685ce2269cec48d19fbf6b0499374a34b7e..9edbf51dc5aac854943ad34c001b11850000e2a7 100644 (file)
--- a/upload-pack.c
+++ b/upload-pack.c
static int upload_pack(void)
{
+ head_ref(send_ref);
for_each_ref(send_ref);
packet_flush(1);
nr_needs = receive_needs();