print log for commit diffs and support csv format 93/125793/3
authorJunghyun Kim <jh0822.kim@samsung.com>
Wed, 19 Apr 2017 01:45:03 +0000 (10:45 +0900)
committerJunghyun Kim <jh0822.kim@samsung.com>
Wed, 19 Apr 2017 05:46:58 +0000 (14:46 +0900)
Two features
1) print commit log between previous and current versions
2) provide a csv-format file

Change-Id: Ia8bf681196e1c1cecd4eae87f56b3c3d71ba34e2
Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
MANIFEST.in
snapdiff/__init__.py
snapdiff/templates/diff.csv [new file with mode: 0644]
snapdiff/templates/diff.html
snapdiff/templates/image_diff.csv [new file with mode: 0644]
snapdiff/templates/image_diff.html

index 99b20aeeca33c59d146cafe8617b30692d9c69c3..10cdd31517da8eccade6ae9a84610dce5e92fb06 100644 (file)
@@ -1,2 +1,3 @@
 include snapdiff/templates/*.html
+include snapdiff/templates/*.csv
 include snapdiff/static/*/*
index 8d24e6a8b667f16e5630c72585097b0c4fb1ca3b..2bbf605081a641eb128a96698b87d5904d7d2587 100644 (file)
@@ -30,6 +30,8 @@ import json
 import os
 import shutil
 import re
+import subprocess
+import io
 
 import yaml
 
@@ -37,6 +39,17 @@ from .image import ks_diff, packages
 from .render import output_html
 from .repo import Repo
 
+def escape_html(s):
+    s = s.replace("&", "&amp;");
+    s = s.replace("<", "&lt;");
+    s = s.replace(">", "&gt;");
+    s = s.replace("'", "&#39;");
+    s = s.replace('"', "&quot;");
+    return s
+
+def escape_html_newline(s):
+    s = s.replace('\n', "<br/>");
+    return s
 
 def diff_to_json(old_url, new_url, **kwargs):
     """Output diffs' json format.
@@ -61,6 +74,42 @@ def diff_to_json(old_url, new_url, **kwargs):
     added, removed, modified, rebuilded = [], [], [], []
     package_names = set(old.__dict__.keys() + new.__dict__.keys())
 
+    def _get_commit_log_delta(old_proj, new_proj, old_commit_id, new_commit_id):
+        cache_dir = os.getenv('GIT_CACHE_DIR')
+        git_dir = os.path.join(cache_dir, new_proj)
+        log_filename = 'git_log'
+
+        if not os.path.exists(git_dir):
+            return []
+
+        revision_range = ''
+        if old_commit_id == None or len(old_commit_id) == 0:
+            revision_range = new_commit_id
+        else:
+            revision_range = old_commit_id + ".." + new_commit_id
+
+        if old_proj != new_proj:
+            revision_range = new_commit_id
+
+        f = io.open(log_filename, 'w', encoding='utf-8', errors='ignore')
+        subprocess.call(['git', '--git-dir='+git_dir+'.git', 'log',
+                        revision_range,
+                        '--pretty="format:||||%H|||%cN<%cE>|||%cD|||%s%n%b||||"'], stdout=f)
+                        #'--pretty="format:||||%H|||%aN<%aE>%n%s%n%b||||"'], stdout=f)
+        f.close()
+        f = io.open(log_filename, 'r', encoding='utf-8', errors='ignore')
+        contents = escape_html(f.read())
+        sp = contents.split("||||")
+        data = []
+        for idx in range(1, len(sp), 2):
+            l = sp[idx].split("|||")
+            data.append({"commit_id": l[0],
+                         "committer": l[1],
+                         "commit_date": l[2],
+                         "commit_log": {'html':escape_html_newline(l[3]), 'raw':l[3]}})
+        f.close()
+        return data
+
     def _get_git_web(url):
         matchdomain = re.match(r"http[s]?://[a-z0-9\.]*", url)
         if not matchdomain:
@@ -109,84 +158,287 @@ def diff_to_json(old_url, new_url, **kwargs):
 
     obj = {style: {'old': old_url, 'new': new_url},
             'diff': {
-                'added': [
-                    {'oldpkg': None,
-                    'newpkg': {
-                        'name': _new.name,
+              'added': [],
+              'removed': [],
+              'modified': [],
+              'rebuilded': [],
+            }}
+    #-----------------------------------------------------------------------------
+    added_p = {}
+    for _new in added:
+        _git_path = _new.version.vcs.split('#', 1)[0]
+        _version = '-'.join([_new.version.ver, _new.version.rel])
+
+        if _git_path not in added_p:
+            added_p[_git_path] = {}
+
+        if _version not in added_p[_git_path]:
+            added_p[_git_path][_version] = []
+
+        added_p[_git_path][_version].append(_new)
+
+    for _git_path in added_p:
+        for _version in added_p[_git_path]:
+            _p = added_p[_git_path][_version][0]
+            _commit_id = _p.version.vcs.split('#',1)[1]
+            _codediff = None
+            _commit_log = _get_commit_log_delta('', _git_path, '', _commit_id)
+
+            ps = []
+            for _pp in added_p[_git_path][_version]:
+                ps.append('.'.join([_pp.name,_pp.arch]))
+
+            p = {'oldpkg': None,
+                 'newpkg': {
+                     'name': ','.join(ps),
+                     'version': {
+                         'epoch': _p.version.epoch,
+                         'rel': _p.version.rel,
+                         'ver': _p.version.ver,
+                     },
+                 'git_path': _git_path,
+                 'commit_id': _commit_id
+                 },
+                 'codediff': _codediff,
+                 'commit_log': _commit_log
+                }
+            obj['diff']['added'].append(p)
+
+    #-----------------------------------------------------------------------------
+    removed_p = {}
+    for _old in removed:
+        _git_path = _old.version.vcs.split('#', 1)[0]
+        _version = '-'.join([_old.version.ver, _old.version.rel])
+
+        if _git_path not in removed_p:
+            removed_p[_git_path] = {}
+
+        if _version not in removed_p[_git_path]:
+            removed_p[_git_path][_version] = []
+
+        removed_p[_git_path][_version].append(_old)
+
+    for _git_path in removed_p:
+        for _version in removed_p[_git_path]:
+            _p = removed_p[_git_path][_version][0]
+            _commit_id = _p.version.vcs.split('#',1)[1]
+            _codediff = None
+
+            ps = []
+            for _pp in removed_p[_git_path][_version]:
+                ps.append('.'.join([_pp.name,_pp.arch]))
+
+            obj['diff']['removed'].append(
+                    {'oldpkg': {
+                        'name': ','.join(ps),
                         'version': {
-                            'epoch': _new.version.epoch,
-                            'rel': _new.version.rel,
-                            'ver': _new.version.ver,
+                            'epoch': _p.version.epoch,
+                            'rel': _p.version.rel,
+                            'ver': _p.version.ver,
                             },
-                        # we use '#' to split vcs into git_path and commit_id,
-                        # but commit_id maybe contains '#', so split the 1st.
-                        'git_path': _new.version.vcs.split('#', 1)[0],
-                        'commit_id': _new.version.vcs.split('#', 1)[1],
+                        'git_path': _git_path,
+                        'commit_id': _commit_id
                         },
-                    'codediff': None,
-                    } for _new in added],
-                'removed': [
+                        'newpkg': None,
+                        'codediff': _codediff,
+                        })
+
+    #-----------------------------------------------------------------------------
+    modified_p = {}
+    for _old, _new in modified:
+        _git_path = _old.version.vcs.split('#',1)[0]
+        _version = '-'.join([_old.version.ver, _old.version.rel, _new.version.ver, _new.version.rel])
+
+        if _git_path not in modified_p:
+            modified_p[_git_path] = {}
+
+        if _version not in modified_p:
+            modified_p[_git_path][_version] = []
+
+        modified_p[_git_path][_version].append((_old,_new))
+
+    for _git_path in modified_p:
+        for _version in modified_p[_git_path]:
+            (_old,_new) = modified_p[_git_path][_version][0]
+            _old_git_path  = _old.version.vcs.split('#', 1)[0]
+            _old_commit_id = _old.version.vcs.split('#', 1)[1]
+            _new_git_path  = _new.version.vcs.split('#', 1)[0]
+            _new_commit_id = _new.version.vcs.split('#', 1)[1]
+
+            _codediff = None
+            _commit_log = _get_commit_log_delta(_old_git_path, _new_git_path,
+                                                _old_commit_id, _new_commit_id)
+
+            ps = []
+            for _old, _new in modified_p[_git_path][_version]:
+                ps.append('.'.join([_old.name,_old.arch]))
+
+            names = ','.join(ps)
+            obj['diff']['modified'].append(
                     {'oldpkg': {
-                        'name': _old.name,
+                        'name': names,
                         'version': {
                             'epoch': _old.version.epoch,
                             'rel': _old.version.rel,
                             'ver': _old.version.ver,
                             },
-                        'git_path': _old.version.vcs.split('#', 1)[0],
-                        'commit_id': _old.version.vcs.split('#', 1)[1],
+                        'git_path': _old_git_path,
+                        'commit_id': _old_commit_id
                         },
-                    'newpkg': None,
-                    'codediff': None,
-                    } for _old in removed],
-                'modified': [
+                        'newpkg':{
+                            'name': names,
+                            'version': {
+                                'epoch': _new.version.epoch,
+                                'rel': _new.version.rel,
+                                'ver': _new.version.ver,
+                                },
+                            'git_path': _new_git_path,
+                            'commit_id': _new_commit_id
+                            },
+                        'codediff': _codediff,
+                        'commit_log': _commit_log
+                        })
+
+    #-----------------------------------------------------------------------------
+    rebuilded_p = {}
+    for _old, _new in rebuilded:
+        _git_path = _old.version.vcs.split('#',1)[0]
+        _version = '-'.join([_old.version.ver, _old.version.rel, _new.version.ver, _new.version.rel])
+
+        if _git_path not in rebuilded_p:
+            rebuilded_p[_git_path] = {}
+
+        if _version not in rebuilded_p:
+            rebuilded_p[_git_path][_version] = []
+
+        rebuilded_p[_git_path][_version].append((_old,_new))
+
+    for _git_path in rebuilded_p:
+        for _version in rebuilded_p[_git_path]:
+            (_old,_new) = rebuilded_p[_git_path][_version][0]
+            _old_git_path  = _old.version.vcs.split('#', 1)[0]
+            _old_commit_id = _old.version.vcs.split('#', 1)[1]
+            _new_git_path  = _new.version.vcs.split('#', 1)[0]
+            _new_commit_id = _new.version.vcs.split('#', 1)[1]
+
+            _codediff = None
+
+            ps = []
+            for _old, _new in rebuilded_p[_git_path][_version]:
+                ps.append('.'.join([_old.name,_old.arch]))
+
+            names = ','.join(ps)
+            obj['diff']['rebuilded'].append(
                     {'oldpkg': {
-                        'name': _old.name,
+                        'name': names,
                         'version': {
                             'epoch': _old.version.epoch,
                             'rel': _old.version.rel,
                             'ver': _old.version.ver,
                             },
-                        'git_path': _old.version.vcs.split('#', 1)[0],
-                        'commit_id': _old.version.vcs.split('#', 1)[1],
+                        'git_path': _old_git_path,
+                        'commit_id': _old_commit_id
                         },
-                    'newpkg': {
-                        'name': _new.name,
-                        'version': {
-                            'epoch': _new.version.epoch,
-                            'rel': _new.version.rel,
-                            'ver': _new.version.ver,
+                        'newpkg':{
+                            'name': names,
+                            'version': {
+                                'epoch': _new.version.epoch,
+                                'rel': _new.version.rel,
+                                'ver': _new.version.ver,
+                                },
+                            'git_path': _new_git_path,
+                            'commit_id': _new_commit_id
                             },
-                        'git_path': _new.version.vcs.split('#', 1)[0],
-                        'commit_id': _new.version.vcs.split('#', 1)[1],
-                        },
-                    'codediff': None,
-                    } for _old, _new in modified],
-                 'rebuilded': [{
-                     'oldpkg': {
-                         'name': _old.name,
-                         'version': {
-                             'epoch': _old.version.epoch,
-                             'rel': _old.version.rel,
-                             'ver': _old.version.ver,
-                             },
-                        'git_path': _old.version.vcs.split('#', 1)[0],
-                        'commit_id': _old.version.vcs.split('#', 1)[1],
-                        },
-                     'newpkg': {
-                         'name': _new.name,
-                         'version': {
-                             'epoch': _new.version.epoch,
-                             'rel': _new.version.rel,
-                             'ver': _new.version.ver,
-                             },
-                         'git_path': _new.version.vcs.split('#', 1)[0],
-                         'commit_id': _new.version.vcs.split('#', 1)[1],
-                         },
-                     'codediff': None,
-                     } for _old, _new in rebuilded],
-                }
-            }
+                        'codediff': _codediff,
+                        })
+
+    #-----------------------------------------------------------------------------
+    #obj = {style: {'old': old_url, 'new': new_url},
+            #'diff': {
+                #'added': [
+                    #{'oldpkg': None,
+                    #'newpkg': {
+                        #'name': _new.name,
+                        #'version': {
+                            #'epoch': _new.version.epoch,
+                            #'rel': _new.version.rel,
+                            #'ver': _new.version.ver,
+                            #},
+                        ## we use '#' to split vcs into git_path and commit_id,
+                        ## but commit_id maybe contains '#', so split the 1st.
+                        #'git_path': _new.version.vcs.split('#', 1)[0],
+                        #'commit_id': _new.version.vcs.split('#', 1)[1],
+                        #},
+                    #'codediff': None,
+                    #'commit_log': _get_commit_log_delta('', _new.version.vcs.split('#',1)[0],
+                                                        #'', _new.version.vcs.split('#',1)[1])
+                    #} for _new in added],
+                #'removed': [
+                    #{'oldpkg': {
+                        #'name': _old.name,
+                        #'version': {
+                            #'epoch': _old.version.epoch,
+                            #'rel': _old.version.rel,
+                            #'ver': _old.version.ver,
+                            #},
+                        #'git_path': _old.version.vcs.split('#', 1)[0],
+                        #'commit_id': _old.version.vcs.split('#', 1)[1],
+                        #},
+                    #'newpkg': None,
+                    #'codediff': None,
+                    #} for _old in removed],
+                #'modified': [
+                    #{'oldpkg': {
+                        #'name': _old.name,
+                        #'version': {
+                            #'epoch': _old.version.epoch,
+                            #'rel': _old.version.rel,
+                            #'ver': _old.version.ver,
+                            #},
+                        #'git_path': _old.version.vcs.split('#', 1)[0],
+                        #'commit_id': _old.version.vcs.split('#', 1)[1],
+                        #},
+                    #'newpkg': {
+                        #'name': _new.name,
+                        #'version': {
+                            #'epoch': _new.version.epoch,
+                            #'rel': _new.version.rel,
+                            #'ver': _new.version.ver,
+                            #},
+                        #'git_path': _new.version.vcs.split('#', 1)[0],
+                        #'commit_id': _new.version.vcs.split('#', 1)[1],
+                        #},
+                    #'codediff': None,
+                    #'commit_log': _get_commit_log_delta(_old.version.vcs.split('#',1)[0],
+                                                        #_new.version.vcs.split('#',1)[0],
+                                                        #_old.version.vcs.split('#',1)[1],
+                                                        #_new.version.vcs.split('#',1)[1]),
+                    #} for _old, _new in modified],
+                 #'rebuilded': [{
+                     #'oldpkg': {
+                         #'name': _old.name,
+                         #'version': {
+                             #'epoch': _old.version.epoch,
+                             #'rel': _old.version.rel,
+                             #'ver': _old.version.ver,
+                             #},
+                        #'git_path': _old.version.vcs.split('#', 1)[0],
+                        #'commit_id': _old.version.vcs.split('#', 1)[1],
+                        #},
+                     #'newpkg': {
+                         #'name': _new.name,
+                         #'version': {
+                             #'epoch': _new.version.epoch,
+                             #'rel': _new.version.rel,
+                             #'ver': _new.version.ver,
+                             #},
+                         #'git_path': _new.version.vcs.split('#', 1)[0],
+                         #'commit_id': _new.version.vcs.split('#', 1)[1],
+                         #},
+                     #'codediff': None,
+                     #} for _old, _new in rebuilded],
+                #}
+            #}
 
     if style == 'image':
         obj['diff']['ks'] = ks_diff(old_url, new_url)
@@ -196,6 +448,38 @@ def diff_to_json(old_url, new_url, **kwargs):
 
     return json.dumps(obj, indent=4)
 
+def diff_to_csv(old_url, new_url, **kwargs):
+    """Output diffs' html format.
+
+    :param old_url: old repo or image url
+    :param new_url: new repo or image url
+    :param style: repo or image type, default is repo
+    """
+
+    style = kwargs.get('style') or 'repo'
+    diff_name = kwargs.get('diff_name') or 'diff'
+
+    json_obj = diff_to_json(old_url, new_url, style=style)
+
+    if json_obj is None:
+        return
+
+    data = json.loads(json_obj)
+
+    context = {
+        'old': {'url': old_url,
+            'name': re.search(r'\w*_\d{8}\.\d*', old_url).group(0)},
+        'new': {'url': new_url,
+            'name': re.search(r'\w*_\d{8}\.\d*', new_url).group(0)},
+        'diff': data['diff'],
+        'filename': diff_name,
+        'gitweb': data['gitweb']
+        }
+    if style == 'repo':
+        return output_html('diff.csv', **context) # pylint: disable=W0142
+    elif style == 'image':
+        return output_html('image_diff.csv', **context) # pylint: disable=W0142
+
 def diff_to_html(old_url, new_url, **kwargs):
     """Output diffs' html format.
 
@@ -205,6 +489,7 @@ def diff_to_html(old_url, new_url, **kwargs):
     """
 
     style = kwargs.get('style') or 'repo'
+    diff_name = kwargs.get('diff_name') or 'diff'
 
     json_obj = diff_to_json(old_url, new_url, style=style)
 
@@ -219,6 +504,7 @@ def diff_to_html(old_url, new_url, **kwargs):
         'new': {'url': new_url,
             'name': re.search(r'\w*_\d{8}\.\d*', new_url).group(0)},
         'diff': data['diff'],
+        'filename': diff_name,
         'gitweb': data['gitweb']
         }
     if style == 'repo':
@@ -238,8 +524,6 @@ def diff_to_dist(old_url, new_url, dist_path, **kwargs):
     static_dir = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'static')
 
-    output = diff_to_html(old_url, new_url, style=kwargs.get('style'))
-
     if not os.path.exists(dist_path):
         os.makedirs(dist_path)
 
@@ -258,6 +542,11 @@ def diff_to_dist(old_url, new_url, dist_path, **kwargs):
 
     diff_name = kwargs.get('diff_name') or 'diff'
 
-    with open(os.path.join(dist_path, '%s.html' % diff_name), 'w') as fname:
+    output = diff_to_html(old_url, new_url, style=kwargs.get('style'), diff_name=diff_name)
+    with io.open(os.path.join(dist_path, '%s.html' % diff_name), 'w', encoding='utf-8', errors='ignore') as fname:
+        fname.write(output)
+
+    output = diff_to_csv(old_url, new_url, style=kwargs.get('style'), diff_name=diff_name)
+    with io.open(os.path.join(dist_path, '%s.csv' % diff_name), 'w', encoding='utf-8', errors='ignore') as fname:
         fname.write(output)
     return dist_path
diff --git a/snapdiff/templates/diff.csv b/snapdiff/templates/diff.csv
new file mode 100644 (file)
index 0000000..ce8fe3a
--- /dev/null
@@ -0,0 +1,47 @@
+Difference between {{old['name']}} and {{new['name']}}
+
+Added Packages: {{ diff['added']|count }}
+Removed Packages: {{ diff['removed']|count }}
+Modified packages: {{ diff['modified']|count }}
+Packages with Rebuilds: {{ diff['rebuilded']|count }}
+
+Added Packages,{% if diff['added'] %}
+Package,Version,Git Path,CommitId,DiffCommits,CommitId,Committer,Commit Date,Commit Log
+  {%- for item in diff['added'] -%}
+    {%- set diff_commits = item['commit_log']|length %}
+"{{ item['newpkg']['name']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ item['newpkg']['git_path'] }}","{{ item['newpkg']['commit_id'] }}","{{diff_commits}}"
+    {%- for commit_item in item['commit_log'] %}
+,,,,,"{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
+Removed Packages,{% if diff['removed'] %}
+Package,Version,Git Path,CommitId
+  {%- for item in diff['removed'] %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['oldpkg']['git_path'] }}","{{ item['oldpkg']['commit_id'] }}"
+  {%- endfor -%}
+{%- endif %}
+
+Modified Packages,{% if diff['modified'] %}
+Package,Old Version,New Version,Git Path,Old CommitId,New CommitId,DiffCommits,CommitId,Committer,Commit Date,Commit Log
+  {%- for item in diff['modified'] -%}
+  {%- set diff_commits = item['commit_log']|length -%}
+  {%- if item['oldpkg']['git_path'] != item['newpkg']['git_path'] -%}
+    {%- set git_path = item['oldpkg']['git_path'] + "-" + item['newpkg']['git_path'] -%}
+  {%- else -%}
+    {%- set git_path = item['oldpkg']['git_path'] -%}
+  {%- endif %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ git_path }}","{{item['oldpkg']['commit_id']}}","{{item['newpkg']['commit_id']}}","{{diff_commits}}"
+    {%- for commit_item in item['commit_log'] %}
+,,,,,,,"{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
+Packages with Rebuilds,{% if diff['rebuilded'] %}
+Package,Old Version,New Version,Git Path,CommitId
+  {%- for item in diff['rebuilded'] %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ item['oldpkg']['git_path'] }}","{{item['oldpkg']['commit_id']}}"
+  {%- endfor -%}
+{%- endif -%}
index 578e7bea3935d46af037f4ee9f38c4b9088fbcc0..69e234b130bd6551a394561364eb59a873ece69b 100644 (file)
@@ -9,6 +9,20 @@
     <link href="./css/shCore.css" rel="stylesheet" type="text/css" />
     <link href="./css/shThemeDefault.css" rel="stylesheet" type="text/css" />
     <link href="./css/diff.css" rel="stylesheet" type="text/css" />
+
+<script>
+function toggle_show(table_id, button) {
+  var obj = document.getElementById(table_id);
+  if( obj.style.display == 'none' ) {
+    obj.style.display = "";
+    button.innerHTML="-";
+  } else {
+    obj.style.display = "none";
+    button.innerHTML="+";
+  }
+}
+
+</script>
 </head>
 <body>
     <div id="page-wrapper">
@@ -26,6 +40,7 @@
         Repository Difference and Changelogs
     </h1>
     <a href="index.html">Go back</a>...<br>
+    <a href="{{filename}}.csv">csv format</a>...<br>
     <p>Difference between
         <a href="{{old['url']}}">{{ old['name'] }}</a> and <a href="{{new['url']}}">{{ new['name'] }}</a>
     </p>
         <li><a href="#modified">Modified packages: {{ diff['modified']|count }}</a></li>
         <li><a href="#rebuilded">Packages with Rebuilds: {{ diff['rebuilded']|count }}</a></li>
     </ul>
-    <table>
-        <tr><td colspan="6" class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
+    <table id='data_table'>
+        <tr><td colspan="8" id='added' class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
         {% set git_web = gitweb %}
         {% if diff['added'] %}
             <tbody>
             <tr>
-                <th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan=2>CommitId</th><th>DiffCommits</th>
             </tr>
             {% for item in diff['added'] %}
+            {% set diff_commits = item['commit_log']|length %}
+            {% set table_id = 'added_table_'+ (loop.index|string) %}
                 <tr>
+                    <td>
+                      <button style='width:30px' onclick="toggle_show('{{table_id}}', this)">+</button>
+                    </td>
                     <td>{{ item['newpkg']['name'] }}</td>
                     <td colspan="2">{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
+                    <td colspan=2><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
+                    <td>{{diff_commits}}</td>
                 </tr>
+
+                <tr><td colspan=8>
+                  <table id='{{table_id}}' style='display:none'>
+                    <thead>
+                      <tr>
+                        <th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                    {% for commit_item in item['commit_log'] %}
+                    <tr>
+                      <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                      <td>{{ commit_item['committer'] }}</td>
+                      <td>{{ commit_item['commit_date'] }}</td>
+                      <td>{{ commit_item['commit_log']['html'] }}</td>
+                    </tr>
+                    {% endfor %}
+                    </tbody>
+                  </table>
+                </td></tr>
+
             {% endfor %}
             </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Removed Packages</a></h3></td></tr>
+        <tr><td colspan="8" id='removed' class="tableTitle"><h3><a>Removed Packages</a></h3></td></tr>
         {% if diff['removed'] %}
          <tbody>
             <tr>
-                <th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="3">CommitId</th>
             </tr>
             {% for item in diff['removed'] %}
                 <tr>
+                    <td></td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td colspan="2">{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td colspan="3"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
         </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Modified Packages</a></h3></td></tr>
+        <tr><td colspan="8" id='modified' class="tableTitle"><h3><a>Modified Packages</a></h3></td></tr>
         {% if diff['modified'] %}
-         <tbody>
+            <tbody>
             <tr>
-                <th>Package</th><th>Old Version</th><th>New Version</th><th>GitPath</th><th>Old CommitId</th><th>New CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th>Old Version</th><th>New Version</th><th>GitPath</th><th>Old CommitId</th><th>New CommitId</th><th>DiffCommits</th>
             </tr>
             {% for item in diff['modified'] %}
+            {% set diff_commits = item['commit_log']|length %}
+            {% set table_id = 'modified_table_'+ (loop.index|string) %}
                 <tr>
+                    <td>
+                      <button style='width:30px' onclick="toggle_show('{{table_id}}', this)">+</button>
+                    </td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     </td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                     <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
-                    </td>
+                    <td>{{diff_commits}}</td>
                 </tr>
+
+                <tr><td colspan=8>
+                  <table id='{{table_id}}' style='display:none'>
+                    <thead>
+                      <tr>
+                        <th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                    {% for commit_item in item['commit_log'] %}
+                    <tr>
+                      <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                      <td>{{ commit_item['committer'] }}</td>
+                      <td>{{ commit_item['commit_date'] }}</td>
+                      <td>{{ commit_item['commit_log']['html'] }}</td>
+                    </tr>
+                    {% endfor %}
+                    </tbody>
+                  </table>
+                </td></tr>
+
+
             {% endfor %}
-        </tbody>
+            </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Packages with Rebuilds</a></h3></td></tr>
+        <tr><td colspan="8" id='rebuilded' class="tableTitle"><h3><a>Packages with Rebuilds</a></h3></td></tr>
         {% if diff['rebuilded'] %}
          <tbody>
             <tr>
-                <th>Package</th><th>Old Version</th><th>New Version</td><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th>Old Version</th><th>New Version</td><th>GitPath</th><th colspan="3">CommitId</th>
             </tr>
             {% for item in diff['rebuilded'] %}
                 <tr>
+                    <td></td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td colspan="3"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
         </tbody>
         {% endif %}
     </table>
 </body>
+
 </html>
 
diff --git a/snapdiff/templates/image_diff.csv b/snapdiff/templates/image_diff.csv
new file mode 100644 (file)
index 0000000..1ede8d1
--- /dev/null
@@ -0,0 +1,71 @@
+
+Difference between {{old['name']}} and {{new['name']}}
+
+KS
+
+{% if diff['ks'] %}
+,"{{diff['ks']['file_name'][0]}}","{{diff['ks']['file_name'][1]}}"
+  {%- if diff['ks']['sections'] -%}
+    {%- for section in diff['ks']['sections'] -%}
+      {%- for hunk in section['hunks'] -%}
+        {%- if hunk['type'] == "context" %}
+"{{hunk['left_num']}}","{{hunk['text']}}","{{hunk['text']}}","{{hunk['right_num']}}"
+        {%- elif hunk['type'] == "delete" %}
+"{{hunk['left_num']}}","{{hunk['left_text']}}"
+        {%- elif hunk['type'] == "insert" %}
+,,"{{hunk['right_text']}}","{{hunk['right_num']}}"
+        {%- elif hunk['type'] == "change" %}
+"{{hunk['left_num']}}","{{hunk['left_text']}}","{{hunk['right_text']}}","{{hunk['right_num']}}"
+        {%- endif %}
+      {%- endfor %}
+      {%- if not loop.last %}
+      {% endif %}
+    {%- endfor %}
+  {%- endif %}
+{%- endif %}
+
+Added Packages: {{ diff['added']|count }}
+Removed Packages: {{ diff['removed']|count }}
+Modified packages: {{ diff['modified']|count }}
+Packages with Rebuilds: {{ diff['rebuilded']|count }}
+
+Added Packages,{% if diff['added'] %}
+Package,Version,Git Path,CommitId,DiffCommits,CommitId,Committer,Commit Date,Commit Log
+  {%- for item in diff['added'] -%}
+    {%- set diff_commits = item['commit_log']|length %}
+"{{ item['newpkg']['name']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ item['newpkg']['git_path'] }}","{{ item['newpkg']['commit_id'] }}","{{diff_commits}}"
+    {%- for commit_item in item['commit_log'] %}
+,,,,,"{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
+Removed Packages,{% if diff['removed'] %}
+Package,Version,Git Path,CommitId
+  {%- for item in diff['removed'] %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['oldpkg']['git_path'] }}","{{ item['oldpkg']['commit_id'] }}"
+  {%- endfor -%}
+{%- endif %}
+
+Modified Packages,{% if diff['modified'] %}
+Package,Old Version,New Version,Git Path,Old CommitId,New CommitId,DiffCommits,CommitId,Committer,Commit Date,Commit Log
+  {%- for item in diff['modified'] -%}
+  {%- set diff_commits = item['commit_log']|length -%}
+  {%- if item['oldpkg']['git_path'] != item['newpkg']['git_path'] -%}
+    {%- set git_path = item['oldpkg']['git_path'] + "-" + item['newpkg']['git_path'] -%}
+  {%- else -%}
+    {%- set git_path = item['oldpkg']['git_path'] -%}
+  {%- endif %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ git_path }}","{{item['oldpkg']['commit_id']}}","{{item['newpkg']['commit_id']}}","{{diff_commits}}"
+    {%- for commit_item in item['commit_log'] %}
+,,,,,,,"{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
+Packages with Rebuilds,{% if diff['rebuilded'] %}
+Package,Old Version,New Version,Git Path,CommitId
+  {%- for item in diff['rebuilded'] %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}","{{ item['oldpkg']['git_path'] }}","{{item['oldpkg']['commit_id']}}"
+  {%- endfor -%}
+{%- endif -%}
index a887500f2d8e2d14d0aeb1b4dd6e913167c1918f..0ddf432e5c93f833b4dcf03f8d60d30c65437928 100644 (file)
@@ -9,6 +9,18 @@
     <link href="./css/shCore.css" rel="stylesheet" type="text/css" />
     <link href="./css/shThemeDefault.css" rel="stylesheet" type="text/css" />
     <link href="./css/diff.css" rel="stylesheet" type="text/css" />
+<script>
+function toggle_show(table_id, button) {
+  var obj = document.getElementById(table_id);
+  if( obj.style.display == 'none' ) {
+    obj.style.display = "";
+    button.innerHTML="-";
+  } else {
+    obj.style.display = "none";
+    button.innerHTML="+";
+  }
+}
+</script>
 </head>
 <body>
     <div id="page-wrapper">
@@ -26,6 +38,7 @@
         Repository Difference and Changelogs
     </h1>
     <a href="index.html">Go back</a>...<br>
+    <a href="{{filename}}.csv">csv format</a>...<br>
     <p>Difference between
         <a href="{{old['url']}}">{{ old['name'] }}</a> and <a href="{{new['url']}}">{{ new['name'] }}</a>
     </p>
@@ -46,7 +59,7 @@
                         {% elif hunk['type'] == "delete" %}
                         <tr>
                             <td class="left_num">{{hunk['left_num']}}</td>
-                            <td class="code_delete content">{{hunk['ileft_text']}}</td>
+                            <td class="code_delete content">{{hunk['left_text']}}</td>
                             <td class="nocontent content"></td>
                             <td class="right_num"></td>
                         </tr>
         <li><a href="#rebuilded">Packages with Rebuilds: {{ diff['rebuilded']|count }}</a></li>
     </ul>
     <table>
-        <tr><td colspan="6" class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
+        <tr><td colspan="8" id='added' class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
         {% set git_web = gitweb %}
         {% if diff['added'] %}
             <tbody>
             <tr>
-                <th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan=2>CommitId</th><th>DiffCommits</th>
             </tr>
             {% for item in diff['added'] %}
+            {% set diff_commits = item['commit_log']|length %}
+            {% set table_id = 'added_table_'+ (loop.index|string) %}
                 <tr>
+                    <td>
+                      <button style='width:30px' onclick="toggle_show('{{table_id}}', this)">+</button>
+                    </td>
                     <td>{{ item['newpkg']['name'] }}</td>
-                    <td colspan="2">{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
+                    <td colspan=2>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
+                    <td colspan=2><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
+                    <td>{{diff_commits}}</td>
                 </tr>
+
+                <tr><td colspan=8>
+                  <table id='{{table_id}}' style='display:none'>
+                    <thead>
+                      <tr>
+                        <th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                    {% for commit_item in item['commit_log'] %}
+                    <tr>
+                      <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                      <td>{{ commit_item['committer'] }}</td>
+                      <td>{{ commit_item['commit_date'] }}</td>
+                      <td>{{ commit_item['commit_log']['html'] }}</td>
+                    </tr>
+                    {% endfor %}
+                    </tbody>
+                  </table>
+                </td></tr>
+
             {% endfor %}
             </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Removed Packages</a></h3></td></tr>
+        <tr><td colspan="8" id='removed' class="tableTitle"><h3><a>Removed Packages</a></h3></td></tr>
         {% if diff['removed'] %}
             <tbody>
             <tr>
-                <th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="3">CommitId</th>
             </tr>
             {% for item in diff['removed'] %}
                 <tr>
+                    <td></td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td colspan="2">{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td colspan="3"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
             </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Modified Packages</a></h3></td></tr>
+        <tr><td colspan="8" id='modified' class="tableTitle"><h3><a>Modified Packages</a></h3></td></tr>
         {% if diff['modified'] %}
             <tbody>
             <tr>
-                <th>Package</th><th>Old Version</th><th>New Version</th><th>GitPath</th><th>Old CommitId</th><th>New CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th>Old Version</th><th>New Version</th><th>GitPath</th><th>Old CommitId</th><th>New CommitId</th><th>DiffCommits</th>
             </tr>
             {% for item in diff['modified'] %}
+            {% set diff_commits = item['commit_log']|length %}
+            {% set table_id = 'modified_table_'+ (loop.index|string) %}
                 <tr>
+                    <td>
+                      <button style='width:30px' onclick="toggle_show('{{table_id}}', this)">+</button>
+                    </td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     </td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                     <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
-                    </td>
+                    <td>{{diff_commits}}</td>
                 </tr>
+
+                <tr><td colspan=8>
+                  <table id='{{table_id}}' style='display:none'>
+                    <thead>
+                      <tr>
+                        <th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+                      </tr>
+                    </thead>
+                    <tbody>
+                    {% for commit_item in item['commit_log'] %}
+                    <tr>
+                      <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                      <td>{{ commit_item['committer'] }}</td>
+                      <td>{{ commit_item['commit_date'] }}</td>
+                      <td>{{ commit_item['commit_log']['html'] }}</td>
+                    </tr>
+                    {% endfor %}
+                    </tbody>
+                  </table>
+                </td></tr>
+
+
             {% endfor %}
             </tbody>
         {% endif %}
-        <tr><td colspan="6" class="tableTitle"><h3><a>Packages with Rebuilds</a></h3></td></tr>
+        <tr><td colspan="8" id='rebuilded' class="tableTitle"><h3><a>Packages with Rebuilds</a></h3></td></tr>
         {% if diff['rebuilded'] %}
-        <tbody>
+         <tbody>
             <tr>
-                <th>Package</th><th>Old Version</th><th>New Version</th><th>GitPath</th><th colspan="2">CommitId</th>
+              <th style='width:40px'></th><th>Package</th><th>Old Version</th><th>New Version</td><th>GitPath</th><th colspan="3">CommitId</th>
             </tr>
             {% for item in diff['rebuilded'] %}
                 <tr>
+                    <td></td>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
                     <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
-                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td colspan="3"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
-            </tbody>
+        </tbody>
         {% endif %}
     </table>
 </body>