X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=refs.c;h=d2b7b7fb56f76294bb48526496429968d86e49b2;hb=885b98107547fe3f6d17ca0af0578e040f7600d0;hp=7e07fc4cb5b6bc32f5c75211aff636421f9e14d5;hpb=ecea1ed5fe18a00bfca546d20de8ed8759c35ff6;p=git.git diff --git a/refs.c b/refs.c index 7e07fc4cb..d2b7b7fb5 100644 --- a/refs.c +++ b/refs.c @@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg) goto rollback; } - if (!strncmp(oldref, "refs/heads/", 11) && - !strncmp(newref, "refs/heads/", 11)) { - char oldsection[1024], newsection[1024]; - - snprintf(oldsection, 1024, "branch.%s", oldref + 11); - snprintf(newsection, 1024, "branch.%s", newref + 11); - if (git_config_rename_section(oldsection, newsection) < 0) - return 1; - } - return 0; rollback: @@ -894,8 +884,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, log_file = git_path("logs/%s", ref_name); if (log_all_ref_updates && - (!strncmp(ref_name, "refs/heads/", 11) || - !strncmp(ref_name, "refs/remotes/", 13) || + (!prefixcmp(ref_name, "refs/heads/") || + !prefixcmp(ref_name, "refs/remotes/") || !strcmp(ref_name, "HEAD"))) { if (safe_create_leading_directories(log_file) < 0) return error("unable to create directory for %s", @@ -921,6 +911,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, log_file, strerror(errno)); } + adjust_shared_perm(log_file); + msglen = 0; if (msg) { /* clean up the message and make sure it is a single line */ @@ -978,6 +970,27 @@ int write_ref_sha1(struct ref_lock *lock, unlock_ref(lock); return -1; } + if (strcmp(lock->orig_ref_name, "HEAD") != 0) { + /* + * Special hack: If a branch is updated directly and HEAD + * points to it (may happen on the remote side of a push + * for example) then logically the HEAD reflog should be + * updated too. + * A generic solution implies reverse symref information, + * but finding all symrefs pointing to the given branch + * would be rather costly for this rare event (the direct + * update of a branch) to be worth it. So let's cheat and + * check with HEAD only which should cover 99% of all usage + * scenarios (even 100% of the default ones). + */ + unsigned char head_sha1[20]; + int head_flag; + const char *head_ref; + head_ref = resolve_ref("HEAD", head_sha1, 1, &head_flag); + if (head_ref && (head_flag & REF_ISSYMREF) && + !strcmp(head_ref, lock->ref_name)) + log_ref_write("HEAD", lock->old_sha1, sha1, logmsg); + } if (commit_lock_file(lock->lk)) { error("Couldn't set %s", lock->ref_name); unlock_ref(lock); @@ -1000,6 +1013,9 @@ int create_symref(const char *ref_target, const char *refs_heads_master, if (logmsg && read_ref(ref_target, old_sha1)) hashclr(old_sha1); + if (safe_create_leading_directories(git_HEAD) < 0) + return error("unable to create directory for %s", git_HEAD); + #ifndef NO_SYMLINK_HEAD if (prefer_symlink_refs) { unlink(git_HEAD); @@ -1039,7 +1055,9 @@ int create_symref(const char *ref_target, const char *refs_heads_master, return -1; } +#ifndef NO_SYMLINK_HEAD done: +#endif if (logmsg && !read_ref(refs_heads_master, new_sha1)) log_ref_write(ref_target, old_sha1, new_sha1, logmsg); @@ -1070,6 +1088,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * unsigned long date; unsigned char logged_sha1[20]; void *log_mapped; + size_t mapsz; logfile = git_path("logs/%s", ref); logfd = open(logfile, O_RDONLY, 0); @@ -1078,7 +1097,8 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * fstat(logfd, &st); if (!st.st_size) die("Log %s is empty.", logfile); - log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0); + mapsz = xsize_t(st.st_size); + log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0); logdata = log_mapped; close(logfd); @@ -1131,7 +1151,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * logfile, show_rfc2822_date(date, tz)); } } - munmap(log_mapped, st.st_size); + munmap(log_mapped, mapsz); return 0; } lastrec = rec; @@ -1150,7 +1170,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * die("Log %s is corrupt.", logfile); if (msg) *msg = ref_msg(logdata, logend); - munmap(log_mapped, st.st_size); + munmap(log_mapped, mapsz); if (cutoff_time) *cutoff_time = date; @@ -1189,12 +1209,14 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data) !message || message[0] != ' ' || (message[1] != '+' && message[1] != '-') || !isdigit(message[2]) || !isdigit(message[3]) || - !isdigit(message[4]) || !isdigit(message[5]) || - message[6] != '\t') + !isdigit(message[4]) || !isdigit(message[5])) continue; /* corrupt? */ email_end[1] = '\0'; tz = strtol(message + 1, NULL, 10); - message += 7; + if (message[6] != '\t') + message += 6; + else + message += 7; ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data); if (ret) break; @@ -1246,7 +1268,7 @@ static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data) free(log); closedir(dir); } - else + else if (*base) return errno; return retval; }