@matheusbsbs / matheus-bagliano / commits / 678d0f4cbf
Fork 0

git-branch: let caller specify logmsg

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Lars Hjemli committed Nov 30, 2006 at 03:16 UTC 678d0f4cbfa7a3b529c6e894f2977bef6a2d3e4c
3 files changed +10 -10
builtin-branch.c
+6 -2
@@ -247,7 +247,7 @@ static void create_branch(const char *name, const char *start,
247
248 static void rename_branch(const char *oldname, const char *newname, int force)
249 {
250 - char oldref[PATH_MAX], newref[PATH_MAX];
250 + char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
251 unsigned char sha1[20];
252
253 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)
265 if (resolve_ref(newref, sha1, 1, NULL) && !force)
266 die("A branch named '%s' already exists.", newname);
267
268 - if (rename_ref(oldref, newref))
268 + snprintf(logmsg, sizeof(logmsg), "Branch: renamed %s to %s",
269 + oldref, newref);
270 +
271 + if (rename_ref(oldref, newref, logmsg))
272 die("Branch rename failed");
273
274 if (!strcmp(oldname, head) && create_symref("HEAD", newref))
@@ -281,6 +284,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
284 int kinds = REF_LOCAL_BRANCH;
285 int i;
286
287 + setup_ident();
288 git_config(git_default_config);
289
290 for (i = 1; i < argc; i++) {
refs.c
+3 -7
@@ -784,13 +784,12 @@ int delete_ref(const char *refname, unsigned char *sha1)
784 return ret;
785 }
786
787 -int rename_ref(const char *oldref, const char *newref)
787 +int rename_ref(const char *oldref, const char *newref, const char *logmsg)
788 {
789 static const char renamed_ref[] = "RENAMED-REF";
790 unsigned char sha1[20], orig_sha1[20];
791 int flag = 0, logmoved = 0;
792 struct ref_lock *lock;
793 - char msg[PATH_MAX*2 + 100];
793 struct stat loginfo;
794 int log = !lstat(git_path("logs/%s", oldref), &loginfo);
795
@@ -806,14 +805,11 @@ int rename_ref(const char *oldref, const char *newref)
805 if (!is_refname_available(newref, oldref, get_loose_refs(), 0))
806 return 1;
807
809 - if (snprintf(msg, sizeof(msg), "renamed %s to %s", oldref, newref) > sizeof(msg))
810 - return error("Refnames to long");
811 -
808 lock = lock_ref_sha1_basic(renamed_ref, NULL, NULL);
809 if (!lock)
810 return error("unable to lock %s", renamed_ref);
811 lock->force_write = 1;
816 - if (write_ref_sha1(lock, orig_sha1, msg))
812 + if (write_ref_sha1(lock, orig_sha1, logmsg))
813 return error("unable to save current sha1 in %s", renamed_ref);
814
815 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)
862
863 lock->force_write = 1;
864 hashcpy(lock->old_sha1, orig_sha1);
869 - if (write_ref_sha1(lock, orig_sha1, msg)) {
865 + if (write_ref_sha1(lock, orig_sha1, logmsg)) {
866 error("unable to write current sha1 into %s", newref);
867 goto rollback;
868 }
refs.h
+1 -1
@@ -48,6 +48,6 @@ extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned
48 extern int check_ref_format(const char *target);
49
50 /** rename ref, return 0 on success **/
51 -extern int rename_ref(const char *oldref, const char *newref);
51 +extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
52
53 #endif /* REFS_H */