Blame 0004-Optionally-ignore-remote-mercurial-revision-names.patch

e22089e
commit e2627129b1f6ebc6ad4bdd695f708195d85bcb6a
e22089e
Author: TomasKorbar <tomas.korb@seznam.cz>
e22089e
Date:   Sat Apr 28 19:23:07 2018 +0200
e22089e
e22089e
    ignore some mercurial remote revision names
e22089e
e22089e
diff --git a/git-remote-hg b/git-remote-hg
e22089e
index 8e1c321..e9dac14 100755
e22089e
--- a/git-remote-hg
e22089e
+++ b/git-remote-hg
e22089e
@@ -95,8 +95,8 @@ def check_version(*check):
e22089e
         return True
e22089e
     return hg_version >= check
e22089e
 
e22089e
-def get_config(config):
e22089e
-    cmd = ['git', 'config', '--get', config]
e22089e
+def get_config(config, getall=False):
e22089e
+    cmd = ['git', 'config', '--get' if not getall else '--get-all', config]
e22089e
     process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
e22089e
     output, _ = process.communicate()
e22089e
     return output
e22089e
@@ -696,20 +696,41 @@ def do_list(parser):
e22089e
 
e22089e
     list_head(repo, cur)
e22089e
 
e22089e
+    ignore_ref = get_config('remote-hg.ignore-name', True)
e22089e
+    ignore_re = []
e22089e
+    for exp in ignore_ref.splitlines():
e22089e
+        if exp:
e22089e
+            try:
e22089e
+                #warn("checking %s" % (
e22089e
+                ignore_re.append(re.compile(exp.strip()))
e22089e
+            except:
e22089e
+                warn("Invalid regular expression '%s'" % (exp))
e22089e
+    def ignore(kind, name):
e22089e
+        for r in ignore_re:
e22089e
+            if r.search(name):
e22089e
+                warn("Ignoring matched %s %s" % (kind, name))
e22089e
+                return True
e22089e
+        return False
e22089e
+
e22089e
+    for_push = (parser.line.find('for-push') >= 0)
e22089e
+    sha1 = 'f' * 40 if (capability_push and for_push) else '?'
e22089e
+
e22089e
     if track_branches:
e22089e
         for branch in branches:
e22089e
-            print "? refs/heads/branches/%s" % gitref(branch)
e22089e
+            if not ignore('branch', branch):
e22089e
+                print "%s refs/heads/branches/%s" % (sha1, gitref(branch))
e22089e
 
e22089e
     for bmark in bmarks:
e22089e
         if bmarks[bmark].hex() == '0' * 40:
e22089e
             warn("Ignoring invalid bookmark '%s'", bmark)
e22089e
-        else:
e22089e
-            print "? refs/heads/%s" % gitref(bmark)
e22089e
+        elif not ignore('bookmark', bmark):
e22089e
+            print "%s refs/heads/%s" % (sha1, gitref(bmark))
e22089e
 
e22089e
     for tag, node in repo.tagslist():
e22089e
         if tag == 'tip':
e22089e
             continue
e22089e
-        print "? refs/tags/%s" % gitref(tag)
e22089e
+        if not ignore('tag', tag):
e22089e
+            print "%s refs/tags/%s" % (sha1, gitref(tag))
e22089e
 
e22089e
     print
e22089e
 
e22089e
@@ -1270,6 +1291,7 @@ def main(args):
e22089e
     global fake_bmark, hg_version
e22089e
     global dry_run
e22089e
     global notes, alias
e22089e
+    global capability_push
e22089e
 
e22089e
     marks = None
e22089e
     is_tmp = False
e22089e
@@ -1287,6 +1309,8 @@ def main(args):
e22089e
 
e22089e
     hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
e22089e
     track_branches = get_config_bool('remote-hg.track-branches', True)
e22089e
+    capability_push = get_config_bool('remote-hg.capability-push', True)
e22089e
+
e22089e
     force_push = False
e22089e
 
e22089e
     if hg_git_compat: