ref: cec38a6e09ce13a29ad85c217f1039e038a5dbd7
parent: 60d952cc1465ca99cc101be38f340a2f64550bdf
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 18 22:49:46 EST 2020
clean up handling of branch names and push -a
--- a/push
+++ b/push
@@ -24,10 +24,10 @@
shift
upstream=$1
case -a
- sendall=true
+ branch=-b`$nl{cd .git/refs/heads && walk -f}
case -b
shift
- branch=$1
+ branch=(-b$1 $branch)
case -r
shift
remove=(-r$1 $remove);
@@ -47,10 +47,9 @@
remote=$upstream
if(~ $#remote 0)
die 'no idea where to push'
-if(~ $sendall '')
- updates=`$nl{git/send $force -b $branch $remove $remote || die $status}
-if not
- updates=`$nl{git/send $force $remove -a $remote || die $status}
+if(~ $#branch 0)
+ die 'no branches'
+updates=`$nl{git/send $force $branch $remove $remote || die $status}
for(ln in $updates){
u=`{echo $ln}
--- a/send.c
+++ b/send.c
@@ -33,7 +33,8 @@
int sendall;
int force;
-char *curbranch = "refs/heads/master";
+int nbranch;
+char **branch;
char *removed[128];
int nremoved;
@@ -246,28 +247,17 @@
readours(Update **ret)
{
Update *u, *r;
- Hash *h;
- int nd, nu, i;
+ int nu, i;
char *pfx;
- Dir *d;
+ Hash *h;
nu = 0;
- if(!sendall){
- u = emalloc((nremoved + 1)*sizeof(Update));
- snprint(u[nu].ref, sizeof(u[nu].ref), "%s", curbranch);
- if(resolveref(&u[nu].ours, curbranch) == -1)
- sysfatal("broken branch %s", curbranch);
+ u = emalloc((nremoved + nbranch)*sizeof(Update));
+ for(i = 0; i < nbranch; i++){
+ snprint(u[nu].ref, sizeof(u[nu].ref), "%s", branch[i]);
+ if(resolveref(&u[nu].ours, branch[i]) == -1)
+ sysfatal("broken branch %s", branch[i]);
nu++;
- }else{
- if((nd = slurpdir(".git/refs/heads", &d)) == -1)
- sysfatal("read branches: %r");
- u = emalloc((nremoved + nd)*sizeof(Update));
- for(i = 0; i < nd; i++){
- snprint(u[nu].ref, sizeof(u[nu].ref), "refs/heads/%s", d[nu].name);
- if(resolveref(&u[nu].ours, u[nu].ref) == -1)
- continue;
- nu++;
- }
}
for(i = 0; i < nremoved; i++){
pfx = "refs/heads/";
@@ -296,8 +286,7 @@
Update *upd, *u;
Object *a, *b;
- if((nupd = readours(&upd)) == -1)
- sysfatal("read refs: %r");
+ nupd = readours(&upd);
while(1){
n = readpkt(fd, buf, sizeof(buf));
if(n == -1)
@@ -410,13 +399,16 @@
{
char proto[Nproto], host[Nhost], port[Nport];
char repo[Nrepo], path[Npath];
+ char *br;
int fd;
ARGBEGIN{
- default: usage(); break;
- case 'a': sendall++; break;
- case 'd': chattygit++; break;
- case 'f': force++; break;
+ default:
+ usage(); break;
+ case 'd':
+ chattygit++; break;
+ case 'f':
+ force++; break;
case 'r':
if(nremoved == nelem(removed))
sysfatal("too many deleted branches");
@@ -423,7 +415,16 @@
removed[nremoved++] = EARGF(usage());
break;
case 'b':
- curbranch = smprint("refs/%s", EARGF(usage()));
+ br = EARGF(usage());
+ if(strncmp(br, "refs/heads/", strlen("refs/heads/")) == 0)
+ br = smprint("%s", br);
+ else if(strncmp(br, "heads/", strlen("heads/")) == 0)
+ br = smprint("refs/%s", br);
+ else
+ br = smprint("refs/heads/%s", br);
+ branch = erealloc(branch, (nbranch + 1)*sizeof(char*));
+ branch[nbranch] = br;
+ nbranch++;
break;
}ARGEND;