{"thread":{"id":"3437","subject":"gitview: Use git ls-remote to find the tag and branch details","startedAt":"2006-02-22T16:07:18Z","lastAt":"2006-02-22T16:07:18Z","messageCount":1,"participants":["Aneesh Kumar K.V"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"16572","messageId":"43FC8C36.5060309@gmail.com","threadId":"3437","inReplyTo":null,"subject":"gitview: Use git ls-remote to find the tag and branch details","fromName":"Aneesh Kumar K.V","fromEmail":"aneesh.kumar@gmail.com","sentAt":"2006-02-22T16:07:18Z","receivedAt":"2006-02-22T16:07:18Z","isPatch":false,"sender":{"key":"aneesh.kumar@gmail.com","avatar":"https://gravatar.com/avatar/0621fc0b2f14ead1e9024382f16053a808c148596da30c1b92572fa075621f68?d=mp&s=160"},"body":"\n\n\nFrom: Junio C Hamano <junkio@cox.net>\nThis fix the below bug\n\nJunio C Hamano <junkio@cox.net> writes:\n\n>\n> It does not work in my repository, since you do not seem to\n> handle branch and tag names with slashes in them.  All of my\n> topic branches live in directories with two-letter names\n> (e.g. ak/gitview).\n\nAlso use ${GIT_DIR} directly  so that it works with below environment setup\n\nGIT_DIR=/home/opensource/Test\\ Output/git-devel/.git\n\nSigned-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n\n---\n\n contrib/gitview/gitview |   54 ++++++++++++-----------------------------------\n 1 files changed, 14 insertions(+), 40 deletions(-)\n\necd82bdd8399b84ada1f4fc0c720a88ae0735a94\ndiff --git a/contrib/gitview/gitview b/contrib/gitview/gitview\nindex 0e52c78..76a1b67 100755\n--- a/contrib/gitview/gitview\n+++ b/contrib/gitview/gitview\n@@ -56,20 +56,6 @@ def show_date(epoch, tz):\n \n \treturn time.strftime(\"%Y-%m-%d %H:%M:%S\", time.gmtime(secs))\n \n-def get_sha1_from_tags(line):\n-\tfp = os.popen(\"git cat-file -t \" + line)\n-\tentry = string.strip(fp.readline())\n-\tfp.close()\n-\tif (entry == \"commit\"):\n-\t\treturn line\n-\telif (entry == \"tag\"):\n-\t\tfp = os.popen(\"git cat-file tag \"+ line)\n-\t\tentry = string.strip(fp.readline())\n-\t\tfp.close()\n-\t\tobj = re.split(\" \", entry)\n-\t\tif (obj[0] == \"object\"):\n-\t\t\treturn obj[1]\n-\treturn None\n \n class CellRendererGraph(gtk.GenericCellRenderer):\n \t\"\"\"Cell renderer for directed graph.\n@@ -467,32 +453,20 @@ class GitView:\n \t\trespective sha1 details \"\"\"\n \n \t\tself.bt_sha1 = { }\n-\t\tgit_dir = os.getenv(\"GIT_DIR\")\n-\t\tif (git_dir == None):\n-\t\t\tgit_dir = \".git\"\n-\n-\t\t#FIXME the path seperator\n-\t\tref_files = os.listdir(git_dir + \"/refs/tags\")\n-\t\tfor file in ref_files:\n-\t\t\tfp = open(git_dir + \"/refs/tags/\"+file)\n-\t\t\tsha1 = get_sha1_from_tags(string.strip(fp.readline()))\n-\t\t\ttry:\n-\t\t\t\tself.bt_sha1[sha1].append(file)\n-\t\t\texcept KeyError:\n-\t\t\t\tself.bt_sha1[sha1] = [file]\n-\t\t\tfp.close()\n-\n-\n-\t\t#FIXME the path seperator\n-\t\tref_files = os.listdir(git_dir + \"/refs/heads\")\n-\t\tfor file in ref_files:\n-\t\t\tfp = open(git_dir + \"/refs/heads/\" + file)\n-\t\t\tsha1 = get_sha1_from_tags(string.strip(fp.readline()))\n-\t\t\ttry:\n-\t\t\t\tself.bt_sha1[sha1].append(file)\n-\t\t\texcept KeyError:\n-\t\t\t\tself.bt_sha1[sha1] = [file]\n-\t\t\tfp.close()\n+\t\tls_remote = re.compile('^(.{40})\\trefs/([^^]+)(?:\\\\^(..))?$');\n+\t\tfp = os.popen('git ls-remote \"${GIT_DIR:-.git}\"')\n+\t\twhile 1:\n+\t\t\tline = string.strip(fp.readline())\n+\t\t\tif line == '':\n+\t\t\t\tbreak\n+\t\t\tm = ls_remote.match(line)\n+\t\t\tif not m:\n+\t\t\t\tcontinue\n+\t\t\t(sha1, name) = (m.group(1), m.group(2))\n+\t\t\tif not self.bt_sha1.has_key(sha1):\n+\t\t\t\tself.bt_sha1[sha1] = []\n+\t\t\tself.bt_sha1[sha1].append(name)\n+\t\tfp.close()\n \n \n \tdef construct(self):\n-- \n1.2.0-dirty\n\n"}]}