# [StGit PATCH] Do not crash if a patch log ref is missing

3 messages from 2008-09-12 to 2008-09-14. Participants: Catalin Marinas, Karl Hasselström.
Thread: https://gitlist.dev/t/15506

## Catalin Marinas, 2008-09-12 21:54

Subject: [StGit PATCH] Do not crash if a patch log ref is missing
Message-ID: <20080912215449.10270.38860.stgit@localhost.localdomain>
URL: https://gitlist.dev/e/20080912215449.10270.38860.stgit%40localhost.localdomain

```
Since we'll get rid of the individual patch logs, StGit should ignore if
such a ref is missing when deleting the compatibility patch files.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/lib/stack.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py
index 9cb3967..1059955 100644
--- a/stgit/lib/stack.py
+++ b/stgit/lib/stack.py
@@ -68,7 +68,11 @@ class Patch(object):
             for f in os.listdir(self.__compat_dir):
                 os.remove(os.path.join(self.__compat_dir, f))
             os.rmdir(self.__compat_dir)
-        self.__stack.repository.refs.delete(self.__log_ref)
+        try:
+            # this compatibility log ref might not exist
+            self.__stack.repository.refs.delete(self.__log_ref)
+        except KeyError:
+            pass
     def set_commit(self, commit, msg):
         self.__write_compat_files(commit, msg)
         self.__stack.repository.refs.set(self.__ref, commit, msg)

```

## Karl Hasselström, 2008-09-14 08:08

Subject: Re: [StGit PATCH] Do not crash if a patch log ref is missing
Message-ID: <20080914080839.GA30664@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20080914080839.GA30664%40diana.vm.bytemark.co.uk
In-Reply-To: <20080912215449.10270.38860.stgit@localhost.localdomain>

```
On 2008-09-12 22:54:58 +0100, Catalin Marinas wrote:

> Since we'll get rid of the individual patch logs, StGit should
> ignore if such a ref is missing when deleting the compatibility
> patch files.

I agree this is a good idea from a robustness perspective. Did you
encounter a case where the deletion actually failed?

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Catalin Marinas, 2008-09-14 21:01

Subject: Re: [StGit PATCH] Do not crash if a patch log ref is missing
Message-ID: <b0943d9e0809141401o36b1347ctf6444a695b74a8b7@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0809141401o36b1347ctf6444a695b74a8b7%40mail.gmail.com
In-Reply-To: <20080914080839.GA30664@diana.vm.bytemark.co.uk>

```
On 14/09/2008, Karl Hasselström <kha@treskal.com> wrote:
> On 2008-09-12 22:54:58 +0100, Catalin Marinas wrote:
>
>  > Since we'll get rid of the individual patch logs, StGit should
>  > ignore if such a ref is missing when deleting the compatibility
>  > patch files.
>
>
> I agree this is a good idea from a robustness perspective. Did you
>  encounter a case where the deletion actually failed?

Yes, I was deleting some older patches and it happened for one of them
not to have a log reference. It left the stack in a pretty undefined
state (and used the stable StGit to delete the rest of the patches as
it is more tolerant :-)).

-- 
Catalin

```
