summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 41b625b)
raw | patch | inline | side by side (parent: 41b625b)
author | Nicolas Pitre <nico@cam.org> | |
Fri, 26 Jan 2007 22:26:10 +0000 (17:26 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 28 Jan 2007 10:16:46 +0000 (02:16 -0800) |
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
index f93b79a85e1259f789551a94ab422a846cf4cf65..a88f7228605ee35002573123f3dbe63c3e405dc6 100644 (file)
SYNOPSIS
--------
-'git-symbolic-ref' [-q] <name> [<ref>]
+'git-symbolic-ref' [-q] [-m <reason>] <name> [<ref>]
DESCRIPTION
-----------
symbolic ref but a detached HEAD; instead exit with
non-zero status silently.
+-m::
+ Update the reflog for <name> with <reason>. This is valid only
+ when creating or updating a symbolic ref.
+
NOTES
-----
In the past, `.git/HEAD` was a symbolic link pointing at
diff --git a/builtin-branch.c b/builtin-branch.c
index d60690bb084ef83ce99a56453ae9dfa56da12807..76f174fd89b6841ba395d25cb089d2c615f5dd37 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
if (rename_ref(oldref, newref, logmsg))
die("Branch rename failed");
- if (!strcmp(oldname, head) && create_symref("HEAD", newref))
+ /* no need to pass logmsg here as HEAD didn't really move */
+ if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
die("Branch renamed to %s, but HEAD is not updated!", newname);
}
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 186548938193ac125d9d9f89080cec640d0a46e0..12e43d0db4df0c40fe6375b38691684efcddad18 100644 (file)
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
strcpy(path + len, "HEAD");
reinit = !read_ref("HEAD", sha1);
if (!reinit) {
- if (create_symref("HEAD", "refs/heads/master") < 0)
+ if (create_symref("HEAD", "refs/heads/master", NULL) < 0)
exit(1);
}
diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index 227c9d4a6274871b52420221d9d088bb3ac5554f..d41b40640b96e7d5568174c7d16088c29d361d42 100644 (file)
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
#include "refs.h"
static const char git_symbolic_ref_usage[] =
-"git-symbolic-ref [-q] name [ref]";
+"git-symbolic-ref [-q] [-m <reason>] name [ref]";
static void check_symref(const char *HEAD, int quiet)
{
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
{
int quiet = 0;
+ const char *msg = NULL;
git_config(git_default_config);
break;
else if (!strcmp("-q", arg))
quiet = 1;
+ else if (!strcmp("-m", arg)) {
+ argc--;
+ argv++;
+ if (argc <= 1)
+ break;
+ msg = argv[1];
+ if (!*msg)
+ die("Refusing to perform update with empty message");
+ if (strchr(msg, '\n'))
+ die("Refusing to perform update with \\n in message");
+ }
else if (!strcmp("--", arg)) {
argc--;
argv++;
check_symref(argv[1], quiet);
break;
case 3:
- create_symref(argv[1], argv[2]);
+ create_symref(argv[1], argv[2], msg);
break;
default:
usage(git_symbolic_ref_usage);
index 9873ee97d93f7e4b6809262469f228c53339d080..201704bacf5e7c03ccab9b81b01f94cf50fe943e 100644 (file)
--- a/cache.h
+++ b/cache.h
extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
-extern int create_symref(const char *ref, const char *refs_heads_master);
+extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg);
extern int validate_headref(const char *ref);
extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
index ec6fe29ebb671924e4b0bb27a5d2c6d2288561c0..591318501f6ba072c4888ed7cf9e5b34d26fb32f 100644 (file)
--- a/refs.c
+++ b/refs.c
return 0;
}
-int create_symref(const char *ref_target, const char *refs_heads_master)
+int create_symref(const char *ref_target, const char *refs_heads_master,
+ const char *logmsg)
{
const char *lockpath;
char ref[1000];
int fd, len, written;
const char *git_HEAD = git_path("%s", ref_target);
+ unsigned char old_sha1[20], new_sha1[20];
+
+ if (logmsg && read_ref(ref_target, old_sha1))
+ hashclr(old_sha1);
#ifndef NO_SYMLINK_HEAD
if (prefer_symlink_refs) {
unlink(git_HEAD);
if (!symlink(refs_heads_master, git_HEAD))
- return 0;
+ goto done;
fprintf(stderr, "no symlink - falling back to symbolic ref\n");
}
#endif
error("Unable to fix permissions on %s", lockpath);
return -4;
}
+
+ done:
+ if (logmsg && !read_ref(refs_heads_master, new_sha1))
+ log_ref_write(ref_target, old_sha1, new_sha1, logmsg);
+
return 0;
}