~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to path.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20070422133105-xg8fnm18r2cxcbg1
Tags: upstream-1.5.1.2
ImportĀ upstreamĀ versionĀ 1.5.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * which is what it's designed for.
12
12
 */
13
13
#include "cache.h"
14
 
#include <pwd.h>
15
14
 
16
15
static char bad_path[] = "/bad-path/";
17
16
 
91
90
}
92
91
 
93
92
 
94
 
int validate_symref(const char *path)
 
93
int validate_headref(const char *path)
95
94
{
96
95
        struct stat st;
97
96
        char *buf, buffer[256];
 
97
        unsigned char sha1[20];
98
98
        int len, fd;
99
99
 
100
100
        if (lstat(path, &st) < 0)
114
114
        fd = open(path, O_RDONLY);
115
115
        if (fd < 0)
116
116
                return -1;
117
 
        len = read(fd, buffer, sizeof(buffer)-1);
 
117
        len = read_in_full(fd, buffer, sizeof(buffer)-1);
118
118
        close(fd);
119
119
 
120
120
        /*
121
121
         * Is it a symbolic ref?
122
122
         */
123
 
        if (len < 4 || memcmp("ref:", buffer, 4))
 
123
        if (len < 4)
124
124
                return -1;
125
 
        buf = buffer + 4;
126
 
        len -= 4;
127
 
        while (len && isspace(*buf))
128
 
                buf++, len--;
129
 
        if (len >= 5 && !memcmp("refs/", buf, 5))
 
125
        if (!memcmp("ref:", buffer, 4)) {
 
126
                buf = buffer + 4;
 
127
                len -= 4;
 
128
                while (len && isspace(*buf))
 
129
                        buf++, len--;
 
130
                if (len >= 5 && !memcmp("refs/", buf, 5))
 
131
                        return 0;
 
132
        }
 
133
 
 
134
        /*
 
135
         * Is this a detached HEAD?
 
136
         */
 
137
        if (!get_sha1_hex(buffer, sha1))
130
138
                return 0;
 
139
 
131
140
        return -1;
132
141
}
133
142
 
242
251
                return NULL;
243
252
 
244
253
        if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
245
 
            validate_symref("HEAD") == 0) {
246
 
                putenv("GIT_DIR=.");
 
254
            validate_headref("HEAD") == 0) {
 
255
                setenv("GIT_DIR", ".", 1);
247
256
                check_repository_format();
248
257
                return path;
249
258
        }