* [PATCH 1/7] make reflog filename independent from struct ref_lock
@ 2007-01-26 22:26 Nicolas Pitre
2007-01-26 22:26 ` [PATCH 2/7] lock_ref_sha1_basic(): remember the original name of a ref when resolving it Nicolas Pitre
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
This allows for ref_log_write() to be used in a more flexible way,
and is needed for future changes.
This is only code reorg with no behavior change.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
builtin-reflog.c | 10 ++++++----
refs.c | 44 ++++++++++++++++++++++----------------------
refs.h | 1 -
3 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/builtin-reflog.c b/builtin-reflog.c
index b443ed9..b6612a9 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -242,7 +242,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
struct cmd_reflog_expire_cb *cmd = cb_data;
struct expire_reflog_cb cb;
struct ref_lock *lock;
- char *newlog_path = NULL;
+ char *log_file, *newlog_path = NULL;
int status = 0;
if (strncmp(ref, "refs/", 5))
@@ -255,7 +255,8 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
lock = lock_ref_sha1(ref + 5, sha1);
if (!lock)
return error("cannot lock ref '%s'", ref);
- if (!file_exists(lock->log_file))
+ log_file = xstrdup(git_path("logs/%s", ref));
+ if (!file_exists(log_file))
goto finish;
if (!cmd->dry_run) {
newlog_path = xstrdup(git_path("logs/%s.lock", ref));
@@ -271,13 +272,14 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
if (fclose(cb.newlog))
status |= error("%s: %s", strerror(errno),
newlog_path);
- if (rename(newlog_path, lock->log_file)) {
+ if (rename(newlog_path, log_file)) {
status |= error("cannot rename %s to %s",
- newlog_path, lock->log_file);
+ newlog_path, log_file);
unlink(newlog_path);
}
}
free(newlog_path);
+ free(log_file);
unlock_ref(lock);
return status;
}
diff --git a/refs.c b/refs.c
index 4323e9a..9395677 100644
--- a/refs.c
+++ b/refs.c
@@ -676,7 +676,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
lock->lk = xcalloc(1, sizeof(struct lock_file));
lock->ref_name = xstrdup(ref);
- lock->log_file = xstrdup(git_path("logs/%s", ref));
ref_file = git_path("%s", ref);
lock->force_write = lstat(ref_file, &st) && errno == ENOENT;
@@ -772,10 +771,10 @@ int delete_ref(const char *refname, unsigned char *sha1)
*/
ret |= repack_without_ref(refname);
- err = unlink(lock->log_file);
+ err = unlink(git_path("logs/%s", lock->ref_name));
if (err && errno != ENOENT)
fprintf(stderr, "warning: unlink(%s) failed: %s",
- lock->log_file, strerror(errno));
+ git_path("logs/%s", lock->ref_name), strerror(errno));
invalidate_cached_refs();
unlock_ref(lock);
return ret;
@@ -916,46 +915,47 @@ void unlock_ref(struct ref_lock *lock)
rollback_lock_file(lock->lk);
}
free(lock->ref_name);
- free(lock->log_file);
free(lock);
}
-static int log_ref_write(struct ref_lock *lock,
- const unsigned char *sha1, const char *msg)
+static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
+ const unsigned char *new_sha1, const char *msg)
{
int logfd, written, oflags = O_APPEND | O_WRONLY;
unsigned maxlen, len;
- char *logrec;
+ char *log_file, *logrec;
const char *committer;
if (log_all_ref_updates < 0)
log_all_ref_updates = !is_bare_repository();
+ log_file = git_path("logs/%s", ref_name);
+
if (log_all_ref_updates &&
- (!strncmp(lock->ref_name, "refs/heads/", 11) ||
- !strncmp(lock->ref_name, "refs/remotes/", 13))) {
- if (safe_create_leading_directories(lock->log_file) < 0)
+ (!strncmp(ref_name, "refs/heads/", 11) ||
+ !strncmp(ref_name, "refs/remotes/", 13))) {
+ if (safe_create_leading_directories(log_file) < 0)
return error("unable to create directory for %s",
- lock->log_file);
+ log_file);
oflags |= O_CREAT;
}
- logfd = open(lock->log_file, oflags, 0666);
+ logfd = open(log_file, oflags, 0666);
if (logfd < 0) {
if (!(oflags & O_CREAT) && errno == ENOENT)
return 0;
if ((oflags & O_CREAT) && errno == EISDIR) {
- if (remove_empty_directories(lock->log_file)) {
+ if (remove_empty_directories(log_file)) {
return error("There are still logs under '%s'",
- lock->log_file);
+ log_file);
}
- logfd = open(lock->log_file, oflags, 0666);
+ logfd = open(log_file, oflags, 0666);
}
if (logfd < 0)
return error("Unable to append to %s: %s",
- lock->log_file, strerror(errno));
+ log_file, strerror(errno));
}
committer = git_committer_info(-1);
@@ -963,8 +963,8 @@ static int log_ref_write(struct ref_lock *lock,
maxlen = strlen(committer) + strlen(msg) + 2*40 + 5;
logrec = xmalloc(maxlen);
len = snprintf(logrec, maxlen, "%s %s %s\t%s\n",
- sha1_to_hex(lock->old_sha1),
- sha1_to_hex(sha1),
+ sha1_to_hex(old_sha1),
+ sha1_to_hex(new_sha1),
committer,
msg);
}
@@ -972,15 +972,15 @@ static int log_ref_write(struct ref_lock *lock,
maxlen = strlen(committer) + 2*40 + 4;
logrec = xmalloc(maxlen);
len = snprintf(logrec, maxlen, "%s %s %s\n",
- sha1_to_hex(lock->old_sha1),
- sha1_to_hex(sha1),
+ sha1_to_hex(old_sha1),
+ sha1_to_hex(new_sha1),
committer);
}
written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1;
free(logrec);
close(logfd);
if (written != len)
- return error("Unable to append to %s", lock->log_file);
+ return error("Unable to append to %s", log_file);
return 0;
}
@@ -1003,7 +1003,7 @@ int write_ref_sha1(struct ref_lock *lock,
return -1;
}
invalidate_cached_refs();
- if (log_ref_write(lock, sha1, logmsg) < 0) {
+ if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0) {
unlock_ref(lock);
return -1;
}
diff --git a/refs.h b/refs.h
index 33450f1..2d2ba14 100644
--- a/refs.h
+++ b/refs.h
@@ -3,7 +3,6 @@
struct ref_lock {
char *ref_name;
- char *log_file;
struct lock_file *lk;
unsigned char old_sha1[20];
int lock_fd;
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/7] lock_ref_sha1_basic(): remember the original name of a ref when resolving it
2007-01-26 22:26 [PATCH 1/7] make reflog filename independent from struct ref_lock Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
2007-01-26 22:26 ` [PATCH 3/7] enable separate reflog for HEAD Nicolas Pitre
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
A ref might be pointing to another ref but only the name of the last ref
is remembered. Let's remember about the first name as well.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
refs.c | 2 ++
refs.h | 1 +
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/refs.c b/refs.c
index 9395677..9641fad 100644
--- a/refs.c
+++ b/refs.c
@@ -676,6 +676,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
lock->lk = xcalloc(1, sizeof(struct lock_file));
lock->ref_name = xstrdup(ref);
+ lock->orig_ref_name = xstrdup(orig_ref);
ref_file = git_path("%s", ref);
lock->force_write = lstat(ref_file, &st) && errno == ENOENT;
@@ -915,6 +916,7 @@ void unlock_ref(struct ref_lock *lock)
rollback_lock_file(lock->lk);
}
free(lock->ref_name);
+ free(lock->orig_ref_name);
free(lock);
}
diff --git a/refs.h b/refs.h
index 2d2ba14..94a58b4 100644
--- a/refs.h
+++ b/refs.h
@@ -3,6 +3,7 @@
struct ref_lock {
char *ref_name;
+ char *orig_ref_name;
struct lock_file *lk;
unsigned char old_sha1[20];
int lock_fd;
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/7] enable separate reflog for HEAD
2007-01-26 22:26 ` [PATCH 2/7] lock_ref_sha1_basic(): remember the original name of a ref when resolving it Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
2007-01-26 22:26 ` [PATCH 4/7] add reflog entries for HEAD when detached Nicolas Pitre
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
If HEAD is tied to a branch then both logs/HEAD and logs/heads/<branch> are
updated. This is also true for any symbolic refs in general, but only HEAD
will see its reflog created automatically.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
refs.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index 9641fad..92fa2e4 100644
--- a/refs.c
+++ b/refs.c
@@ -935,7 +935,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
if (log_all_ref_updates &&
(!strncmp(ref_name, "refs/heads/", 11) ||
- !strncmp(ref_name, "refs/remotes/", 13))) {
+ !strncmp(ref_name, "refs/remotes/", 13) ||
+ !strcmp(ref_name, "HEAD"))) {
if (safe_create_leading_directories(log_file) < 0)
return error("unable to create directory for %s",
log_file);
@@ -1005,7 +1006,9 @@ int write_ref_sha1(struct ref_lock *lock,
return -1;
}
invalidate_cached_refs();
- if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0) {
+ if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
+ (strcmp(lock->ref_name, lock->orig_ref_name) &&
+ log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) {
unlock_ref(lock);
return -1;
}
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/7] add reflog entries for HEAD when detached
2007-01-26 22:26 ` [PATCH 3/7] enable separate reflog for HEAD Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
2007-01-26 22:26 ` [PATCH 5/7] move create_symref() past log_ref_write() Nicolas Pitre
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
git-checkout.sh | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index c52f352..ed344d8 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -259,8 +259,9 @@ if [ "$?" -eq 0 ]; then
# git update-ref --detach HEAD $new
# or something like that...
#
- echo "$detached" >"$GIT_DIR/HEAD.new" &&
- mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" ||
+ git-rev-parse HEAD >"$GIT_DIR/HEAD.new" &&
+ mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" &&
+ git-update-ref -m "checkout: moving to $arg" HEAD "$detached" ||
die "Cannot detach HEAD"
if test -n "$detach_warn"
then
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/7] move create_symref() past log_ref_write()
2007-01-26 22:26 ` [PATCH 4/7] add reflog entries for HEAD when detached Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
2007-01-26 22:26 ` [PATCH 6/7] add logref support to git-symbolic-ref Nicolas Pitre
2007-01-27 1:49 ` [PATCH 2/3] create_symref(): do not assume pathname from git_path() persists long enough Junio C Hamano
0 siblings, 2 replies; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
This doesn't change the code at all. It is done to makes the next patch
more obvious.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
refs.c | 86 ++++++++++++++++++++++++++++++++--------------------------------
1 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/refs.c b/refs.c
index 92fa2e4..f91e853 100644
--- a/refs.c
+++ b/refs.c
@@ -309,49 +309,6 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
return ref;
}
-int create_symref(const char *ref_target, const char *refs_heads_master)
-{
- const char *lockpath;
- char ref[1000];
- int fd, len, written;
- const char *git_HEAD = git_path("%s", ref_target);
-
-#ifndef NO_SYMLINK_HEAD
- if (prefer_symlink_refs) {
- unlink(git_HEAD);
- if (!symlink(refs_heads_master, git_HEAD))
- return 0;
- fprintf(stderr, "no symlink - falling back to symbolic ref\n");
- }
-#endif
-
- len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
- if (sizeof(ref) <= len) {
- error("refname too long: %s", refs_heads_master);
- return -1;
- }
- lockpath = mkpath("%s.lock", git_HEAD);
- fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
- written = write_in_full(fd, ref, len);
- close(fd);
- if (written != len) {
- unlink(lockpath);
- error("Unable to write to %s", lockpath);
- return -2;
- }
- if (rename(lockpath, git_HEAD) < 0) {
- unlink(lockpath);
- error("Unable to create %s", git_HEAD);
- return -3;
- }
- if (adjust_shared_perm(git_HEAD)) {
- unlink(lockpath);
- error("Unable to fix permissions on %s", lockpath);
- return -4;
- }
- return 0;
-}
-
int read_ref(const char *ref, unsigned char *sha1)
{
if (resolve_ref(ref, sha1, 1, NULL))
@@ -1022,6 +979,49 @@ int write_ref_sha1(struct ref_lock *lock,
return 0;
}
+int create_symref(const char *ref_target, const char *refs_heads_master)
+{
+ const char *lockpath;
+ char ref[1000];
+ int fd, len, written;
+ const char *git_HEAD = git_path("%s", ref_target);
+
+#ifndef NO_SYMLINK_HEAD
+ if (prefer_symlink_refs) {
+ unlink(git_HEAD);
+ if (!symlink(refs_heads_master, git_HEAD))
+ return 0;
+ fprintf(stderr, "no symlink - falling back to symbolic ref\n");
+ }
+#endif
+
+ len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
+ if (sizeof(ref) <= len) {
+ error("refname too long: %s", refs_heads_master);
+ return -1;
+ }
+ lockpath = mkpath("%s.lock", git_HEAD);
+ fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
+ written = write_in_full(fd, ref, len);
+ close(fd);
+ if (written != len) {
+ unlink(lockpath);
+ error("Unable to write to %s", lockpath);
+ return -2;
+ }
+ if (rename(lockpath, git_HEAD) < 0) {
+ unlink(lockpath);
+ error("Unable to create %s", git_HEAD);
+ return -3;
+ }
+ if (adjust_shared_perm(git_HEAD)) {
+ unlink(lockpath);
+ error("Unable to fix permissions on %s", lockpath);
+ return -4;
+ }
+ return 0;
+}
+
static char *ref_msg(const char *line, const char *endp)
{
const char *ep;
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/7] add logref support to git-symbolic-ref
2007-01-26 22:26 ` [PATCH 5/7] move create_symref() past log_ref_write() Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
2007-01-26 22:26 ` [PATCH 7/7] add reflog when moving HEAD to a new branch Nicolas Pitre
2007-01-27 1:49 ` [PATCH 2/3] create_symref(): do not assume pathname from git_path() persists long enough Junio C Hamano
1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
Documentation/git-symbolic-ref.txt | 6 +++++-
builtin-branch.c | 3 ++-
builtin-init-db.c | 2 +-
builtin-symbolic-ref.c | 16 ++++++++++++++--
cache.h | 2 +-
refs.c | 14 ++++++++++++--
6 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt
index f93b79a..a88f722 100644
--- a/Documentation/git-symbolic-ref.txt
+++ b/Documentation/git-symbolic-ref.txt
@@ -7,7 +7,7 @@ git-symbolic-ref - Read and modify symbolic refs
SYNOPSIS
--------
-'git-symbolic-ref' [-q] <name> [<ref>]
+'git-symbolic-ref' [-q] [-m <reason>] <name> [<ref>]
DESCRIPTION
-----------
@@ -31,6 +31,10 @@ OPTIONS
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 25ffa54..52a9250 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -381,7 +381,8 @@ static void rename_branch(const char *oldname, const char *newname, int force)
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 1865489..12e43d0 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -231,7 +231,7 @@ static int create_default_files(const char *git_dir, const char *template_path)
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 227c9d4..d41b406 100644
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
@@ -3,7 +3,7 @@
#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)
{
@@ -25,6 +25,7 @@ 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);
@@ -34,6 +35,17 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
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++;
@@ -50,7 +62,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
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);
diff --git a/cache.h b/cache.h
index 9486132..6472608 100644
--- a/cache.h
+++ b/cache.h
@@ -302,7 +302,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
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);
diff --git a/refs.c b/refs.c
index f91e853..f632d49 100644
--- a/refs.c
+++ b/refs.c
@@ -979,18 +979,23 @@ int write_ref_sha1(struct ref_lock *lock,
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
@@ -1019,6 +1024,11 @@ int create_symref(const char *ref_target, const char *refs_heads_master)
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;
}
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 7/7] add reflog when moving HEAD to a new branch
2007-01-26 22:26 ` [PATCH 6/7] add logref support to git-symbolic-ref Nicolas Pitre
@ 2007-01-26 22:26 ` Nicolas Pitre
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Pitre @ 2007-01-26 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nicolas Pitre
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
git-checkout.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index ed344d8..5dc281f 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -250,7 +250,7 @@ if [ "$?" -eq 0 ]; then
fi
if test -n "$branch"
then
- GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD "refs/heads/$branch"
+ GIT_DIR="$GIT_DIR" git-symbolic-ref -m "checkout: moving to $branch" HEAD "refs/heads/$branch"
elif test -n "$detached"
then
# NEEDSWORK: we would want a command to detach the HEAD
--
1.5.0.rc2.g6e2c
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] create_symref(): do not assume pathname from git_path() persists long enough
2007-01-26 22:26 ` [PATCH 5/7] move create_symref() past log_ref_write() Nicolas Pitre
2007-01-26 22:26 ` [PATCH 6/7] add logref support to git-symbolic-ref Nicolas Pitre
@ 2007-01-27 1:49 ` Junio C Hamano
1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2007-01-27 1:49 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: git
Being lazy to rely on the cycling N buffers mkpath() and friends
return is nice in general, but it makes it too easy to introduce
new bugs that are "mysterious".
Introduction of read_ref() in create_symref() after calling
git_path() to get the git_HEAD value (i.e. the path to create a
new symref at) consumed more than the available buffers and
broke a later call to mkpath() that derives lockpath from it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
* t7201-co.sh caught three failures. The problem this patch is
fixing overwrote and gave ".lock" in lockpath, then open() on
that path failed and gave fd = -1 (because I scratched my
head and re-run the test without cleaning, and O_EXCL
triggered), which threw write_in_full() into infinite loop,
which will be fixed with the next patch.
refs.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/refs.c b/refs.c
index 5913185..4a52308 100644
--- a/refs.c
+++ b/refs.c
@@ -992,7 +992,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
const char *lockpath;
char ref[1000];
int fd, len, written;
- const char *git_HEAD = git_path("%s", ref_target);
+ char *git_HEAD = xstrdup(git_path("%s", ref_target));
unsigned char old_sha1[20], new_sha1[20];
if (logmsg && read_ref(ref_target, old_sha1))
@@ -1010,36 +1010,38 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
if (sizeof(ref) <= len) {
error("refname too long: %s", refs_heads_master);
- return -1;
+ goto error_free_return;
}
lockpath = mkpath("%s.lock", git_HEAD);
fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd < 0) {
error("Unable to open %s for writing", lockpath);
- return -5;
+ goto error_free_return;
}
written = write_in_full(fd, ref, len);
close(fd);
if (written != len) {
- unlink(lockpath);
error("Unable to write to %s", lockpath);
- return -2;
+ goto error_unlink_return;
}
if (rename(lockpath, git_HEAD) < 0) {
- unlink(lockpath);
error("Unable to create %s", git_HEAD);
- return -3;
+ goto error_unlink_return;
}
if (adjust_shared_perm(git_HEAD)) {
- unlink(lockpath);
error("Unable to fix permissions on %s", lockpath);
- return -4;
+ error_unlink_return:
+ unlink(lockpath);
+ error_free_return:
+ free(git_HEAD);
+ return -1;
}
done:
if (logmsg && !read_ref(refs_heads_master, new_sha1))
log_ref_write(ref_target, old_sha1, new_sha1, logmsg);
+ free(git_HEAD);
return 0;
}
--
1.5.0.rc2.g8ac6-dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-01-27 1:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-26 22:26 [PATCH 1/7] make reflog filename independent from struct ref_lock Nicolas Pitre
2007-01-26 22:26 ` [PATCH 2/7] lock_ref_sha1_basic(): remember the original name of a ref when resolving it Nicolas Pitre
2007-01-26 22:26 ` [PATCH 3/7] enable separate reflog for HEAD Nicolas Pitre
2007-01-26 22:26 ` [PATCH 4/7] add reflog entries for HEAD when detached Nicolas Pitre
2007-01-26 22:26 ` [PATCH 5/7] move create_symref() past log_ref_write() Nicolas Pitre
2007-01-26 22:26 ` [PATCH 6/7] add logref support to git-symbolic-ref Nicolas Pitre
2007-01-26 22:26 ` [PATCH 7/7] add reflog when moving HEAD to a new branch Nicolas Pitre
2007-01-27 1:49 ` [PATCH 2/3] create_symref(): do not assume pathname from git_path() persists long enough Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).