[PATCH] repoman.modules.vcs.git.changes: reindex (bug 712106)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] repoman.modules.vcs.git.changes: reindex (bug 712106)

Zac Medico-2
For files returned by git diff-index, call git update-index in order
to ensure that the index reflects the state on disk. This will prevent
incorrect assumptions in cases where the index is missing or stale for
some reason. Since repoman uses this information to decide when to
update copyright header dates, this can prevent spurious copyright
header updates.

Signed-off-by: Zac Medico <[hidden email]>
Bug: https://bugs.gentoo.org/712106
---
 repoman/lib/repoman/modules/vcs/git/changes.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/repoman/lib/repoman/modules/vcs/git/changes.py b/repoman/lib/repoman/modules/vcs/git/changes.py
index 7e9ac1eb5..ebf770d53 100644
--- a/repoman/lib/repoman/modules/vcs/git/changes.py
+++ b/repoman/lib/repoman/modules/vcs/git/changes.py
@@ -29,8 +29,14 @@ class Changes(ChangesBase):
  '''
  super(Changes, self).__init__(options, repo_settings)
 
- def _scan(self):
- '''VCS type scan function, looks for all detectable changes'''
+ def _scan(self, _reindex=True):
+ '''
+ VCS type scan function, looks for all detectable changes
+
+ @param _reindex: ensure that the git index reflects the state on
+ disk for files returned by git diff-index
+ @type _reindex: bool
+ '''
  with repoman_popen(
  "git diff-index --name-only "
  "--relative --diff-filter=M HEAD") as f:
@@ -51,6 +57,9 @@ class Changes(ChangesBase):
  removed = f.readlines()
  self.removed = ["./" + elem[:-1] for elem in removed]
  del removed
+ if _reindex and (self.changed or self.new or self.removed):
+ self.update_index([], self.changed + self.new + self.removed)
+ self._scan(_reindex=False)
 
  @property
  def unadded(self):
@@ -91,7 +100,7 @@ class Changes(ChangesBase):
  # of the working tree.
  myfiles = mymanifests + myupdates
  myfiles.sort()
- update_index_cmd = ["git", "update-index"]
+ update_index_cmd = ["git", "update-index", "--add", "--remove"]
  update_index_cmd.extend(f.lstrip("./") for f in myfiles)
  if self.options.pretend:
  print("(%s)" % (" ".join(update_index_cmd),))
--
2.24.1


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] repoman.modules.vcs.git.changes: reindex (bug 712106)

Alec Warner-2
On Wed, Mar 11, 2020 at 12:16 AM Zac Medico <[hidden email]> wrote:
For files returned by git diff-index, call git update-index in order
to ensure that the index reflects the state on disk. This will prevent
incorrect assumptions in cases where the index is missing or stale for
some reason. Since repoman uses this information to decide when to
update copyright header dates, this can prevent spurious copyright
header updates.

Signed-off-by: Zac Medico <[hidden email]>
Bug: https://bugs.gentoo.org/712106
---
 repoman/lib/repoman/modules/vcs/git/changes.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/repoman/lib/repoman/modules/vcs/git/changes.py b/repoman/lib/repoman/modules/vcs/git/changes.py
index 7e9ac1eb5..ebf770d53 100644
--- a/repoman/lib/repoman/modules/vcs/git/changes.py
+++ b/repoman/lib/repoman/modules/vcs/git/changes.py
@@ -29,8 +29,14 @@ class Changes(ChangesBase):
                '''
                super(Changes, self).__init__(options, repo_settings)

-       def _scan(self):
-               '''VCS type scan function, looks for all detectable changes'''
+       def _scan(self, _reindex=True):

Why the underscore prefix?

-A
 
+               '''
+               VCS type scan function, looks for all detectable changes
+
+               @param _reindex: ensure that the git index reflects the state on
+                       disk for files returned by git diff-index
+               @type _reindex: bool
+               '''
                with repoman_popen(
                        "git diff-index --name-only "
                        "--relative --diff-filter=M HEAD") as f:
@@ -51,6 +57,9 @@ class Changes(ChangesBase):
                        removed = f.readlines()
                self.removed = ["./" + elem[:-1] for elem in removed]
                del removed
+               if _reindex and (self.changed or self.new or self.removed):
+                       self.update_index([], self.changed + self.new + self.removed)
+                       self._scan(_reindex=False)

        @property
        def unadded(self):
@@ -91,7 +100,7 @@ class Changes(ChangesBase):
                # of the working tree.
                myfiles = mymanifests + myupdates
                myfiles.sort()
-               update_index_cmd = ["git", "update-index"]
+               update_index_cmd = ["git", "update-index", "--add", "--remove"]
                update_index_cmd.extend(f.lstrip("./") for f in myfiles)
                if self.options.pretend:
                        print("(%s)" % (" ".join(update_index_cmd),))
--
2.24.1


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] repoman.modules.vcs.git.changes: reindex (bug 712106)

Zac Medico-2
On 3/11/20 9:37 AM, Alec Warner wrote:

> On Wed, Mar 11, 2020 at 12:16 AM Zac Medico <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     For files returned by git diff-index, call git update-index in order
>     to ensure that the index reflects the state on disk. This will prevent
>     incorrect assumptions in cases where the index is missing or stale for
>     some reason. Since repoman uses this information to decide when to
>     update copyright header dates, this can prevent spurious copyright
>     header updates.
>
>     Signed-off-by: Zac Medico <[hidden email]
>     <mailto:[hidden email]>>
>     Bug: https://bugs.gentoo.org/712106
>     ---
>      repoman/lib/repoman/modules/vcs/git/changes.py | 15 ++++++++++++---
>      1 file changed, 12 insertions(+), 3 deletions(-)
>
>     diff --git a/repoman/lib/repoman/modules/vcs/git/changes.py
>     b/repoman/lib/repoman/modules/vcs/git/changes.py
>     index 7e9ac1eb5..ebf770d53 100644
>     --- a/repoman/lib/repoman/modules/vcs/git/changes.py
>     +++ b/repoman/lib/repoman/modules/vcs/git/changes.py
>     @@ -29,8 +29,14 @@ class Changes(ChangesBase):
>                     '''
>                     super(Changes, self).__init__(options, repo_settings)
>
>     -       def _scan(self):
>     -               '''VCS type scan function, looks for all detectable
>     changes'''
>     +       def _scan(self, _reindex=True):
>
>
> Why the underscore prefix?
>
> -A
I can't think of a reason to use this parameter aside from this
recursive call, and the underscore hints at this.
--
Thanks,
Zac


signature.asc (1000 bytes) Download Attachment