forked from adamm/git-importer
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			add_old_st
			...
			add_force
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 7b20c03256 | 
| @@ -7,8 +7,6 @@ import sys | ||||
|  | ||||
| import osc.core | ||||
|  | ||||
| from lib.db import DB | ||||
| from lib.db_revision import DBRevision | ||||
| from lib.git_exporter import GitExporter | ||||
| from lib.importer import Importer | ||||
| from lib.test_exporter import TestExporter | ||||
| @@ -102,56 +100,6 @@ def main(): | ||||
|             requests_log.setLevel(logging.DEBUG) | ||||
|             requests_log.propagate = True | ||||
|  | ||||
|     def check_old_package(db: DB, dir: pathlib.Path): | ||||
|         md5file = dir / "MD5SUMS" | ||||
|         print(md5file) | ||||
|         valid_revisions = None | ||||
|         with open(md5file, "rb") as f: | ||||
|             for line in f.readlines(): | ||||
|                 try: | ||||
|                     md5, file = line.decode("utf-8").strip().split("  ") | ||||
|                 except UnicodeDecodeError: | ||||
|                     logging.error(f"Corrupt MD5 file: {md5file}") | ||||
|                     return | ||||
|                 if file == "ready": | ||||
|                     continue | ||||
|                 if len(md5) != 32: | ||||
|                     logging.error(f"Corrupt MD5 file: {md5file}") | ||||
|                     return | ||||
|                 with db.cursor() as cur: | ||||
|                     cur.execute( | ||||
|                         "SELECT revision_id FROM files WHERE md5=%s AND name=%s", | ||||
|                         (md5, file), | ||||
|                     ) | ||||
|                     nrevs = set([row[0] for row in cur.fetchall()]) | ||||
|                     if valid_revisions is None: | ||||
|                         valid_revisions = nrevs | ||||
|                     else: | ||||
|                         valid_revisions = valid_revisions & nrevs | ||||
|                     if not valid_revisions: | ||||
|                         break | ||||
|  | ||||
|         with db.cursor() as cur: | ||||
|             cur.execute( | ||||
|                 "SELECT * FROM revisions WHERE id = ANY(%s) AND project=%s", | ||||
|                 (list(valid_revisions), "openSUSE:Factory"), | ||||
|             ) | ||||
|             for row in cur.fetchall(): | ||||
|                 r = DBRevision(db, row) | ||||
|                 print("Valid", r, r.files_hash) | ||||
|                 return True | ||||
|  | ||||
|     if False: | ||||
|         import os | ||||
|  | ||||
|         db = DB() | ||||
|         basedir = pathlib.Path( | ||||
|             f"/mounts/work/SAVE/oldpackages/stable/{args.packages[0]}" | ||||
|         ) | ||||
|         for subdir in sorted(os.listdir(basedir)): | ||||
|             if check_old_package(db, basedir / subdir): | ||||
|                 break | ||||
|  | ||||
|     if args.export: | ||||
|         if len(args.packages) != 1: | ||||
|             print("Can only export one package") | ||||
|   | ||||
							
								
								
									
										10
									
								
								lib/git.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								lib/git.py
									
									
									
									
									
								
							| @@ -215,13 +215,17 @@ class Git: | ||||
|         url = f"gitea@gitea.opensuse.org:{org_name}/{repo_name}.git" | ||||
|         self.repo.remotes.create("origin", url) | ||||
|  | ||||
|     def push(self): | ||||
|     def push(self, force=False): | ||||
|         remo = self.repo.remotes["origin"] | ||||
|  | ||||
|         keypair = pygit2.KeypairFromAgent("gitea") | ||||
|         callbacks = pygit2.RemoteCallbacks(credentials=keypair) | ||||
|  | ||||
|         refspecs = ["refs/heads/factory"] | ||||
|         if "refs/heads/devel" in self.repo.references: | ||||
|             refspecs.append("refs/heads/devel") | ||||
|         develspec = "refs/heads/devel" | ||||
|         if develspec in self.repo.references: | ||||
|             if force: | ||||
|                 refspecs.append(f"+{develspec}:{develspec}") | ||||
|             else: | ||||
|                 refspecs.append("{develspec}:{develspec}") | ||||
|         remo.push(refspecs, callbacks=callbacks) | ||||
|   | ||||
| @@ -86,7 +86,7 @@ class GitExporter: | ||||
|             logging.debug(f"Committing {flat}") | ||||
|             self.commit_flat(flat, branch_state) | ||||
|  | ||||
|         self.git.push() | ||||
|         self.git.push(force=True) | ||||
|  | ||||
|     def run_gc(self): | ||||
|         self.gc_cnt = self.gc_interval | ||||
|   | ||||
		Reference in New Issue
	
	Block a user