[PATCH v2 9/9] sha1_name: add support for @{publish} marks

2014-04-10 Thread Felipe Contreras
Signed-off-by: Felipe Contreras felipe.contre...@gmail.com
---
 Documentation/revisions.txt |  4 
 sha1_name.c | 49 -
 t/t1508-at-combinations.sh  |  5 +
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index 5a286d0..fd01cb4 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -96,6 +96,10 @@ some output processing may assume ref names in UTF-8.
   refers to the branch that the branch specified by branchname is set to build 
on
   top of.  A missing branchname defaults to the current one.
 
+'branchname@\{publish\}', e.g. 'master@\{publish\}', '@\{p\}'::
+  The suffix '@\{publish\}' to a branchname refers to the remote branch to
+  push to. A missing branchname defaults to the current one.
+
 'rev{caret}', e.g. 'HEAD{caret}, v1.5.1{caret}0'::
   A suffix '{caret}' to a revision parameter means the first parent of
   that commit object.  '{caret}n' means the nth parent (i.e.
diff --git a/sha1_name.c b/sha1_name.c
index aa3f3e0..a36852d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -415,9 +415,9 @@ static int ambiguous_path(const char *path, int len)
return slash;
 }
 
-static inline int upstream_mark(const char *string, int len)
+static inline int tracking_mark(const char *string, int len)
 {
-   const char *suffix[] = { upstream, u };
+   const char *suffix[] = { upstream, u, publish, p };
int i;
 
for (i = 0; i  ARRAY_SIZE(suffix); i++) {
@@ -475,7 +475,7 @@ static int get_sha1_basic(const char *str, int len, 
unsigned char *sha1)
nth_prior = 1;
continue;
}
-   if (!upstream_mark(str + at + 2, len - at - 3)) 
{
+   if (!tracking_mark(str + at + 2, len - at - 3)) 
{
reflog_len = (len-1) - (at+2);
len = at;
}
@@ -1057,10 +1057,11 @@ static void set_shortened_ref(struct strbuf *buf, const 
char *ref)
free(s);
 }
 
-static const char *get_upstream_branch(const char *name_buf, int len)
+static const char *get_tracking_branch(const char *name_buf, int len, char 
type)
 {
char *name = xstrndup(name_buf, len);
struct branch *branch = branch_get(*name ? name : NULL);
+   char *tracking = NULL;
 
/*
 * Upstream can be NULL only if branch refers to HEAD and HEAD
@@ -1068,23 +1069,35 @@ static const char *get_upstream_branch(const char 
*name_buf, int len)
 */
if (!branch)
die(_(HEAD does not point to a branch));
-   if (!branch-merge || !branch-merge[0]-dst) {
-   if (!ref_exists(branch-refname))
-   die(_(No such branch: '%s'), name);
-   if (!branch-merge) {
-   die(_(No upstream configured for branch '%s'),
-   branch-name);
+   switch (type) {
+   case 'u':
+   if (!branch-merge || !branch-merge[0]-dst) {
+   if (!ref_exists(branch-refname))
+   die(_(No such branch: '%s'), name);
+   if (!branch-merge) {
+   die(_(No upstream configured for branch '%s'),
+   branch-name);
+   }
+   die(
+   _(Upstream branch '%s' not stored as a 
remote-tracking branch),
+   branch-merge[0]-src);
+   }
+   tracking = branch-merge[0]-dst;
+   break;
+   case 'p':
+   if (!branch-push.dst) {
+   die(_(No publish configured for branch '%s'),
+   branch-name);
}
-   die(
-   _(Upstream branch '%s' not stored as a remote-tracking 
branch),
-   branch-merge[0]-src);
+   tracking = branch-push.dst;
+   break;
}
free(name);
 
-   return branch-merge[0]-dst;
+   return tracking;
 }
 
-static int interpret_upstream_mark(const char *name, int namelen,
+static int interpret_tracking_mark(const char *name, int namelen,
   int at, struct strbuf *buf)
 {
int len;
@@ -1092,14 +1105,14 @@ static int interpret_upstream_mark(const char *name, 
int namelen,
if (name[at + 1] != '{' || name[namelen - 1] != '}')
return -1;
 
-   len = upstream_mark(name + at + 2, namelen - at - 3);
+   len = tracking_mark(name + at + 2, namelen - at - 3);
if (!len)
return -1;
 
if (memchr(name, ':', at))
return -1;
 
-   

Re: [PATCH v2 9/9] sha1_name: add support for @{publish} marks

2014-04-10 Thread Ramkumar Ramachandra
Felipe Contreras wrote:
 @@ -1068,23 +1069,35 @@ static const char *get_upstream_branch(const char 
 *name_buf, int len)
  */
 if (!branch)
 die(_(HEAD does not point to a branch));
 -   if (!branch-merge || !branch-merge[0]-dst) {
 -   if (!ref_exists(branch-refname))
 -   die(_(No such branch: '%s'), name);
 -   if (!branch-merge) {
 -   die(_(No upstream configured for branch '%s'),
 -   branch-name);
 +   switch (type) {
 +   case 'u':
 +   if (!branch-merge || !branch-merge[0]-dst) {
 +   if (!ref_exists(branch-refname))
 +   die(_(No such branch: '%s'), name);
 +   if (!branch-merge) {
 +   die(_(No upstream configured for branch 
 '%s'),
 +   branch-name);
 +   }
 +   die(
 +   _(Upstream branch '%s' not stored as a 
 remote-tracking branch),
 +   branch-merge[0]-src);
 +   }
 +   tracking = branch-merge[0]-dst;
 +   break;
 +   case 'p':
 +   if (!branch-push.dst) {
 +   die(_(No publish configured for branch '%s'),
 +   branch-name);

This assumes a push.default value of 'current' or 'matching'. What
happens if push.default is set to 'nothing' or 'upstream', for
instance?

p.s- Good to see you back on the list :)
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 9/9] sha1_name: add support for @{publish} marks

2014-04-10 Thread Ramkumar Ramachandra
Felipe Contreras wrote:
 diff --git a/sha1_name.c b/sha1_name.c
 index aa3f3e0..a36852d 100644
 --- a/sha1_name.c
 +++ b/sha1_name.c
 @@ -415,9 +415,9 @@ static int ambiguous_path(const char *path, int len)
 return slash;
  }

 -static inline int upstream_mark(const char *string, int len)
 +static inline int tracking_mark(const char *string, int len)
  {
 -   const char *suffix[] = { upstream, u };
 +   const char *suffix[] = { upstream, u, publish, p };

Oh, another thing: on some threads, people decided that @{push}
would be a more apt name (+ alias @{u} to @{pull} for symmetry).
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 9/9] sha1_name: add support for @{publish} marks

2014-04-10 Thread Felipe Contreras
Ramkumar Ramachandra wrote:
 Felipe Contreras wrote:
  @@ -1068,23 +1069,35 @@ static const char *get_upstream_branch(const char 
  *name_buf, int len)
   */
  if (!branch)
  die(_(HEAD does not point to a branch));
  -   if (!branch-merge || !branch-merge[0]-dst) {
  -   if (!ref_exists(branch-refname))
  -   die(_(No such branch: '%s'), name);
  -   if (!branch-merge) {
  -   die(_(No upstream configured for branch '%s'),
  -   branch-name);
  +   switch (type) {
  +   case 'u':
  +   if (!branch-merge || !branch-merge[0]-dst) {
  +   if (!ref_exists(branch-refname))
  +   die(_(No such branch: '%s'), name);
  +   if (!branch-merge) {
  +   die(_(No upstream configured for branch 
  '%s'),
  +   branch-name);
  +   }
  +   die(
  +   _(Upstream branch '%s' not stored as a 
  remote-tracking branch),
  +   branch-merge[0]-src);
  +   }
  +   tracking = branch-merge[0]-dst;
  +   break;
  +   case 'p':
  +   if (!branch-push.dst) {
  +   die(_(No publish configured for branch '%s'),
  +   branch-name);
 
 This assumes a push.default value of 'current' or 'matching'. What
 happens if push.default is set to 'nothing' or 'upstream', for
 instance?

Why would that matter? @{upstream} doesn't depend on this, neither does
@{publish}; @{upstream} is .remote+.merge, @{publish} is .pushremote+.push.

If the user hasn't configured a publish branch, @{publish} fails.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 9/9] sha1_name: add support for @{publish} marks

2014-04-10 Thread Felipe Contreras
Ramkumar Ramachandra wrote:
 Felipe Contreras wrote:
  diff --git a/sha1_name.c b/sha1_name.c
  index aa3f3e0..a36852d 100644
  --- a/sha1_name.c
  +++ b/sha1_name.c
  @@ -415,9 +415,9 @@ static int ambiguous_path(const char *path, int len)
  return slash;
   }
 
  -static inline int upstream_mark(const char *string, int len)
  +static inline int tracking_mark(const char *string, int len)
   {
  -   const char *suffix[] = { upstream, u };
  +   const char *suffix[] = { upstream, u, publish, p };
 
 Oh, another thing: on some threads, people decided that @{push}
 would be a more apt name (+ alias @{u} to @{pull} for symmetry).

@{push} is the name I originally suggested, but it's weird to talk about
the push branch, so I decided on the publish branch, which is more natural.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html