git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Lars Hjemli" <hjemli@gmail.com>
To: "Junio C Hamano" <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Teach git-branch howto rename a branch
Date: Tue, 28 Nov 2006 10:55:47 +0100	[thread overview]
Message-ID: <8c5c35580611280155v3b21cbe1m4b580ca9838eac15@mail.gmail.com> (raw)
In-Reply-To: <7vzmac3qig.fsf@assigned-by-dhcp.cox.net>

On 11/28/06, Junio C Hamano <junkio@cox.net> wrote:
> Lars Hjemli <hjemli@gmail.com> writes:
> >
> > With two branchnames, the second name is renamed to the first.
>
> Thanks.
>
> "--rename newname oldname" feels funny, as already mentioned a
> few times on the list.  rename(2) is "rename(old, new)" and
> mv(1) is "mv old new".

Ok, how about

  git branch [-m|-M] [oldbranch] newbranch

where -m is 'move' and -M is 'force move'?


>
> +       if (!rename_ref(oldref, newref) && !strcmp(oldname, head))
> +               create_symref("HEAD", newref);
> +}
>
> Can create_symref() fail?

Yes... But what can been done if/when it fails? create_symref()
already seems to be pretty verbose about errors, so the only thing I
can think of is to return the errorcode to the caller (which I should
have done in the first place, git-branch ought to have a usable
exitcode)

>
> +int rename_ref(const char *oldref, const char *newref)
> +{
> +       unsigned char sha1[20], orig_sha1[20];
> +       int flag = 0, logmoved = 0;
> +       struct ref_lock *lock;
> +       char msg[PATH_MAX*2 + 100];
> +       struct stat stat;
> +       int log = !lstat(git_path("logs/%s", oldref), &stat);
>
> This is not wrong per-se, but it made me stop and wonder if we
> want to error out when we find out "logs/oldref" is a symlink; I
> do not think we care about it that much, but in that case we may
> want to say stat() here instead...  Just a minor detail.

Well, it's a good point. If it's a symlink that's a pretty strong
indication that someone has been messing with the log for some reason,
so to error out is probably the right thing to do.


>
> +       lock = lock_ref_sha1_basic("tmp-renamed-ref", NULL, NULL);
> +       if (!lock)
> +               return error("unable to lock tmp-renamed-ref");
> +       lock->force_write = 1;
> +       if (write_ref_sha1(lock, orig_sha1, msg))
> +               return error("unable to save current sha1 in tmp-renamed-ref");
> +       if (log && rename(git_path("logs/%s", oldref), git_path("tmp-renamed-log")))
> +               return error("unable to move logfile logs/%s to tmp-renamed-log: %s",
> +                       oldref, strerror(errno));
>
> I am confused with this code.  tmp-renamed-ref is not even a
> ref, you lock $GIT_DIR/tmp-renamed-ref and call write-ref_sha1()
> with an uninitialized msg[] buffer to write into a logfile. What
> is the name of that logfile?  $GIT_DIR/log/tmp-renamed-ref???

My goal was to save the ref in a tmp-file before deleting the old ref,
not to log the event. I think of it as a way to get out of trouble if
rename_ref should fail badly.

Btw: I't _might_ be interesting to have $GIT_DIR/logs/tmp-renamed-ref
(or something similar) as a branch-independent log of branch renames


Anyway, I'l fix up the mentioned issues in a new patch

--

      reply	other threads:[~2006-11-28  9:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-28  2:01 [PATCH] Teach git-branch howto rename a branch Lars Hjemli
2006-11-28  8:07 ` Jakub Narebski
2006-11-28  8:49 ` Junio C Hamano
2006-11-28  9:55   ` Lars Hjemli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c5c35580611280155v3b21cbe1m4b580ca9838eac15@mail.gmail.com \
    --to=hjemli@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).