# [StGit PATCH] Import git show output easily

3 messages from 2009-09-02 to 2009-09-02. Participants: Catalin Marinas, Gustav Hållberg.
Thread: https://gitlist.dev/t/20825

## Catalin Marinas, 2009-09-02 17:50

Subject: [StGit PATCH] Import git show output easily
Message-ID: <20090902175039.21633.25294.stgit@pc1117.cambridge.arm.com>
URL: https://gitlist.dev/e/20090902175039.21633.25294.stgit%40pc1117.cambridge.arm.com

```
This patch modifies the import command to check for standard 'git show'
output and parse it accordingly.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/common.py |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index d38d263..0d39148 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -355,6 +355,7 @@ def __parse_description(descr):
 
     lasthdr = 0
     end = len(descr_lines)
+    descr_strip = 0
 
     # Parse the patch header
     for pos in range(0, end):
@@ -374,12 +375,16 @@ def __parse_description(descr):
         if subject:
             break
         # get the subject
-        subject = descr_lines[pos]
+        subject = descr_lines[pos][descr_strip:]
+        if re.match('commit [\da-f]{40}$', subject):
+            # 'git show' output, look for the real subject
+            subject = ''
+            descr_strip = 4
         lasthdr = pos + 1
 
     # get the body
     if lasthdr < end:
-        body = reduce(lambda x, y: x + '\n' + y, descr_lines[lasthdr:], '')
+        body = '\n' + '\n'.join(l[descr_strip:] for l in descr_lines[lasthdr:])
 
     return (subject + body, authname, authemail, authdate)
 

```

## Gustav Hållberg, 2009-09-02 20:51

Subject: Re: [StGit PATCH] Import git show output easily
Message-ID: <a1e915350909021351l315358a0s9d8c076440bc0fb7@mail.gmail.com>
URL: https://gitlist.dev/e/a1e915350909021351l315358a0s9d8c076440bc0fb7%40mail.gmail.com
In-Reply-To: <20090902175039.21633.25294.stgit@pc1117.cambridge.arm.com>

```
Somewhat related:

It would really rock if stg import could handle the regular patch "-p<N>" flag.
In particular, I miss -p0 as some broken versioning systems default to
such output.

- Gustav

```

## Catalin Marinas, 2009-09-02 20:54

Subject: Re: [StGit PATCH] Import git show output easily
Message-ID: <b0943d9e0909021354y3c795265p693131b44928e0fe@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0909021354y3c795265p693131b44928e0fe%40mail.gmail.com
In-Reply-To: <a1e915350909021351l315358a0s9d8c076440bc0fb7@mail.gmail.com>

```
2009/9/2 Gustav Hållberg <gustav@gmail.com>:
> It would really rock if stg import could handle the regular patch "-p<N>" flag.
> In particular, I miss -p0 as some broken versioning systems default to
> such output.

It's probably just a matter of passing the right flag to git-apply.
I'll try to have a look before -rc3.

-- 
Catalin

```
