move create_symref() past log_ref_write()
This doesn't change the code at all. It is done to make the next patch more obvious. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Jan 26, 2007 at 17:26 UTC
41b625b047ad5c537ca312d2f07c86bdd783a7b0
1 file changed
+47
-47
refs.c
+47
-47
@@ -309,53 +309,6 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
309
return ref;
310
}
311
312
-int create_symref(const char *ref_target, const char *refs_heads_master)
313
-{
314
- const char *lockpath;
315
- char ref[1000];
316
- int fd, len, written;
317
- const char *git_HEAD = git_path("%s", ref_target);
318
-
319
-#ifndef NO_SYMLINK_HEAD
320
- if (prefer_symlink_refs) {
321
- unlink(git_HEAD);
322
- if (!symlink(refs_heads_master, git_HEAD))
323
- return 0;
324
- fprintf(stderr, "no symlink - falling back to symbolic ref\n");
325
- }
326
-#endif
327
-
328
- len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
329
- if (sizeof(ref) <= len) {
330
- error("refname too long: %s", refs_heads_master);
331
- return -1;
332
- }
333
- lockpath = mkpath("%s.lock", git_HEAD);
334
- fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
335
- if (fd < 0) {
336
- error("Unable to open %s for writing", lockpath);
337
- return -5;
338
- }
339
- written = write_in_full(fd, ref, len);
340
- close(fd);
341
- if (written != len) {
342
- unlink(lockpath);
343
- error("Unable to write to %s", lockpath);
344
- return -2;
345
- }
346
- if (rename(lockpath, git_HEAD) < 0) {
347
- unlink(lockpath);
348
- error("Unable to create %s", git_HEAD);
349
- return -3;
350
- }
351
- if (adjust_shared_perm(git_HEAD)) {
352
- unlink(lockpath);
353
- error("Unable to fix permissions on %s", lockpath);
354
- return -4;
355
- }
356
- return 0;
357
-}
358
-
312
int read_ref(const char *ref, unsigned char *sha1)
313
{
314
if (resolve_ref(ref, sha1, 1, NULL))
@@ -1033,6 +986,53 @@ int write_ref_sha1(struct ref_lock *lock,
986
return 0;
987
}
988
989
+int create_symref(const char *ref_target, const char *refs_heads_master)
990
+{
991
+ const char *lockpath;
992
+ char ref[1000];
993
+ int fd, len, written;
994
+ const char *git_HEAD = git_path("%s", ref_target);
995
+
996
+#ifndef NO_SYMLINK_HEAD
997
+ if (prefer_symlink_refs) {
998
+ unlink(git_HEAD);
999
+ if (!symlink(refs_heads_master, git_HEAD))
1000
+ return 0;
1001
+ fprintf(stderr, "no symlink - falling back to symbolic ref\n");
1002
+ }
1003
+#endif
1004
+
1005
+ len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
1006
+ if (sizeof(ref) <= len) {
1007
+ error("refname too long: %s", refs_heads_master);
1008
+ return -1;
1009
+ }
1010
+ lockpath = mkpath("%s.lock", git_HEAD);
1011
+ fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
1012
+ if (fd < 0) {
1013
+ error("Unable to open %s for writing", lockpath);
1014
+ return -5;
1015
+ }
1016
+ written = write_in_full(fd, ref, len);
1017
+ close(fd);
1018
+ if (written != len) {
1019
+ unlink(lockpath);
1020
+ error("Unable to write to %s", lockpath);
1021
+ return -2;
1022
+ }
1023
+ if (rename(lockpath, git_HEAD) < 0) {
1024
+ unlink(lockpath);
1025
+ error("Unable to create %s", git_HEAD);
1026
+ return -3;
1027
+ }
1028
+ if (adjust_shared_perm(git_HEAD)) {
1029
+ unlink(lockpath);
1030
+ error("Unable to fix permissions on %s", lockpath);
1031
+ return -4;
1032
+ }
1033
+ return 0;
1034
+}
1035
+
1036
static char *ref_msg(const char *line, const char *endp)
1037
{
1038
const char *ep;