Patchwork [2/2] scripts/combo-layer: handle diffs in commit messages

login
register
mail settings
Submitter Paul Eggleton
Date March 22, 2012, 5:15 p.m.
Message ID <f876f5ca2d2e19fd35d90706f9e7087ed31ba5e0.1332436375.git.paul.eggleton@linux.intel.com>
Download mbox | patch
Permalink /patch/24169/
State New
Headers show

Comments

Paul Eggleton - March 22, 2012, 5:15 p.m.
A few recent commits in the OE-Core repository contain diffs in their
commit messages, which totally confuses git-am when applying them to the
combo repository during update. Add some code to detect and indent any
Otavio Salvador - March 22, 2012, 7:45 p.m.
Acked-by: Otavio Salvador <otavio@ossystems.com.br>


On Thu, Mar 22, 2012 at 14:15, Paul Eggleton
<paul.eggleton@linux.intel.com> wrote:
> A few recent commits in the OE-Core repository contain diffs in their
> commit messages, which totally confuses git-am when applying them to the
> combo repository during update. Add some code to detect and indent any
> diff text in the commit message so that this does not happen (and show a
> warning).
>
> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
> ---
>  scripts/combo-layer |   38 ++++++++++++++++++++++++++++++++++++++
>  1 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/combo-layer b/scripts/combo-layer
> index 3612323..73d61cc 100755
> --- a/scripts/combo-layer
> +++ b/scripts/combo-layer
> @@ -144,6 +144,43 @@ def check_repo_clean(repodir):
>         logger.error("git repo %s is dirty, please fix it first", repodir)
>         sys.exit(1)
>
> +def check_patch(patchfile):
> +    f = open(patchfile)
> +    ln = f.readline()
> +    of = None
> +    in_patch = False
> +    beyond_msg = False
> +    pre_buf = ''
> +    while ln:
> +        if not beyond_msg:
> +            if ln == '---\n':
> +                if not of:
> +                    break
> +                in_patch = False
> +                beyond_msg = True
> +            elif ln.startswith('--- '):
> +                # We have a diff in the commit message
> +                in_patch = True
> +                if not of:
> +                    print('WARNING: %s contains a diff in its commit message, indenting to avoid failure during apply' % patchfile)
> +                    of = open(patchfile + '.tmp', 'w')
> +                    of.write(pre_buf)
> +                    pre_buf = ''
> +            elif in_patch and not ln[0] in '+-@ \n\r':
> +                in_patch = False
> +        if of:
> +            if in_patch:
> +                of.write(' ' + ln)
> +            else:
> +                of.write(ln)
> +        else:
> +            pre_buf += ln
> +        ln = f.readline()
> +    f.close()
> +    if of:
> +        of.close()
> +        os.rename(patchfile + '.tmp', patchfile)
> +
>  def action_update(conf, args):
>     """
>         update the component repos
> @@ -227,6 +264,7 @@ def action_update(conf, args):
>         count=len(revlist)-1
>         for patch in patchlist:
>             f.write("%s %s\n" % (patch, revlist[count]))
> +            check_patch(os.path.join(patch_dir, patch))
>             count=count-1
>         f.close()
>
> --
> 1.7.5.4
>
>
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core

Patch

diff text in the commit message so that this does not happen (and show a
warning).

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/combo-layer |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/scripts/combo-layer b/scripts/combo-layer
index 3612323..73d61cc 100755
--- a/scripts/combo-layer
+++ b/scripts/combo-layer
@@ -144,6 +144,43 @@  def check_repo_clean(repodir):
         logger.error("git repo %s is dirty, please fix it first", repodir)
         sys.exit(1)
 
+def check_patch(patchfile):
+    f = open(patchfile)
+    ln = f.readline()
+    of = None
+    in_patch = False
+    beyond_msg = False
+    pre_buf = ''
+    while ln:
+        if not beyond_msg:
+            if ln == '---\n':
+                if not of:
+                    break
+                in_patch = False
+                beyond_msg = True
+            elif ln.startswith('--- '):
+                # We have a diff in the commit message
+                in_patch = True
+                if not of:
+                    print('WARNING: %s contains a diff in its commit message, indenting to avoid failure during apply' % patchfile)
+                    of = open(patchfile + '.tmp', 'w')
+                    of.write(pre_buf)
+                    pre_buf = ''
+            elif in_patch and not ln[0] in '+-@ \n\r':
+                in_patch = False
+        if of:
+            if in_patch:
+                of.write(' ' + ln)
+            else:
+                of.write(ln)
+        else:
+            pre_buf += ln
+        ln = f.readline()
+    f.close()
+    if of:
+        of.close()
+        os.rename(patchfile + '.tmp', patchfile)
+
 def action_update(conf, args):
     """
         update the component repos
@@ -227,6 +264,7 @@  def action_update(conf, args):
         count=len(revlist)-1
         for patch in patchlist:
             f.write("%s %s\n" % (patch, revlist[count]))
+            check_patch(os.path.join(patch_dir, patch))
             count=count-1
         f.close()