git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-branch: let caller specify logmsg
@ 2006-11-30  2:16 Lars Hjemli
  0 siblings, 0 replies; only message in thread
From: Lars Hjemli @ 2006-11-30  2:16 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

This changes the signature of rename_ref() in refs.[hc] to include a
logmessage for the reflogs.

Also, builtin-branch.c is modified to provide a proper logmessage + call
setup_ident() before any logmessages are written.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 builtin-branch.c |    8 ++++++--
 refs.c           |   10 +++-------
 refs.h           |    2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index 3e206b9..abf23c4 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -247,7 +247,7 @@ static void create_branch(const char *name, const char *start,
 
 static void rename_branch(const char *oldname, const char *newname, int force)
 {
-	char oldref[PATH_MAX], newref[PATH_MAX];
+	char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
 	unsigned char sha1[20];
 
 	if (snprintf(oldref, sizeof(oldref), "refs/heads/%s", oldname) > sizeof(oldref))
@@ -265,7 +265,10 @@ static void rename_branch(const char *oldname, const char *newname, int force)
 	if (resolve_ref(newref, sha1, 1, NULL) && !force)
 		die("A branch named '%s' already exists.", newname);
 
-	if (rename_ref(oldref, newref))
+	snprintf(logmsg, sizeof(logmsg), "Branch: renamed %s to %s",
+		 oldref, newref);
+
+	if (rename_ref(oldref, newref, logmsg))
 		die("Branch rename failed");
 
 	if (!strcmp(oldname, head) && create_symref("HEAD", newref))
@@ -281,6 +284,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	int kinds = REF_LOCAL_BRANCH;
 	int i;
 
+	setup_ident();
 	git_config(git_default_config);
 
 	for (i = 1; i < argc; i++) {
diff --git a/refs.c b/refs.c
index d8c19e6..d45f267 100644
--- a/refs.c
+++ b/refs.c
@@ -784,13 +784,12 @@ int delete_ref(const char *refname, unsigned char *sha1)
 	return ret;
 }
 
-int rename_ref(const char *oldref, const char *newref)
+int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 {
 	static const char renamed_ref[] = "RENAMED-REF";
 	unsigned char sha1[20], orig_sha1[20];
 	int flag = 0, logmoved = 0;
 	struct ref_lock *lock;
-	char msg[PATH_MAX*2 + 100];
 	struct stat loginfo;
 	int log = !lstat(git_path("logs/%s", oldref), &loginfo);
 
@@ -806,14 +805,11 @@ int rename_ref(const char *oldref, const char *newref)
 	if (!is_refname_available(newref, oldref, get_loose_refs(), 0))
 		return 1;
 
-	if (snprintf(msg, sizeof(msg), "renamed %s to %s", oldref, newref) > sizeof(msg))
-		return error("Refnames to long");
-
 	lock = lock_ref_sha1_basic(renamed_ref, NULL, NULL);
 	if (!lock)
 		return error("unable to lock %s", renamed_ref);
 	lock->force_write = 1;
-	if (write_ref_sha1(lock, orig_sha1, msg))
+	if (write_ref_sha1(lock, orig_sha1, logmsg))
 		return error("unable to save current sha1 in %s", renamed_ref);
 
 	if (log && rename(git_path("logs/%s", oldref), git_path("tmp-renamed-log")))
@@ -866,7 +862,7 @@ int rename_ref(const char *oldref, const char *newref)
 
 	lock->force_write = 1;
 	hashcpy(lock->old_sha1, orig_sha1);
-	if (write_ref_sha1(lock, orig_sha1, msg)) {
+	if (write_ref_sha1(lock, orig_sha1, logmsg)) {
 		error("unable to write current sha1 into %s", newref);
 		goto rollback;
 	}
diff --git a/refs.h b/refs.h
index ce73d5c..51aab1e 100644
--- a/refs.h
+++ b/refs.h
@@ -48,6 +48,6 @@ extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned
 extern int check_ref_format(const char *target);
 
 /** rename ref, return 0 on success **/
-extern int rename_ref(const char *oldref, const char *newref);
+extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
 
 #endif /* REFS_H */
-- 
1.4.4.1.gf0df

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-30  2:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-30  2:16 [PATCH] git-branch: let caller specify logmsg Lars Hjemli

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).