@@ -1090,6 +1090,15 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
1090
1090
return ret ;
1091
1091
}
1092
1092
1093
+ /*
1094
+ * People using contrib's git-new-workdir have .git/logs/refs ->
1095
+ * /some/other/path/.git/logs/refs, and that may live on another device.
1096
+ *
1097
+ * IOW, to avoid cross device rename errors, the temporary renamed log must
1098
+ * live into logs/refs.
1099
+ */
1100
+ #define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
1101
+
1093
1102
int rename_ref (const char * oldref , const char * newref , const char * logmsg )
1094
1103
{
1095
1104
static const char renamed_ref [] = "RENAMED-REF" ;
@@ -1123,8 +1132,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1123
1132
if (write_ref_sha1 (lock , orig_sha1 , logmsg ))
1124
1133
return error ("unable to save current sha1 in %s" , renamed_ref );
1125
1134
1126
- if (log && rename (git_path ("logs/%s" , oldref ), git_path ("tmp-renamed-log" )))
1127
- return error ("unable to move logfile logs/%s to tmp-renamed-log : %s" ,
1135
+ if (log && rename (git_path ("logs/%s" , oldref ), git_path (TMP_RENAMED_LOG )))
1136
+ return error ("unable to move logfile logs/%s to " TMP_RENAMED_LOG " : %s" ,
1128
1137
oldref , strerror (errno ));
1129
1138
1130
1139
if (delete_ref (oldref , orig_sha1 , REF_NODEREF )) {
@@ -1150,7 +1159,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1150
1159
}
1151
1160
1152
1161
retry :
1153
- if (log && rename (git_path ("tmp-renamed-log" ), git_path ("logs/%s" , newref ))) {
1162
+ if (log && rename (git_path (TMP_RENAMED_LOG ), git_path ("logs/%s" , newref ))) {
1154
1163
if (errno == EISDIR || errno == ENOTDIR ) {
1155
1164
/*
1156
1165
* rename(a, b) when b is an existing
@@ -1163,7 +1172,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1163
1172
}
1164
1173
goto retry ;
1165
1174
} else {
1166
- error ("unable to move logfile tmp-renamed-log to logs/%s: %s" ,
1175
+ error ("unable to move logfile " TMP_RENAMED_LOG " to logs/%s: %s" ,
1167
1176
newref , strerror (errno ));
1168
1177
goto rollback ;
1169
1178
}
@@ -1203,8 +1212,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1203
1212
error ("unable to restore logfile %s from %s: %s" ,
1204
1213
oldref , newref , strerror (errno ));
1205
1214
if (!logmoved && log &&
1206
- rename (git_path ("tmp-renamed-log" ), git_path ("logs/%s" , oldref )))
1207
- error ("unable to restore logfile %s from tmp-renamed-log : %s" ,
1215
+ rename (git_path (TMP_RENAMED_LOG ), git_path ("logs/%s" , oldref )))
1216
+ error ("unable to restore logfile %s from " TMP_RENAMED_LOG " : %s" ,
1208
1217
oldref , strerror (errno ));
1209
1218
1210
1219
return 1 ;
0 commit comments