From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/5] remote.c: refactor creation of new dst ref
Date: Sat, 9 Jun 2007 02:21:33 -0700 [thread overview]
Message-ID: <11813808961403-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <11813808962261-git-send-email-gitster@pobox.com>
This refactors open-coded sequence to create a new "struct ref"
and link it to the tail of dst list into a new function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
remote.c | 35 +++++++++++++++++------------------
1 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/remote.c b/remote.c
index b53130f..f469fb3 100644
--- a/remote.c
+++ b/remote.c
@@ -406,6 +406,18 @@ static struct ref *try_explicit_object_name(const char *name)
return ref;
}
+static struct ref *make_dst(const char *name, struct ref ***dst_tail)
+{
+ struct ref *dst;
+ size_t len;
+
+ len = strlen(name) + 1;
+ dst = xcalloc(1, sizeof(*dst) + len);
+ memcpy(dst->name, name, len);
+ link_dst_tail(dst, dst_tail);
+ return dst;
+}
+
static int match_explicit(struct ref *src, struct ref *dst,
struct ref ***dst_tail,
struct refspec *rs,
@@ -447,23 +459,13 @@ static int match_explicit(struct ref *src, struct ref *dst,
case 1:
break;
case 0:
- if (!memcmp(dst_value, "refs/", 5)) {
- int len = strlen(dst_value) + 1;
- matched_dst = xcalloc(1, sizeof(*dst) + len);
- memcpy(matched_dst->name, dst_value, len);
- link_dst_tail(matched_dst, dst_tail);
- }
- else if (!strcmp(rs->src, dst_value) &&
- matched_src) {
+ if (!memcmp(dst_value, "refs/", 5))
+ matched_dst = make_dst(dst_value, dst_tail);
+ else if (!strcmp(rs->src, dst_value) && matched_src)
/* pushing "master:master" when
* remote does not have master yet.
*/
- int len = strlen(matched_src->name) + 1;
- matched_dst = xcalloc(1, sizeof(*dst) + len);
- memcpy(matched_dst->name, matched_src->name,
- len);
- link_dst_tail(matched_dst, dst_tail);
- }
+ matched_dst = make_dst(matched_src->name, dst_tail);
else {
errs = 1;
error("dst refspec %s does not match any "
@@ -567,11 +569,8 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
goto free_name;
if (!dst_peer) {
/* Create a new one and link it */
- int len = strlen(dst_name) + 1;
- dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
- memcpy(dst_peer->name, dst_name, len);
+ dst_peer = make_dst(dst_name, dst_tail);
hashcpy(dst_peer->new_sha1, src->new_sha1);
- link_dst_tail(dst_peer, dst_tail);
}
dst_peer->peer_ref = src;
free_name:
--
1.5.2.1.144.gabc40
next prev parent reply other threads:[~2007-06-09 9:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-09 9:21 [PATCH 1/5] remote.c: refactor match_explicit_refs() Junio C Hamano
2007-06-09 9:21 ` Junio C Hamano [this message]
2007-06-09 9:21 ` [PATCH 3/5] remote.c: minor clean-up of match_explicit() Junio C Hamano
2007-06-09 9:21 ` [PATCH 4/5] remote.c: fix "git push" weak match disambiguation Junio C Hamano
2007-06-09 9:21 ` [PATCH 5/5] remote.c: "git-push frotz" should update what matches at the source Junio C Hamano
2007-06-10 6:59 ` [PATCH 6/5] git-push: Update description of refspecs and add examples Junio C Hamano
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=11813808961403-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/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).