@matheusbsbs / matheus-bagliano / commits / 463db9b104
Fork 0

wrapper: move odb_* to environment.c

The odb_mkstemp and odb_pack_keep functions open files under the $GIT_OBJECT_DIRECTORY directory. This requires access to the git configuration which very simple programs do not need. Move these functions to environment.o, closer to their dependencies. This should make it easier for programs to link to wrapper.o without linking to environment.o. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 6, 2010 at 06:45 UTC 463db9b104b5db7d574ce4c5ede8caaa6d02ff4c
3 files changed +38 -37
environment.c
+37
@@ -171,6 +171,43 @@ char *get_object_directory(void)
171 return git_object_dir;
172 }
173
174 +int odb_mkstemp(char *template, size_t limit, const char *pattern)
175 +{
176 + int fd;
177 + /*
178 + * we let the umask do its job, don't try to be more
179 + * restrictive except to remove write permission.
180 + */
181 + int mode = 0444;
182 + snprintf(template, limit, "%s/%s",
183 + get_object_directory(), pattern);
184 + fd = git_mkstemp_mode(template, mode);
185 + if (0 <= fd)
186 + return fd;
187 +
188 + /* slow path */
189 + /* some mkstemp implementations erase template on failure */
190 + snprintf(template, limit, "%s/%s",
191 + get_object_directory(), pattern);
192 + safe_create_leading_directories(template);
193 + return xmkstemp_mode(template, mode);
194 +}
195 +
196 +int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
197 +{
198 + int fd;
199 +
200 + snprintf(name, namesz, "%s/pack/pack-%s.keep",
201 + get_object_directory(), sha1_to_hex(sha1));
202 + fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
203 + if (0 <= fd)
204 + return fd;
205 +
206 + /* slow path */
207 + safe_create_leading_directories(name);
208 + return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
209 +}
210 +
211 char *get_index_file(void)
212 {
213 if (!git_index_file)
git-compat-util.h
+1
@@ -404,6 +404,7 @@ extern ssize_t xwrite(int fd, const void *buf, size_t len);
404 extern int xdup(int fd);
405 extern FILE *xfdopen(int fd, const char *mode);
406 extern int xmkstemp(char *template);
407 +extern int xmkstemp_mode(char *template, int mode);
408 extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
409 extern int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1);
410
wrapper.c
-37
@@ -274,43 +274,6 @@ int git_inflate(z_streamp strm, int flush)
274 return ret;
275 }
276
277 -int odb_mkstemp(char *template, size_t limit, const char *pattern)
278 -{
279 - int fd;
280 - /*
281 - * we let the umask do its job, don't try to be more
282 - * restrictive except to remove write permission.
283 - */
284 - int mode = 0444;
285 - snprintf(template, limit, "%s/%s",
286 - get_object_directory(), pattern);
287 - fd = git_mkstemp_mode(template, mode);
288 - if (0 <= fd)
289 - return fd;
290 -
291 - /* slow path */
292 - /* some mkstemp implementations erase template on failure */
293 - snprintf(template, limit, "%s/%s",
294 - get_object_directory(), pattern);
295 - safe_create_leading_directories(template);
296 - return xmkstemp_mode(template, mode);
297 -}
298 -
299 -int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
300 -{
301 - int fd;
302 -
303 - snprintf(name, namesz, "%s/pack/pack-%s.keep",
304 - get_object_directory(), sha1_to_hex(sha1));
305 - fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
306 - if (0 <= fd)
307 - return fd;
308 -
309 - /* slow path */
310 - safe_create_leading_directories(name);
311 - return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
312 -}
313 -
277 static int warn_if_unremovable(const char *op, const char *file, int rc)
278 {
279 if (rc < 0) {