chiark / gitweb /
Dgit.pm: Break out git_get_symref
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Aug 2017 19:57:41 +0000 (20:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 11:25:49 +0000 (12:25 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm
debian/changelog
dgit

index abcf123..ebf9d7d 100644 (file)
@@ -49,7 +49,7 @@ BEGIN {
                      failedcmd_report_cmd failedcmd
                       runcmd cmdoutput cmdoutput_errok
                       git_rev_parse git_cat_file
-                     git_get_ref git_for_each_ref
+                     git_get_ref git_get_symref git_for_each_ref
                       git_for_each_tag_referring is_fast_fwd
                       $package_re $component_re $deliberately_re
                      $distro_re $versiontag_re $series_filename_re
@@ -381,6 +381,19 @@ sub git_cat_file ($;$) {
     return $chk->($type, $data);
 }
 
+sub git_get_symref (;$) {
+    my ($symref) = @_;  $symref //= 'HEAD';
+    # => undef if not a symref, otherwise refs/...
+    my @cmd = (qw(git symbolic-ref -q HEAD));
+    my $branch = cmdoutput_errok @cmd;
+    if (!defined $branch) {
+       $?==256 or failedcmd @cmd;
+    } else {
+       chomp $branch;
+    }
+    return $branch;
+}
+
 sub git_for_each_ref ($$;$) {
     my ($pattern,$func,$gitdir) = @_;
     # calls $func->($objid,$objtype,$fullrefname,$reftail);
index 464a433..62d8eed 100644 (file)
@@ -2,6 +2,7 @@ dgit (4.5~) unstable; urgency=medium
 
   Internal changes:
   * Move $playground global to dgit.
+  * Break git_get_symref out into Dgit.pm.
 
  --
 
diff --git a/dgit b/dgit
index 9ce7972..aaafefb 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -4511,13 +4511,8 @@ sub cmd_clone {
 }
 
 sub branchsuite () {
-    my @cmd = (@git, qw(symbolic-ref -q HEAD));
-    my $branch = cmdoutput_errok @cmd;
-    if (!defined $branch) {
-       $?==256 or failedcmd @cmd;
-       return undef;
-    }
-    if ($branch =~ m#$lbranch_re#o) {
+    my $branch = git_get_symref();
+    if (defined $branch && $branch =~ m#$lbranch_re#o) {
        return $1;
     } else {
        return undef;