threads / patch / 7983

patch, 2 partsImproving patchlogs

Subject: [StGIT PATCH 0/2] Improving patchlogs

## tl;dr

3 messages between May 5, 2007 and May 5, 2007. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Yann Dirson· May 5, 2007, 14:00 UTC · lore

This is a first pass on recording missing history in the patchlogs, as described in a former email. At least "sync" still has unrecorded (merge) information.

-- 
Yann Dirson    <ydirson@altern.org> |
Debian-related: <dirson@debian.org> |   Support Debian GNU/Linux:
                                    |  Freedom, Power, Stability, Gratis
     http://ydirson.free.fr/        | Check <http://www.debian.org/>
Yann Dirson· May 5, 2007, 14:00 UTC · re: Yann Dirson · lore

[PATCH 1/2] Cleanup variable names in pick.

I'm going to need patch objects there, so avoid using variable "patch" to store only a patchname.

Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/commands/pick.py |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
Show changes to stgit/commands/pick.py +6 −6
diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py
index edd614d..4eb79a3 100644
--- a/stgit/commands/pick.py
+++ b/stgit/commands/pick.py
@@ -71,11 +71,11 @@ def func(parser, options, args):
     else:
         patch_branch = commit_str.split('@')
         if options.name:
-            patch = options.name
+            patchname = options.name
         elif len(patch_branch) == 2:
-            patch = patch_branch[0]
+            patchname = patch_branch[0]
         else:
-            patch = make_patch_name(commit.get_log(), crt_series.patch_exists)
+            patchname = make_patch_name(commit.get_log(), crt_series.patch_exists)
 
     if options.parent:
         parent = git_id(options.parent)
@@ -118,17 +118,17 @@ def func(parser, options, args):
         print 'Importing commit %s...' % commit_id,
         sys.stdout.flush()
 
-        crt_series.new_patch(patch, message = message, can_edit = False,
+        crt_series.new_patch(patchname, message = message, can_edit = False,
                              unapplied = True, bottom = bottom, top = top,
                              author_name = author_name,
                              author_email = author_email,
                              author_date = author_date)
         if not options.unapplied:
-            modified = crt_series.push_patch(patch)
+            modified = crt_series.push_patch(patchname)
         else:
             modified = False
 
-        if crt_series.empty_patch(patch):
+        if crt_series.empty_patch(patchname):
             print 'done (empty patch)'
         elif modified:
             print 'done (modified)'
Yann Dirson· May 5, 2007, 14:00 UTC · re: Yann Dirson · lore

[PATCH 2/2] Copy patchlogs when cloning a stack or picking a patch.

This will allow to keep patch history accross those operations, and see when they diverged when looking at the respective patchlogs. With more work, that will allow to locate the common ancestor when sync'ing a patch across branches.

The work on "pick" can still be improved: currently the patchlog is preserved on "pick patch[@branch][//top]", but we could make it work for //top.old as well (or any rev in the patchlog when we'll be able to name those).

Patchlog preservation in pick can only work when referencing a patch by name. When picking an arbitrary commit we could also improve things by recording a "pick" operation instead of a "new".

Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/commands/pick.py |   31 ++++++++++++++++++++++++++-----
 stgit/stack.py         |   22 +++++++++++++++-------
 2 files changed, 41 insertions(+), 12 deletions(-)
Show changes to 2 files +41 −12

stgit/commands/pick.py, stgit/stack.py

diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py
index 4eb79a3..4ef9860 100644
--- a/stgit/commands/pick.py
+++ b/stgit/commands/pick.py
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
+from stgit.stack import Series
 
 
 help = 'import a patch from a different branch or a commit object'
@@ -118,11 +119,31 @@ def func(parser, options, args):
         print 'Importing commit %s...' % commit_id,
         sys.stdout.flush()
 
-        crt_series.new_patch(patchname, message = message, can_edit = False,
-                             unapplied = True, bottom = bottom, top = top,
-                             author_name = author_name,
-                             author_email = author_email,
-                             author_date = author_date)
+        newpatch = crt_series.new_patch(patchname, message = message, can_edit = False,
+                                        unapplied = True, bottom = bottom, top = top,
+                                        author_name = author_name,
+                                        author_email = author_email,
+                                        author_date = author_date)
+        # find a patchlog to fork from
+        (refpatchname, refbranchname, refpatchid) = parse_rev(commit_str)
+        if refpatchname and not refpatchid and \
+               (not refpatchid or refpatchid == 'top'):
+            # FIXME: should also support picking //top.old
+            if refbranchname:
+                # assume the refseries is OK, since we already resolved
+                # commit_str to a git_id
+                refseries = Series(refbranchname)
+            else:
+                refseries = crt_series
+            patch = refseries.get_patch(refpatchname)
+            if patch.get_log():
+                print"log was %s" % newpatch.get_log()
+                print "setting log to %s\n" %  patch.get_log()
+                newpatch.set_log(patch.get_log())
+                print"log is now %s" % newpatch.get_log()
+            else:
+                print "no log for %s\n" % patchname
+ 
         if not options.unapplied:
             modified = crt_series.push_patch(patchname)
         else:
diff --git a/stgit/stack.py b/stgit/stack.py
index b0a01dd..044348a 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -23,6 +23,7 @@ import sys, os, re
 from stgit.utils import *
 from stgit import git, basedir, templates
 from stgit.config import config
+from shutil import copyfile
 
 
 # stack exception class
@@ -628,13 +629,18 @@ class Series(StgitObject):
             patches = applied = unapplied = []
         for p in patches:
             patch = self.get_patch(p)
-            new_series.new_patch(p, message = patch.get_description(),
-                                 can_edit = False, unapplied = True,
-                                 bottom = patch.get_bottom(),
-                                 top = patch.get_top(),
-                                 author_name = patch.get_authname(),
-                                 author_email = patch.get_authemail(),
-                                 author_date = patch.get_authdate())
+            newpatch = new_series.new_patch(p, message = patch.get_description(),
+                                            can_edit = False, unapplied = True,
+                                            bottom = patch.get_bottom(),
+                                            top = patch.get_top(),
+                                            author_name = patch.get_authname(),
+                                            author_email = patch.get_authemail(),
+                                            author_date = patch.get_authdate())
+            if patch.get_log():
+                print "setting log to %s" %  patch.get_log()
+                newpatch.set_log(patch.get_log())
+            else:
+                print "no log for %s" % patchname
 
         # fast forward the cloned series to self's top
         new_series.forward_patches(applied)
@@ -865,6 +871,8 @@ class Series(StgitObject):
             if refresh:
                 self.refresh_patch(cache_update = False, log = 'new')
 
+        return patch
+
     def delete_patch(self, name):
         """Deletes a patch
         """

← back to recent threads